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 / 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`
@n-johnson
n-johnson / latency.txt
Created November 8, 2015 07:47 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@n-johnson
n-johnson / cloudfront_ip.sh
Created October 26, 2015 14:13
cloudfront ip enumeration
# req: prips
curl https://ip-ranges.amazonaws.com/ip-ranges.json \
| grep -B 2 CLOUDFRONT \
| grep 'ip_prefix' \
| awk '{ print $2 }' \
| tr -d '",' \
| xargs -I{} prips {}