View diskutil.sh
# Shows which disks are which
mount
# diskutil secureErase [level] /dev/disk1s1
# 0 = one pass writing zeros
diskutil secureErase freespace 0 /dev/disk1s1
# https://ss64.com/osx/diskutil.html
View rate_limit.js
function rateLimit(rate, perMils) {
let x = 0;
return () => {
if (x < rate) {
++x;
setTimeout(function() {--x;}, perMils);
return false;
}
return true;
}
View ledisdb_example.go
package main
import (
"fmt"
"log"
lediscfg "github.com/siddontang/ledisdb/config"
"github.com/siddontang/ledisdb/ledis"
)
View futch.js
// https://github.com/github/fetch/issues/89#issuecomment-256610849
function futch(url, opts={}, onProgress) {
return new Promise( (res, rej)=>{
var xhr = new XMLHttpRequest();
xhr.open(opts.method || 'get', url);
for (var k in opts.headers||{})
xhr.setRequestHeader(k, opts.headers[k]);
xhr.onload = e => res(e.target.responseText);
xhr.onerror = rej;
if (xhr.upload && onProgress)
View permutations.py
import itertools
# Permutations of multiple lists
# https://stackoverflow.com/q/2853212
s=[ [ 'a', 'b', 'c'], ['d'], ['e', 'f'] ]
for l in list(itertools.product(*s)):
print(l)
# Permutations of all possible sizes of a list
View png_to_jpg.go
package main
import (
"fmt"
"image"
"image/jpeg"
"image/png"
"os"
"path/filepath"
)
View golang_null_field.go
package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
"strings"
)
View crypto-aes-gcm.js
/**
* Encrypts plaintext using AES-GCM with supplied password, for decryption with aesGcmDecrypt().
* (c) Chris Veness MIT Licence
*
* @param {String} plaintext - Plaintext to be encrypted.
* @param {String} password - Password to use to encrypt plaintext.
* @returns {String} Encrypted ciphertext.
*
* @example
* const ciphertext = await aesGcmEncrypt('my secret text', 'pw');
View simple_mime_email_parse.go
package main
import (
"bufio"
"bytes"
"encoding/base64"
"errors"
"fmt"
"io"
"io/ioutil"