This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setObject(str , value){ | |
var arr = str.split('.') | |
var init = window | |
for(var i = 0 ; i < arr.length-1 ; i++){ | |
if(!init[arr[i]]) init[arr[i]] = {} | |
init = init[[arr[i]]] | |
} | |
init[arr[arr.length-1]] = value // trick .. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read TPdevice <<< $( xinput | sed -nre '/TouchPad/s/.*id=([0-9]*).*/\1/p' ) | |
state=$( xinput list-props "$TPdevice" | grep "Device Enabled" | grep -o "[01]$" ) | |
if [ "$state" -eq '1' ];then | |
xinput --disable "$TPdevice" | |
else | |
xinput --enable "$TPdevice" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bsearch = (arr , start , end , el) => { | |
if(start > end) return -1 | |
let mid = Math.round((start + end) / 2) | |
if(mid == el) return mid | |
else if ( mid < el ) return bsearch(arr , mid + 1 , end , el) | |
else if ( mid > el ) return bsearch(arr , start , mid - 1 , el) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import {render} from 'react-dom'; | |
import {createStore} from 'redux' | |
const reducer = (state = 0 , action) => | |
(action.type == 'inc' || action.type == 'dec') ? ((action.type == 'inc' ? state + 1 : state - 1) ) : state | |
const store = createStore(reducer) | |
const Counter = ({value , onInc , onDec}) => ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fac(n){ | |
if( n == 0) return 1 | |
return n * fac(n-1) | |
} | |
function fac2(n){ | |
return (function tmp( n , a){ | |
if(n == 0) return a | |
return tmp(n-1 , a * n) | |
})(n , 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// square root of x in range of e .. g could be much better guessed . | |
function sq(x , e , g ){ | |
g = g || x / 2 | |
if(Math.abs( g * g - x ) < e ) | |
return g | |
else | |
return sq( x , e , ( g + x / g ) / 2 ) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bubble_sort(a) | |
i = 0 | |
len = a.size - 1 | |
while len >= i | |
j = 0 | |
while len > j | |
if a[j] > a[j+1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toBase(number , base){ | |
var s = "" | |
do{ | |
// binary reads from right to left | |
s = String(number % base) + s | |
number = Math.floor(number / base) | |
}while (number > 0) | |
return s | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const combineReducers = (reducers)=>{ | |
return (state = {} , action)=>{ | |
Object.keys(reducers).reduce(function( nextState , key ){ | |
nextState[key] = reducers[key](state[key] , action); | |
return nextState; | |
} , {}) | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const todos(state=[] , action){ | |
switch(action.type){ | |
case 'add_todo': | |
case 'remove_todo': | |
case 'toggle_todo': | |
return todo(state , action) | |
default : | |
return state | |
} |