Verified Commit c87e1b5b authored by Ankit R Gadiya's avatar Ankit R Gadiya
Browse files

Files Added

Pipeline #37519490 passed with stages
in 27 seconds
image: ankitrgadiya/pandoc
- make all
- mv html public
- public
- master
# Makefile to generate files
# SEO Variables
# Directories
SOURCE := source
TEMPL := template
HTML := html
STATIC := static
FOLDERS := $(subst $(SOURCE),$(HTML),$(shell find $(SOURCE) -type d))
# Files
MD_FILES := $(shell find $(SOURCE) -type f -name "*.md")
HTML_FILES := $(subst $(SOURCE),$(HTML),$(patsubst,%.html,$(MD_FILES)))
HTML_TEMPL := $(wildcard $(TEMPL)/*.html)
STATIC_FILES := $(subst $(STATIC),$(HTML),$(wildcard $(STATIC)/*))
SITEMAP := $(HTML)/sitemap.txt
TREE := $(HTML)/list.txt
# Parser options
PANDOC := pandoc
--standalone \
--from markdown \
--to html \
--template $(TEMPL)/default.html \
--mathjax \
--include-after-body=$(TEMPL)/footer.html \
--include-before-body=$(TEMPL)/navigation.html \
--strip-comments \
--variable google_verification=$(GOOGLE_VERIFICATION)
# Default target
# Create folders
mkdir -p $@
# HTML Files
html/%.html: source/
$(PANDOC) $(HTML_FLAGS) --output $@ $<
# Static Assets
$(STATIC_FILES): $(wildcard $(STATIC)/*)
cp -r $(STATIC)/* $(HTML)
# Sitemap
find $(HTML)/ -name "*.html" -type f -printf "$(BASEURL)/%P\n" > $@
# Tree
cd $(HTML) && \
tree -P '*.html|*.css|*.txt' --charset=ascii --dirsfirst -o list.txt
# Clean
rm -rf $(HTML)/*
# Server
caddy -host -port 8000 -root html/
# PHONY targets
.PHONY: all clean server
This repository contains source code of my website -
title: Error 404
subtitle: Page not found
The page you are looking for either do not exist or was moved to other location.
title: Docker Images
subtitle: Documentation for Docker images
[Argp](/index.html) / [Docs](/docs/index.html) / Docker
Following is the list of [Docker]( images I wrote/maintain.
The pre-built images are available at [Docker
* [Nnpy](/docs/docker/nnpy.html)
* [Pandoc](/docs/docker/pandoc.html)
title: "Docker &mdash; Nnpy"
redirect: "/docs/nnpy/docker.html"
[Argp](/index.html) / [Docs](/docs/index.html) /
[Docker](/docs/docker/index.html) / Nnpy
title: Docker &mdash; Pandoc
subtitle: Docker image for Pandoc
[Argp](/index.html) / [Docs](/docs/index.html) /
[Docker](/docs/docker/index.html) / Pandoc
[![Docker Automated build](](
[![Docker Stars](](
[![Docker Pulls](](
[![GitHub issues](](
[![GitHub last commit](](
## About
The Pandoc image comes with the latest [Pandoc]( binary
from [Github Releases]( This image is
meant to be used by CI/CD services to generate various file formats supported
by Pandoc. However, this can also be used instead of distribution specific
versions of Pandoc to get the latest version.
## Usage
The `pandoc` command can be used by running the container.
$ docker run -it ankitrgadiya/pandoc pandoc <ARGS>
Although even for a very basic setup you'll probably need to mount the
directories in the container so the files that Pandoc writes can be persistent.
The `-v` option of `run` subcommand can be used to mount directories. To mount
the current directory in the container you can substitute `pwd` command in
place of directory. Note that by default the container starts in `/` directory
but you can use `-w` option to override the default working directory.
$ docker run -v `pwd`:/root/ -w="/root/" -it ankitrgadiya/pandoc pandoc <ARGS>
The image also comes with GNU Make installed so instead of running commands on
individual files, you can create a receipe in `Makefile` and run `make` command
$ docker run -v `pwd`:/root/ -w="/root/" -it ankitrgadiya/pandoc make
## Links
* [Source](
* [Pre-Built Image](
## License
title: "Docs"
subtitle: "List of all the documentation hosted on this website"
[Argp](/index.html) / Docs
* [Docker](/docs/docker/index.html)
* [Nnpy](/docs/docker/nnpy.html)
* [Pandoc](/docs/docker/pandoc.html)
* [Nnpy](/docs/nnpy/index.html)
* [Docker](/docs/nnpy/docker.html)
* [Nginx](/docs/nnpy/nginx.html)
* [Setup](/docs/nnpy/setup.html)
* [Project Euler](/docs/project-euler/index.html)
* [Problem 1](/docs/project-euler/prob1.html)
* [Problem 2](/docs/project-euler/prob2.html)
* [Simple Template](/docs/simple-template/index.html)
* [Jekyll](/docs/simple-template/jekyll.html)
* [Pandoc](/docs/simple-template/pandoc.html)
title: Nnpy &mdash; Docker
subtitle: Documentation of the docker image of Nnpy
[Argp](/index.html) / [Docs](/docs/index.html) / [Nnpy](/docs/nnpy/index.html)
/ Docker
For easier deployment, Nnpy Docker image can be used instead of manually
installing everything. The Docker image uses [Alpine
Linux]( and is therefore very lightweight.
The repository includes a `Dockerfile` which can be used to build the Docker
image manually. To build the image execute the following command.
$ docker build -t nnpy .
Alternatively, you can pull the pre-built image from [Docker
$ docker pull ankitrgadiya/nnpy
Nnpy uses the [SQLite]( database to store the data. To
use the image, you need a database in place.
Once, you have the image pulled/built and SQLite database in place, to run the
container you can execute the following command.
$ docker run -v /absolute/path/nnpy.db:/app/nnpy.db -p 8080:80 -d ankitrgadiya/nnpy
* `-v` option mounts the `nnpy.db` inside the container at `/app/nnpy.db`.
* `-p` option exposes port 80 of container and maps it to port 8080 of the
machine, effectively serving Pastebin at port 8080 of the local machine.
* `-d` option makes the container run in daemon mode.
title: Nnpy
subtitle: A very simple Pastebin
[Argp](/index.html) / [Docs](/docs/index.html) / Nnpy
[![Docker Automated build](](
[![Docker Stars](](
[![Docker Pulls](](
[![Build Status](](
[![GitHub issues](](
[![GitHub last commit](](
Nnpy is a very simple Pastebin and a clone of [nnmm]( It
is implemented in [Python 3]( and uses the
[Flask]( web framework. To store data, it uses the
[SQLite]( database. It does not include a form to
submit data. Instead, it relies on other software to send *POST* request
A simple example of pasting the output of `ls` command to Nnpy using
$ ls -l | curl --data-urlencode c@-
Another example of pasting the contents of a plain text file to nnpy by
redirecting the input to `curl` command.
$ curl --data-urlencode c@- < plain.txt
* [Docker](/docs/nnpy/docker.html)
* [Nginx](/docs/nnpy/nginx.html)
* [Setup](/docs/nnpy/setup.html)
## Links
* [Github:ankitrgadiya/nnpy](
## License
[BSD 3-Clause]( License
title: Nnpy &mdash; Nginx
subtitle: Setting up Nginx proxy for Nnpy
[Argp](/index.html) / [Docs](/docs/index.html) / [Nnpy](/docs/nnpy/index.html)
/ Nginx
After installing Nnpy, a proxy server can be used to forward requests to nnpy
server. This section provides information to configure
[Nginx]( as a proxy server under
Add a new file named `nnpy` under `/etc/nginx/sites-available/` directory for
Nnpy with the following content and modify the necessary things.
server {
listen 80;
# listen 443 ssl;
# ssl_certificate /etc/nginx/certs/debian/final.crt;
# ssl_certificate_key /etc/nginx/certs/debian/debian.key;
# ssl_client_certificate /etc/nginx/certs/debian/client-ca.crt;
# ssl_verify_client optional;
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass unix:/var/run/nnpy.sock;
To enable it so that Nginx can see and process it, create a symlink to this
file in `/etc/nginx/sites-enabled/` directory.
$ ln -s /etc/nginx/sites-enabled/nnpy /etc/nginx/sites-available/nnpy
The virtual host for Nnpy is enabled now. It is always a good thing to verify
the configuration for errors. Nginx command, if run with `-t` option does the
error checking.
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
To apply the new configurations Nginx needs to reload.
$ service nginx reload
title: Nnpy &mdash; Setup
subtitle: Setting up Nnpy locally and adding Systemd service
[Argp](/index.html) / [Docs](/docs/index.html) / [Nnpy](/docs/nnpy/index.html)
/ Setup
Nnpy requires packages under [Debian]( distribution
(similar packages for other distributions).
* virtualenv
* python3
* sqlite3
* python3-dev (Build Only)
* build-essential (Build Only)
After installing packages, create a virtual environment under the root
directory of Nnpy and activate it.
$ virtualenv -p python3 env/
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /app/env/bin/python3
Also creating executable in /app/env/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
$ source env/bin/activate
Now, install Python modules which are used by Nnpy.
* flask
* uwsgi
(env) $ pip3 install -r requirements.txt
The packages marked as “Build Only” in the list above are required to build the
dependencies and can be uninstalled later.
Now we need to create a database with the `pastes` table with two columns for
`id` and `data`.
$ cat nnpy.sql | sqlite3 nnpy.db
Nnpy is ready to run now. It can be run directly by starting the web server.
Alternatively, it can create a *UNIX* socket which can be used by proxy servers
like [Nginx]( to proxy the web requests to Nnpy. The
`wsgi.ini` file handles the configuration. Default settings will run it in
*HTTP* mode and start web server which will listen at port 5000.
Execute the subsequent command to test `uwsgi` in place.
(env) $ uwsgi --ini wsgi.ini
[Systemd](, which is the default init
system and service manager in a lot of popular Linux Distributions, use service
files to manage services. Please create a new file with the following content
and save it as `nnpy.service`.
Description=nnpy paste
ExecStart=/path/to/nnpy/env/bin/uwsgi --ini nnpy.ini
To add the service file to Systemd, you need to copy the file into
`/etc/systemd/system/` folder.
$ cp nnpy.service /etc/systemd/system/
Now, Systemd daemon needs to reload to recognize and process the service file.
$ sudo systemctl daemon-reload
Now the web app can be run by executing the following command.
$ sudo service nnpy start
To set the service to run on boot, execute the following command.
$ sudo systemctl enable nnpy.service
title: Project Euler
subtitle: Project Euler Problems
[Argp](/index.html) / [Docs](/docs/index.html) / Project Euler
[![GitHub last commit](](
[![GitHub language count](](
[![GitHub stars](](
## About Project Euler
[Project Euler]( is a project by volunteers which has
a large archive of mathematical problems ranging from easy to hard level.
Programmers are to write code in any programming language to solve the problem
and find the correct solution. Every problem has a thread associated with it
where users can post their code and check code of fellow users.
## Problems
The following list contains problems that I’ve solved with the link to the
explanation. If you’ve not tried it on your own, I would recommend giving it a
try by yourself first before looking at the solution.
* &#x2714; [Problem 1](/docs/project-euler/prob1.html)
* &#x2714; [Problem 2](/docs/project-euler/prob2.html)
## Links
* [Source Code](
## License
title: "Project Euler &mdash; Problem 1"
subtitle: "Multiples of 3 and 5"
[Argp](/index.html) / [Docs](/docs/index.html) / [Project
Euler](/docs/project-euler/index.html) / Problem 1
## Problem
If we list all the natural numbers below 10 that are multiples of 3 or 5, we
get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
## Solution
The most [brute force]( way to
approach this problem is to iterate over every number from 1 through 999, that
is, $n - 1$ and check if it is a multiple of 3 or 5 using the
[modulo]( operator. If so add it
to the total sum. This is a simple and correct approach and will definitely
give correct answers.
sum = 0
for i in range(1000):
if i % 3 is 0 or i % 5 is 0:
sum += i
However, this brute force approach is very slow as it goes through literally
$n$ numbers. Therefore, the runtime of this algorithm is linear or in other
words, the complexity of this algorithm is $O\big(n\big)$.
A smarter approach would be to not go through all the numbers, but instead, add
the multiples of 3 and 5. Then reduce, from the total sum, the summation of
multiples of 15 as it got added twice.
def sumOfMultiples(x, limit):
Sum = 0
for i in range(x, 1000, x):
Sum += i
return Sum
print(sumOfMultiples(3, 1000) + sumOfMultiples(5, 1000)
- sumOfMultiples(15, 1000))
This approach, in practice, is faster than the previous brute force approach as
we are churning fewer numbers but theoretically, it’s runtime is still linear.
As it turns out, multiples of any number are always in an [Arithmetic
Progression]( We can
utilize this fact to attain constant runtime.
In this problem, we are dealing with a special case where $a_1$ or initial term
and $d$ or the common difference for the arithmetic progression are same.
\begin{equation} \label{a} \tag{1}
a_1 = d
The n<sup>th</sup> term or $a_n$ of the arithmetic progression then is as
a_n & = a_1 + \big( n - 1 \big) \cdot d \\
But as mentioned earlier $\eqref{a}$, the common difference is same as the
initial term. So, we can substitute the value to get $a_n$ as $n$ times the
inital term.
a_n & = a_1 + \big(n - 1 \big) \cdot a_1 \quad \eqref{a} \\
& = a_1 \cdot n
\end{equation} \label{b} \tag{2}
The summation of $n$ terms of arithmetic progression is given by the following
S_n & = \bigg(\frac{n}{2}\bigg) \cdot \big(a_1 + a_n\big) \\
We can substitute the value of $a_n$ from $\eqref{b}$ in the above equation
to get our final formula for the sum of multiples.
S_n & = \bigg(\frac{n}{2}\bigg) \cdot \big(a_1 + \big(a_1 \cdot n \big) \big)
\quad \eqref{b} \\
& = \Bigg(\frac{a_1 \cdot n \cdot \big( n + 1 \big)}{2} \Bigg)
The above formula can now be used to calculate the sum of multiples in constant
time as the execution does not depend upon the size of the number. And this is
how we can theoretically achieve the runtime complexity of $O(1)$.