Skip to content

Instantly share code, notes, and snippets.

Always Learning...

Mohammad Javad Naderi mjnaderi

Always Learning...
View GitHub Profile
astoilkov /
Last active Sep 26, 2021
Async Operations with useReducer Hook

Async Operations with useReducer Hook

9 March, 2019

We were discussing with @erusev what we can do with async operation when using useReducer() in our application. Our app is simple and we don't want to use a state management library. All our requirements are satisfied with using one root useReducer(). The problem we are facing and don't know how to solve is async operations.

In a discussion with Dan Abramov he recommends Solution 3 but points out that things are fresh with hooks and there could be better ways of handling the problem.


berkayunal / ._ Loading variables from .env files in
Created Jan 16, 2018
Loading variables from .env files in Ansible
View ._ Loading variables from .env files in

Loading variables from .env files in Ansible

Ansible has various ways of looking up data from outside sources, including plain text password files, CSV files and INI files. But it doesn't seem to have a lookup for .env files, as used in Laravel projects, also available for PHP, Ruby, Node.js, Python and others.

One option is to launch Ansible with the Ruby dotenv command line script... But that requires Ruby, which seems like overkill to me.

So here is a simpler solution that I use. It consists of:

  1. The .env file itself
  2. A small shell script that loads the .env file into environment variables -
Alireza2n /
Last active Oct 20, 2020 — forked from omidp/
تولید کننده کد ملی در پایتون
def national_code_generator():
number_list = []
_sum = 0
out = ""
for i in reversed(range(2, 11)):
_j = random.randint(0, 9)
_sum += _j * i
_m = _sum % 11
if _m < 2:
iAugur / ansible-add-string-to-line.yml
Last active Aug 2, 2021
Ansible: Add a String to an existing line in a file
View ansible-add-string-to-line.yml
# Adapted from solution provided by
# Scenario: You want to add a group to the list of the AllowGroups in ssh_config
# before:
# AllowGroups Group1
# After:
# AllowGroups Group1 Group2
- name: Add Group to AllowGroups
backup: yes
hedleysmith /
Last active Aug 8, 2020
Installing nghttp2 & h2load on Ubuntu 14.04
#! /bin/bash
sudo apt-get update
sudo apt-get install g++ make binutils autoconf automake autotools-dev libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev -y
git clone && cd nghttp2
autoreconf -i
./configure --enable-apps
myusuf3 /
Created Nov 3, 2014
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
mjnaderi /
Last active Dec 5, 2015
UpVPN (reconnect vpn when disconnected)
VPN="Sharif ID"
trap "exit 0" SIGINT SIGTERM
while true; do
if ! nmcli con status | grep -q "$VPN"; then
echo "[`date`] Disconnected. Trying to reconnect..."
nmcli -p con up id "$VPN"
rothgar / main.yml
Last active Aug 26, 2021
Generate /etc/hosts with Ansible
View main.yml
# Idempotent way to build a /etc/hosts file with Ansible using your Ansible hosts inventory for a source.
# Will include all hosts the playbook is run on.
# Inspired from
- name: "Build hosts file"
lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" state=present
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: groups['all']
mattiaslundberg / arch-linux-install
Last active Oct 15, 2021
Minimal instructions for installing arch linux on an UEFI system with full system encryption using dm-crypt and luks
View arch-linux-install
# Install ARCH Linux with encrypted file-system and UEFI
# The official installation guide ( contains a more verbose description.
# Download the archiso image from
# Copy to a usb-drive
dd if=archlinux.img of=/dev/sdX bs=16M && sync # on linux
# Boot from the usb. If the usb fails to boot, make sure that secure boot is disabled in the BIOS configuration.
# Set swedish keymap
sloria /
Last active Oct 19, 2021
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General


  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens