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
/** | |
* Clear form data. | |
* | |
* @param HTMLFormElement | |
*/ | |
function clearForm(form) { | |
var l = form.elements.length, o, list = { | |
"checkbox": {prop: "checked", val: false}, | |
"radio": {prop: "checked", val: false}, | |
"select-one": {prop: "selectedIndex", val: null}, |
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
/** ES 5 */ | |
function f (n) { return !!~[1,2].indexOf(n) ? 1 : f(n-1) + f(n-2) } | |
/** ES 6 */ | |
const f = n => !!~[1,2].indexOf(n) ? 1 : f(n-1) + f(n-2) | |
/** more crazy */ | |
const f = n => !!({1:1, 2:1})[n] ? 1 : f(n-1) + f(n-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
/** Bind: */ | |
Function.prototype.c_bind = function (cnt) { | |
var pArgs = [].slice.call(arguments, 0), fn = this; | |
return function () { | |
var args = [].slice.call(arguments, 0); | |
[].splice.apply(pArgs, [0, args.length].concat(args)); | |
return fn.apply(cnt, args); | |
} | |
}; |
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/sh | |
prefix="/var/mail/sendmail/new" | |
numPath="/var/mail/sendmail" | |
if [ ! -f $numPath/num ]; then | |
echo "0" > $numPath/num | |
fi | |
num=`cat $numPath/num` | |
num=$(($num + 1)) | |
echo $num > $numPath/num |
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/sh | |
ALL_IMGS=`find . *.jpg -type f -name '*.jpg'` | |
for I in ${ALL_IMGS} | |
do | |
DEM_H=`identify -format "%h" ${I}` | |
DEM_W=`identify -format "%W" ${I}` | |
echo ${I} - ${DEM_H} x ${DEM_W} |
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 calculate(input) { | |
"use strict"; | |
var len = input.length, extr, max, min, part; | |
extr = input | |
.reduce(function (pre, val, i, arr) { // find local extremums | |
if ((!i && (val > arr[i + 1])) // check first element | |
|| ((i === len - 1) && (val > arr[i - 1])) // check last element | |
|| ((val > arr[i - 1]) && val > arr[i + 1]) // check rest |
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
var parseFloat = function (val){ | |
"use strict"; | |
var res = NaN, i = 0, len, neg = false; | |
if ("number" == typeof val) { | |
return val; | |
} | |
if (null == val | |
|| "object" typeof val |
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
var Promise = (function () { | |
"use strict"; | |
function worker(queue, val) { | |
return queue.reduce(function (res, obj, i) { | |
try { | |
return obj.fn(res); | |
} catch (ex) { | |
return obj.err(ex); | |
} |
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 switchScope(fn, params) { | |
var keys, values; | |
keys = Object.keys(params); | |
values = keys.map(function (val) { | |
return params[val]; | |
}); | |
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::some = (n) -> that = @; (a...) -> that.apply this, a.slice 0, n | |
# loger | |
log = (a...) -> console.log a.join " -> " | |
# math | |
mult = (a) -> a * a | |
# possition | |
odd = (k) -> k % 2 |
OlderNewer