Skip to content

Instantly share code, notes, and snippets.

Avatar
📖
Always Learning...

Mohammad Javad Naderi mjnaderi

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

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.

Problem

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

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 - ansible-playbook.sh
@Alireza2n
Alireza2n / nationalCodeGenerator.py
Last active Oct 20, 2020 — forked from omidp/nationalCodeGenerator.java
تولید کننده کد ملی در پایتون
View nationalCodeGenerator.py
def national_code_generator():
number_list = []
_sum = 0
out = ""
for i in reversed(range(2, 11)):
_j = random.randint(0, 9)
number_list.append(str(_j))
_sum += _j * i
_m = _sum % 11
if _m < 2:
@iAugur
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 http://stackoverflow.com/users/57719/chin-huang http://stackoverflow.com/a/31465939/348868
# 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
replace:
backup: yes
@hedleysmith
hedleysmith / h2load_installation.sh
Last active Aug 8, 2020
Installing nghttp2 & h2load on Ubuntu 14.04
View h2load_installation.sh
#! /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 https://github.com/nghttp2/nghttp2.git && cd nghttp2
autoreconf -i
automake
autoconf
./configure --enable-apps
make
@myusuf3
myusuf3 / delete_git_submodule.md
Created Nov 3, 2014
How effectively delete a git submodule.
View delete_git_submodule.md

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
mjnaderi / upvpn.sh
Last active Dec 5, 2015
UpVPN (reconnect vpn when disconnected)
View upvpn.sh
#!/bin/bash
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
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 http://xmeblog.blogspot.com/2013/06/ansible-dynamicaly-update-etchosts.html
- 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
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 (https://wiki.archlinux.org/index.php/Installation_Guide) contains a more verbose description.
# Download the archiso image from https://www.archlinux.org/
# 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
sloria / bobp-python.md
Last active Oct 19, 2021
A "Best of the Best Practices" (BOBP) guide to developing in Python.
View bobp-python.md

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

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

In General

Values

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