Skip to content

Instantly share code, notes, and snippets.

View behnammodi's full-sized avatar
:octocat:
...

Behnam behnammodi

:octocat:
...
View GitHub Profile
@behnammodi
behnammodi / utils.js
Last active July 5, 2019 18:50
utils file
/**
* @private
*/
const FA = 0;
/**
* @private
*/
const EN = 1;
/**
* @private
@behnammodi
behnammodi / queue.js
Last active November 19, 2018 13:46
async queue in javascript
let count = 0;
let running = false;
const queue = {};
const addTask = task => {
queue[count++] = task;
if (running === false) runTasks();
}
const runTasks = async () => {
@behnammodi
behnammodi / nginx-proxy.sh
Created December 11, 2018 14:40
nginx proxy sample
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
@behnammodi
behnammodi / gitexec.js
Created February 20, 2019 06:41
run git command with nodejs
const {exec} = require('child_process');
function git(args) {
return new Promise(res => {
exec('git ' + args, (err, stdout, stderr) => {
if (err) {
throw err;
} else {
res(stdout.trim());
}
@behnammodi
behnammodi / react-guard-router.js
Last active March 4, 2019 08:00
Sample guard router for react
import React, { Component } from "react";
import {
BrowserRouter,
Route,
Switch,
Link,
Redirect,
withRouter
} from "react-router-dom";
@behnammodi
behnammodi / react-redux-sample.js
Last active May 12, 2019 11:16
React Redux Sample
import React from "react";
import { createStore } from "redux";
import { connect, Provider } from "react-redux";
const ACTIONS_INC = "ACTIONS_INC";
const ACTIONS_DEC = "ACTIONS_DEC";
function counter(state = { count: 0 }, { type }) {
const actions = {
[ACTIONS_INC]: () => ({ count: state.count + 1 }),
@behnammodi
behnammodi / memoize.js
Last active December 5, 2020 23:39
Memoized function for better performance
/**
* @version 2
* @description memoized function for better performance
* @param {function} func
* @returns {function} func
*/
function memoize(func){
const cache = new Map();
return (...args)=>{
const key = args.join('');
@behnammodi
behnammodi / algorithmes.js
Last active July 24, 2020 11:27
Algorithmes
/*
* Commons array
* when array is sorted
*/
function commons(a, b) {
const result = [];
let i = j = 0;
cancel:while (true) {
if (a[i] > b[j]) j++;
else if (a[i] < b[j]) i++;
@behnammodi
behnammodi / react-usebeep.js
Last active July 26, 2019 17:26
React use beep for global state
import React, { useState, useEffect } from "react";
let initialState = {
count: 0,
num: 0
};
let globalState = { ...initialState };
const listeners = [];
import React, { useReducer, createContext, useContext, useEffect } from "react";
import { on, emit } from "jetemit";
const initialValue = { X: 0, Y: 0 };
const reducer = (state, action) => {
switch (action.type) {
case "+":
return {
...state,
X: state.X + 1