Skip to content

Instantly share code, notes, and snippets.

:octocat:
. . .

Behnam Mohammadi uxitten

:octocat:
. . .
Block or report user

Report or block uxitten

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View block-thread.js
function sleep(seconds) {
const startTime = new Date();
const endTime = startTime.setSeconds(startTime.getSeconds() + seconds);
while (new Date() < endTime) {
continue;
}
return;
}
View useState.js
function useState(initialState) {
var _state = initialState;
function setState(value) {
_state = value;
}
function getState() {
return _state;
}
View sum-infinite.js
function sum(...num){
return num.reduce((a,b)=>a+b,0)
}
@uxitten
uxitten / actions.js
Last active Aug 6, 2019
Redux structure
View actions.js
export default {
ACTIONS_INC: state => ({
...state,
count: state.count + 1
}),
ACTIONS_DEC: state => ({ ...state, count: state.count - 1 })
};
View react-useglobalstate.js
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
@uxitten
uxitten / react-usebeep.js
Last active Jul 26, 2019
React use beep for global state
View react-usebeep.js
import React, { useState, useEffect } from "react";
let initialState = {
count: 0,
num: 0
};
let globalState = { ...initialState };
const listeners = [];
View algorithmes.js
/*
* 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++;
@uxitten
uxitten / memoize.js
Created Jul 1, 2019
Memoized function for better performance
View memoize.js
/**
* @description memoized function for better performance
* @param {function} func
* @returns {function} func
*/
function memoize(func) {
var cache = {};
return function() {
var id = JSON.stringify(arguments);
if (cache[id] === undefined)
@uxitten
uxitten / react-redux-sample.js
Last active May 12, 2019
React Redux Sample
View react-redux-sample.js
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 }),
@uxitten
uxitten / react-guard-router.js
Last active Mar 4, 2019
Sample guard router for react
View react-guard-router.js
import React, { Component } from "react";
import {
BrowserRouter,
Route,
Switch,
Link,
Redirect,
withRouter
} from "react-router-dom";
You can’t perform that action at this time.