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 withPropsChanged = (arePropsChagned, callback) => BaseComponent => { | |
const factory = React.createFactory(BaseComponent) | |
return class Watcher extends React.Component { | |
componentWillReceiveProps(nextProps) { | |
if (arePropsChagned(this.props, nextProps)) { | |
callback(nextProps) | |
} | |
} | |
render() { | |
return factory(this.props) |
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
// Return "infinite" sequence of HSL colors | |
function* colorMaker({distance = 1, saturation, luminosity, shift = 0}) { | |
let colorIndex = 0 | |
while (true) { | |
const hue = (colorIndex * distance + shift) % 359 | |
yield `hsl(${hue}, ${saturation}%, ${luminosity}%)` | |
colorIndex++ | |
} | |
} |
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
async function retry(foo, count = 1, delay) { | |
let error; | |
while (count--) { | |
try { | |
return foo() | |
} catch (e) { | |
error = e | |
await timeout(delay) | |
} |
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
/* | |
101 - 100 | |
12 - 12 | |
12.3 - 12 | |
1.45 - 1.4 | |
*/ | |
N = 2 | |
parseFloat(a.toPrecision(N)) |
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
// item = {id: 'uniq id', field: 1, fielda: 'a'} | |
listOfItems.reduce((a, i) => ({...a, [i.id]:i}), {}) |
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 | |
# Input params | |
DOMAIN=$1 | |
UPSTREAM_PORT=$2 | |
# Check if config already exist (no overwrite) | |
if [ -f /etc/nginx/servers/$DOMAIN ]; then | |
echo "Config /etc/nginx/servers/$DOMAIN already exist. Remove it for continue" | |
exit 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! s:encodeURIComponent(str) | |
let s = '' | |
for i in range(strlen(a:str)) | |
let c = a:str[i] | |
if c =~# "[A-Za-z0-9-_.!~*'()]" | |
let s .= c | |
else | |
let s .= printf('%%%02X', char2nr(a:str[i])) | |
endif | |
endfor |
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 LineStream extends Transform { | |
constructor(...args) { | |
super(...args); | |
this.buffer = ''; | |
} | |
_transform(chunk, encoding, callback) { | |
const lines = chunk.toString().split('\n'); | |
lines[0] = this.buffer + lines[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
setInterval(function(){[].forEach.call(document.querySelectorAll('.post_delete_button'), function(e){e.click();e.remove()}); window.scrollTo(0,document.body.scrollHeight);}, 2000) |
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
on run {input, parameters} | |
set myPath to POSIX path of input | |
set cmd to "vim " & quote & myPath & quote | |
tell application "iTerm" | |
activate | |
set newWindow to (create window with default profile) | |
tell current session of newWindow | |
write text cmd | |
end tell |