Skip to content

Instantly share code, notes, and snippets.

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

Behnam behnammodi

:octocat:
...
View GitHub Profile
@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('');
// goto https://github.com/behnammodi/ios-widget-global-calendar
@behnammodi
behnammodi / revision.js
Created October 22, 2020 13:45
For review
// -----------------------------------------------------------------------------------------
/**
* object literal
*/
const circle = {
r: 1,
draw: () => console.log('i draw'),
};
circle.draw();
<html>
<head>
<style>
#box {
width: 100px;
height: 100px;
background-color: lightseagreen;
}
</style>
</head>
@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 / .bash_profile
Last active December 25, 2019 18:17
.bash_profile
# Git branch in prompt.
function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
function number_of_uncommited(){
git status -s 2> /dev/null | wc -l | awk '{$1=$1};1' | grep -v "^0"
}
function color_blue(){
import is from "is";
function ptf(fun, configs) {
if (is.array(configs))
return (...args) => {
configs.forEach((_, index) => {
if (configs[index](args[index]) === false)
throw new Error(
`${index} argument type is error, ${index} value is ${args[index]}`
);
function sleep(seconds) {
const startTime = new Date();
const endTime = startTime.setSeconds(startTime.getSeconds() + seconds);
while (new Date() < endTime) {
continue;
}
return;
}
function useState(initialState) {
var _state = initialState;
function setState(value) {
_state = value;
}
function getState() {
return _state;
}
function sum(...num){
return num.reduce((a,b)=>a+b,0)
}