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 deepFreeze(object) { | |
const clone = JSON.parse(JSON.stringify(object)); | |
for (const name of Object.getOwnPropertyNames(clone)) { | |
if (typeof clone[name] === "object" && clone[name] !== null) { | |
clone[name] = deepFreeze(clone[name]); | |
} | |
} | |
return Object.freeze(clone); | |
} |
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 uuidv4_1() { | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' | |
.split('') | |
.map((c) => { | |
if (c === 'x') return Math.floor(Math.random() * 0xf).toString(16); // [0-9a-f] | |
if (c === 'y') return Math.floor(Math.random() * 4 + 8).toString(16); // [89ab] | |
return c; | |
}) | |
.join(''); | |
} |
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 randomHexColor() { | |
return '#'+(~~(Math.random()*0xffffff)).toString(16).padEnd(6,0); | |
} |
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 array2object(arr) { | |
return { ...arr }; | |
} |
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
git clone https://github.com/neovim/neovim | |
cd neovim | |
# if you want build stable release | |
git checkout stable | |
make CMAKE_BUILD_TYPE=Release \ | |
CMAKE_EXTRA_FLAGS="-DCMAKE_INSTALL_PREFIX=$HOME/.local -DLibIntl_LIBRARY=/usr/lib/libintl.so.8 -DLibIntl_INCLUDE_DIR=/usr/include" | |
make install | |
# export PATH="$HOME/.local/bin:$PATH" |
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
export const animateFrame = ((callback) => { | |
return window.requestAnimationFrame | |
|| function (cb) { | |
return window.setTimeout(cb, 1000/60); | |
}; | |
})(); | |
export const cancelAnimateFrame = window.cancelAnimationFrame || window.clearTimeout; |
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
class DrawCanvas { | |
/** | |
* @param {String} id id of <canvas> | |
*/ | |
constructor(id) { | |
this.lastPos = { x: 0, y: 0 }; | |
this.paths = []; | |
this.drawing = false; | |
this.canvas = document.getElementById(id); | |
this.init(); |
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
#!/sbin/openrc-run | |
environment="production" | |
description="Ghost blogging platform" | |
extra_started_commands="" | |
extra_stopped_commands="" | |
ghost_root="/var/www/ghost" | |
pidfile="/run/ghost.pid" | |
command=/usr/bin/node |
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 isNaturalNumber = (value) => /^(?:0|[1-9][0-9]*)$/.test(value); | |
isNaturalNumber(0); // => true | |
isNaturalNumber(123); // => true | |
isNaturalNumber(0123); // => true | |
isNaturalNumber('0'); // => true | |
isNaturalNumber('123'); // => true | |
isNaturalNumber('0123'); // => false |
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 _ from 'lodash'; | |
const numberRE = /^(?:0|[1-9][0-9]*)$/; | |
const flatten = (originalData) => { | |
const result = {}; | |
const stack = []; | |
let paths = []; | |
let data = JSON.parse(JSON.stringify(originalData)); | |
while(true) { | |
data = { ...data }; |
NewerOlder