Skip to content

Instantly share code, notes, and snippets.

@element6
element6 / setup.sh
Created June 13, 2022 00:42 — forked from bradp/setup.sh
New Mac Setup Script
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
// 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 {
// promised setTimeout
function setTimeoutAsync(fn, ms) {
return new Promise((res, rej) => {
setTimeout(() => {
try{
res(fn())
} catch(err) {
rej(err)
}
}, ms)
@element6
element6 / Google_Colaboratory_backup.py
Created September 3, 2018 05:40 — forked from rdinse/Google_Colaboratory_backup.py
Simple Google Drive backup script with automatic authentication for Google Colaboratory (Python 3)
# 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`.
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
// 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')
#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
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()) {
@element6
element6 / gist:6d419dcc4f1413f96c7aca1bb6788122
Created June 5, 2017 01:27
use env var in command line
FOO=${VARIABLE:-default}
Or, which will assign to VARIABLE as well:
FOO=${VARIABLE:=default}
LOC=; eval "echo ${LOC:=en}; echo $LOC"
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)