Skip to content

Instantly share code, notes, and snippets.

View n-johnson's full-sized avatar

Nathan Johnson n-johnson

  • San Francisco, CA
View GitHub Profile
@n-johnson
n-johnson / keybase.md
Last active May 31, 2019 18:49
keybase.md

Keybase proof

I hereby claim:

  • I am n-johnson on github.
  • I am njohnson (https://keybase.io/njohnson) on keybase.
  • I have a public key whose fingerprint is ABC7 3CD9 1D37 5031 1FC3 C09A 9229 6A35 FA44 8C0A

To claim this, I am signing this object:

@n-johnson
n-johnson / gist:9771675
Created March 25, 2014 21:21
node.js whois an array of domains
var w = require('whoisclient');
var tld = '.com';
var arr = ["google","apple","superlongnottakendomain"];
whoisList(arr, function(data) {
console.log("We found one: " + data + tld);
});
function isNotTaken(data) {
@n-johnson
n-johnson / Dockerfile
Last active December 8, 2016 16:17
Ubuntu use apt mirror
# Speed up slow apt default server
ENV DIST=xenial
RUN echo "deb mirror://mirrors.ubuntu.com/mirrors.txt $DIST main restricted universe multiverse\ndeb mirror://mirrors.ubuntu.com/mirrors.txt $DIST-updates main restricted universe multiverse\ndeb mirror://mirrors.ubuntu.com/mirrors.txt $DIST-backports main restricted universe multiverse\ndeb mirror://mirrors.ubuntu.com/mirrors.txt $DIST-security main restricted universe multiverse\n$(cat /etc/apt/sources.list)" > /etc/apt/sources.list
@n-johnson
n-johnson / parse.js
Created September 14, 2016 19:39
Find `const` usage in javascript file
const fs = require('fs')
const rocambole = require('rocambole');
// Use espree instead of esprima - about twice as fast
const espree = require('espree');
rocambole.parseFn = espree.parse;
rocambole.parseContext = espree;
const parseTime = (delta) => (delta[0] * 1000 + delta[1] / 1e6) + 'ms'
#!/bin/bash
# Takes a parameter PREFIX and then prepends it to all stdin passed through
PREFIX="$1"
awk -v p="$PREFIX" '{ print "\033[90m[" p "]\033[0m" , $0; fflush(); }'
@n-johnson
n-johnson / eh.sh
Created March 25, 2016 04:36
ec2-host cached
#!/bin/bash
MAX_CACHE=21600 # 6 hours (sec)
EC2_CACHE="$HOME/.ec2_host"
file_age() {
stat -f "%Sm" -t "%s" "$1"
}
cur_time=$(date "+%s")
@n-johnson
n-johnson / last_modified.sh
Created March 25, 2016 04:20
osx last modified
#!/bin/bash
stat -f "%Sm" -t "%m-%d-%y %H:%M:%S" "$1"
@n-johnson
n-johnson / byte_range.sh
Created February 22, 2016 00:33
Bash utility to output a range of bytes from a stream
#!/bin/bash
# byte_range $start $end
# - Outputs the bytes between the starting and ending values from the stdin stream
#
# - $start - Starting byte to display
# - $end - Ending byte to display
isInteger() {
local regex_numeric='^[0-9]+$'
@n-johnson
n-johnson / time.sh
Created January 22, 2016 07:23
osx bash time w/ millisecond precision
perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000)'
@n-johnson
n-johnson / host01.sh
Created January 14, 2016 10:46
remote cpu temp monitor
#!/bin/bash
host01_temp() {
local key="host01.cpu.temp"
local temp=$(ssh stats@10.0.0.1 sensors | grep 'Physical id' | awk -F':' '{print $2 }' | awk '{print $1}' | tr -d '+' | tr -d '°C')
echo "$key $temp"
}
statsd `host01_temp`