Skip to content

Instantly share code, notes, and snippets.

View aemloviji's full-sized avatar
🏠
Working from home

Elvin Asadov aemloviji

🏠
Working from home
View GitHub Profile
@aemloviji
aemloviji / UnderstandingDockerVolume.md
Last active April 7, 2020 16:04
Managing Docker Container Volumes

How to manage docker container volumes.

Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. A volume allows data to persist, even when a container is deleted. Volumes can be used to share data between the host and the container(s).

By mounting a volume you can achive to

  • Pull data from a container.
  • Push data to a container.
  • Share data between containers.

Please note that, arguments prefixed with @(at) in below commands must be replaced with actual values.

@aemloviji
aemloviji / nginx-dockerfile
Last active May 6, 2020 19:17
Dockerfile for the Nginx container
FROM nginx:alpine
COPY nginx-custom.conf /etc/nginx/conf.d/default.conf
@aemloviji
aemloviji / DockerfileInstructions.md
Last active April 24, 2020 07:35
Dockerfile Instructions

FROM — specifies the base (parent) image.
LABEL —provides metadata. Good place to include maintainer info.
ENV — sets a persistent environment variable.
RUN —runs a command and creates an image layer. Can be used to install packages into containers or run specific commands(i.e mkdir and etc.).
COPY — copies files and directories to the container.
ADD — copies files and directories to the container. Can upack local .tar files.
CMD — provides a command and arguments for an executing container. Parameters can be overridden. There can be only one CMD.
WORKDIR — sets the working directory for the instructions that follow.
ARG — defines a variable to pass to Docker at build-time.
ENTRYPOINT — provides command and arguments for an executing container. Arguments persist.\

@aemloviji
aemloviji / CSharpHigherOrderFunction.cs
Created May 5, 2020 06:22
Higher-order function in C#
public static void Main(string[] args)
{
Func<int, int> doubleCall(Func<int, int> func) => x => func(func(x));
static int plusN(int n) => n + 3;
Console.WriteLine(doubleCall(plusN)(5));
}
@aemloviji
aemloviji / CAP-Theorem.md
Last active May 6, 2020 19:22
CAP theorem.

CAP theorem NoSQL database types

NoSQL (non-relational) databases are ideal for distributed network applications. Unlike their vertically scalable SQL (relational) counterparts, NoSQL databases are horizontally scalable and distributed by design—they can rapidly scale across a growing network consisting of multiple interconnected nodes.

The ‘CAP’ in the CAP theorem, explained

Let’s take a detailed look at the three distributed system characteristics to which the CAP theorem refers.

Consistency Consistency means that all clients see the same data at the same time, no matter which node they connect to. For this to happen, whenever data is written to one node, it must be instantly forwarded or replicated to all the other nodes in the system before the write is deemed ‘successful.’

@aemloviji
aemloviji / OAuth-notes.md
Last active July 3, 2020 15:34
OAuth protocol flows

Flows

The authentication flows, dictate the process on how a client application can receive an access token from the authorization server. Each flow is appropriate for different scenarios, not all flows are appropriate for all kinds of applications. There are two types of redirect flows and two types of credential exchange type of flows.

Redirect flows

  • Implicit grant flow. This is one of the most popular approaches, the resource owner is redirected to the authorization server and logins there. After a successful login, user is redirected back to the client application, where they get their access token.
  • Authorization code flow. This is similar approach to the above, with one twist. Instead of getting an access token when redirected back to the website, we simply get an authorization code, which can be used to trade for an access token. This mechanism adds an extra layer of security, mitigating MIM attacks.

Credential flows

@aemloviji
aemloviji / docker-commands.md
Last active November 30, 2022 17:18
Helpful Docker commands and code snippets

###############################################################################

Helpful Docker commands and code snippets

###############################################################################

CONTAINERS

#stop ALL containers
docker stop $(docker ps -a -q)
# remove ALL containers
docker rm -f $(docker ps -a -q) 
###############################################################################
# Helpful Docker commands and code snippets
###############################################################################
### CONTAINERS ###
docker stop $(docker ps -a -q) #stop ALL containers
docker rm -f $(docker ps -a -q) # remove ALL containers
docker rm -f $(sudo docker ps --before="container_id_here" -q) # can also filter
# exec into container
@aemloviji
aemloviji / JS_map_reduce_filter.md
Last active October 26, 2020 10:14
How to simplify your codebase with map(), reduce(), and filter() in JavaScript

How to simplify your codebase with map(), reduce(), and filter() in JavaScript

1. Remove duplicates from an array of numbers/strings

Well, this is the only one not about map/reduce/filter, but it’s so compact that it was hard not to put it in the list. Plus we’ll use it in a few examples too.

const values = [3, 1, 3, 5, 2, 4, 4, 4];
const uniqueValues = [...new Set(values)];

// uniqueValues is [3, 1, 5, 2, 4]
@aemloviji
aemloviji / rename-git-committer-name.sh
Created December 25, 2021 16:23
how to change committer name in git when commits were pushed with different name unintentionally
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="aaa@company.com"
CORRECT_NAME="bbb_name"
CORRECT_EMAIL="bbb@company.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then