Rectangle 27 1

Nginx rate limiting simplyfied

Config in nginx. conf > html section

geo $limit {
default 1; 0; 0;
map $limit $limit_key {
0 "";
1 $binary_remote_addr;
limit_req_zone $limit_key zone=req_zone:10m rate=10r/s;
server {
location / {
limit_req zone=req_zone burst=20 nodelay;
limit_req_log_level warn;
limit_req_status 444;
# ...
} }

Installation of Siege on AMI/Centos.

sudo yum-config-manager --enable epel
sudo yum install siege
siege -b -r 1 -c25 http://localhost/parentune-framework/public/

Download and Configure Siege on Ubuntu:

sudo apt-get update && sudo apt-get upgrade --show-upgraded
tar -zxvf siege-latest.tar.gz
cd siege-*/
sudo apt-get install build-essential
sudo make install
Article nginx rate limiting siege
Rectangle 27 1

Log with morgan in Express

To use the new HTTP logger (called morgan) from Express 4.0 you need to install:

npm install morgan

And import it:

var morgan = require('morgan');

When creating a new morgan logger middleware a format must be specified, followed by desired options (which are optional) :


The format can be a string or a function that will produce a log entry (tokens are of help here). Predefined names include dev, combined, short etc.

Options worth mentioning are:

  • immediate that will write log lines on request instead of response (requests will be logged even when server has crashed)
  • skip that determines when logging should be skipped.

To only log error responses:

morgan('combined', { skip: function (req, res) { return res.statusCode < 400 } });

Custom tokens can be also defined using morgan.token function.

Note express logging Node.js
Rectangle 27 1

Easy way to deliver HTML pages with Express

Displaying basic HTML pages can be achieved in many ways using Node's core API, yet the easiest way is by using the Express framework.

The serve-static module will be used to deliver the page:

var express = require('express'); var serveStatic = require('serve-static'); var app = express();

Display index.html:

app.use(serveStatic('public/',{'index': ['index.html', `index.htm`]})); app.listen(3000);

Multiple roots:

app.use(serveStatic(__dirname+ '/first')); app.use(serveStatic(__dirname+ '/second'));

Files will be firstly looked for in /first then in /second as a fallback.

Note express Node.js HTML
Rectangle 27 1

Caching - Defination

Caching (pronounced “cashing”) is the process of storing data in a cache.

A cache is a temporary storage area. For example, the files you automatically request by looking at a Web page are stored on your hard disk in a cache subdirectory under the directory for your browser. When you return to a page you've recently looked at, the browser can get those files from the cache rather than the original server, saving you time and saving the network the burden of additional traffic.

Note caching Defination
Rectangle 27 1

Python - How does slicing work?

# What will be printed by the following snippet?

a = 'pass'


The correct answer is the string itself, but reversed. Some python types such as arrays, lists and strings support slicing, using the following syntax: [start:end:step] . For example, using as support the list a = [1, 2, 3, 4] we can see how slicing works:

  • print(a[0:2]) - notice step is optional - prints 1,2
  • print(a[:]) - notice start , end and step optional - prints the whole list 1, 2, 3, 4
  • print(a[::2]) - goes from start through end , skipping 2 places ahead each time.

In the same fashion, the slicing done in the example will iterate over the whole list (start and end left empty), but backwards due to the -1 value of step.

Note Python slice string
Rectangle 27 1

Installing a .deb package from the terminal

To install a deb package:

$ sudo dpkg -i DEB_PACKAGE # ex: sudo dpkg -i debpack_3.1.deb

If dpkg reports an error due to dependency problems, run:

$ sudo apt-get install -f

This will download the missing dependencies. If that reports an error, dependencies will have to be configured manually.

To remove the package:

$ sudo dpkg -r PACKAGE_NAME # ex: sudo dpkg -r debpack

Note Must Know Linux debian
Rectangle 27 1

Disable IPv6

Often services and applications try to use IPv6and, upon failure, fall back to IPv4. If you consider this being an inconvenient or want more privacy online 1 , you can choose to disable IPv6.

First, check its status:

$ cat /proc/sys/net/ipv6/conf/all/disable_ipv6

1 indicates that is completely disabled , 0otherwise.

To disable it until the system reboots, run:

$ echo "1" > /proc/sys/net/ipv6/conf/all/disable_ipv6

To disable it permanently, append these to /etc/sysctl.conf:

net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1 net.ipv6.conf.lo.disable_ipv6=1

And issue this command to apply the settings:

$ sysctl -p
Note how to ipv6
Rectangle 27 1

GraphQL - A Query Language for APIs

GraphQL is a new API standard that provides a more efficient, powerful and flexible alternative to REST. It was developed and open-sourced by Facebook and is now maintained by a large community of companies and individuals from all over the world. APIs have become ubiquitous components of software infrastructures. In short, an API defines how a client can load data from a server.

Topic query engine graph
Rectangle 27 2

GraphQL - Introduction

GraphQL is a new API standard that provides a more efficient, powerful and flexible alternative to REST. It was developed and open-sourced by Facebook and is now maintained by a large community of companies and individuals from all over the world.

APIs have become ubiquitous components of software infrastructures. In short, an API defines how a clientcan load data from a server.

At its core, GraphQL enables declarative data fetching where a client can specify exactly what data it needs from an API. Instead of multiple endpoints that return fixed data structures, a GraphQL server only exposes a single endpoint and responds with precisely the data a client asked for.

GraphQL - A Query Language for APIs

Most applications today have the need to fetch data from a server where that data is stored in a database. It’s the responsibility of the API to provide an interface to the stored data that fits an application’s needs.

GraphQL is often confused with being a database technology. This is a misconception, GraphQL is a query language for APIs - not databases. In that sense it’s database agnostic and effectively can be used in any context where an API is used.

A more efficient Alternative to REST

REST has been a popular way to expose data from a server. When the concept of REST was developed, client applications were relatively simple and the development pace wasn’t nearly where it is today. REST thus was a good fit for many applications. However, the API landscape has radically changed over the last couple of years. In particular, there are three factors that have been challenging the way APIs are designed:

1. Increased mobile usage creates need for efficient data loading

Increased mobile usage, low-powered devices and sloppy networks were the initial reasons why Facebook developed GraphQL. GraphQL minimizes the amount of data that needs to be transferred over the network and thus majorly improves applications operating under these conditions.

2. Variety of different frontend frameworks and platforms

The heterogeneous landscape of frontend frameworks and platforms that run client applications makes it difficult to build and maintain one API that would fit the requirements of all. With GraphQL, each client can access precisely the data it needs.

3. Fast development & expectation for rapid feature development

Continuous deployment has become a standard for many companies, rapid iterations and frequent product updates are indispensable. With REST APIs, the way data is exposed by the server often needs to be modified to account for specific requirements and design changes on the client-side. This hinders fast development practices and product iterations.

Note rest graph query engine