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
echo "Creating an SSH key for you..." | |
ssh-keygen -t rsa | |
echo "Please add this public key to Github \n" | |
echo "https://github.com/account/ssh \n" | |
read -p "Press [Enter] key after this..." | |
echo "Installing xcode-stuff" | |
xcode-select --install |
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
// exception won't break the next run | |
// guarantees at least `waitMs` milliseconds between each run | |
export function safeInterval(fn, waitMs, leading = false) { | |
let _stop = false | |
if (leading) { | |
run() | |
} | |
function run() { | |
try { |
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
// promised setTimeout | |
function setTimeoutAsync(fn, ms) { | |
return new Promise((res, rej) => { | |
setTimeout(() => { | |
try{ | |
res(fn()) | |
} catch(err) { | |
rej(err) | |
} | |
}, ms) |
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
# Simple Google Drive backup script with automatic authentication | |
# for Google Colaboratory (Python 3) | |
# Instructions: | |
# 1. Run this cell and authenticate via the link and text box. | |
# 2. Copy the JSON output below this cell into the `mycreds_file_contents` | |
# variable. Authentication will occur automatically from now on. | |
# 3. Create a new folder in Google Drive and copy the ID of this folder | |
# from the URL bar to the `folder_id` variable. | |
# 4. Specify the directory to be backed up in `dir_to_backup`. |
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 padZeros(str, pad = '00') { | |
const padding = typeof pad === 'number' ? Array(pad).fill('0').join('') : pad // '0'.repeat(pad) is faster but need polyfill for IE | |
return (padding + str).slice(-padding.length) | |
} | |
padZeros(2) // '02' | |
padZeros(2, '000') // '002' | |
padZeros(234) // '34' | |
padZeros(1, 4) // '0001' second argument can be a number |
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
// assume retry if promise is rejected, with a ttl feature | |
function promiseTest() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
// console.log('promise done') | |
if(Date.now()%2) | |
resolve('ok') | |
else | |
reject('not ok') |
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
#may need to update local branches fist | |
git remote update origin --prune | |
# get all branches that are merged into release | |
# remove the origin/ prefix | |
# make sure we don't delete release, develop and HEAD branches | |
# remove them | |
git branch -r --merged origin/release | sed 's/origin\///' | grep -vwE "(develop|HEAD|release)$" | xargs -n 1 git push origin --delete | |
#for develop |
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 _walkSync(dir, filter) { | |
const fs = require('fs'); | |
const filelist = []; | |
const dirs = [dir]; | |
while (dirs.length) { | |
const folder = dirs.pop(); | |
fs.readdirSync(folder).forEach(file => { | |
const fullpath = folder + '/' + file; | |
if (fs.statSync(fullpath).isDirectory()) { |
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
FOO=${VARIABLE:-default} | |
Or, which will assign to VARIABLE as well: | |
FOO=${VARIABLE:=default} | |
LOC=; eval "echo ${LOC:=en}; echo $LOC" |
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
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash (visit nvm github for the latest url) | |
. ~/.nvm/nvm.sh | |
nvm install v7 (or whatever node version) |
NewerOlder