A Pen by Yu Chun Man Jason on CodePen.
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 tempCSS(element, stylename, temp_value, fn){ | |
// Temporarily replace a css property and restore it after fn(); | |
var ret; | |
var original_value = element.css(stylename); | |
element.css(stylename, temp_value); | |
ret = fn(); | |
element.css(stylename, original_value); | |
return ret; | |
}; |
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
spectrum = getSpectrum(20, ['#2E7D32', '#ffee58', '#B71C1C']); | |
console.log(spectrum); | |
// [[46,125,50],[67,136,54],[88,148,58],[109,159,61],[130,170,65],[151,182,69],[171,193,73],[192,204,77],[213,215,80],[234,227,84],[255,238,88],[248,217,82],[241,196,76],[233,175,70],[226,154,64],[219,133,58],[212,112,52],[205,91,46],[197,70,40],[190,49,34]] | |
/* we can apply the color to css */ | |
$('div').css('background-color', 'rgb(' + spectrum[3] + ')'); |
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 swap = function(arr, i, j){ | |
var temp = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = temp; | |
return arr; | |
}; | |
var insertBefore = function(arr, i, j){ | |
if(i == j || i == j - 1) return arr; | |
else if(i < j) return insertBefore(swap(arr, i, i+1), i+1, j); | |
else if(i > j) return insertBefore(swap(arr, i, i-1), i-1, j); |
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 splitNumber(n, m_parts){ | |
var arr = []; | |
var eachPart = Math.ceil(n / m_parts); | |
for(var i = 0; i < m_parts; i++){ | |
arr.push(eachPart); | |
} | |
var diff = (eachPart * m_parts) - n; | |
for(var i = 0; i < diff; i++){ | |
arr[i%arr.length]--; | |
} |
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 wait(n, cb){ | |
if(n <= 0) cb(); | |
let aggregated_result = {}; | |
let count = 0; | |
return function done(res){ | |
Object.assign(aggregated_result, res); | |
if(++count === n) cb(aggregated_result); | |
} | |
} |
This script generates the SUMMARY.md assuming the following folder structure. Paths ending with /
denotes directories. **
denotes multiply layers or directories.
./
- gitbook root./*/
- parts, will be generated as# Name of the directory
./**/*.md
- articles./*/**/
- chapters
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 foldl(arr, f){ | |
return arr.reduce((arr, x, i) => { | |
if(i === 0) return [x]; | |
return arr.concat([f(arr[i - 1], x)]); | |
}, []); | |
} |
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 queue = (() => { | |
const promises = {}; | |
return async (name, f) => { | |
while(promises[name]) await promises[name]; | |
promises[name] = f(); | |
const res = await promises[name]; | |
promises[name] = undefined; | |
return res; | |
}; | |
})(); |
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 limitAsyncCalls = (fn, n) => { | |
const cap = n; | |
let executing_count = 0; | |
let waitings = []; | |
const wait = () => new Promise(res => waitings.push(res)); | |
const execute = async (fn, args) => { | |
executing_count++; | |
const result = await fn(...args); | |
executing_count--; |
OlderNewer