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 / .bashrc
Created August 13, 2014 08:16
Simple function to convert a hexadecimal input to a decimal output from a linux shell. Just append this function to ~/.bashrc and reload.
h2d(){
echo $((16#$@))
}
@n-johnson
n-johnson / override.sh
Created January 29, 2015 20:12
Override a shell script in a git repo with a custom version - and ensure if the file is updated in a commit you are notified to check for breaking changes. Add the file you modified to .git/info/exclude to prevent pushing your modifications on accident.
V="9ad6a83" # Commit hash when modified, known working
START_MODIFIED=$(git log -n 1 --pretty=format:%h -- start.sh) # Last commit start.sh was modified
if [ "$V" != "$START_MODIFIED" ]
then
echo "UHOH! start.sh was updated, you need to update the custom start file!"
echo "Expected: [$V] | Retrieved: [$START_MODIFIED]"
else
var http = require('follow-redirects').http;
//top 1000
var domains = ["google.com","facebook.com","youtube.com","yahoo.com","baidu.com","wikipedia.org","qq.com","linkedin.com","live.com","twitter.com","amazon.com","blogspot.com","taobao.com","google.co.in","sina.com.cn","wordpress.com","yahoo.co.jp","yandex.ru","bing.com","ebay.com","google.de","vk.com","hao123.com","163.com","tumblr.com","pinterest.com","google.co.uk","google.fr","googleusercontent.com","microsoft.com","msn.com","ask.com","mail.ru","google.co.jp","google.com.br","weibo.com","apple.com","paypal.com","google.ru","instagram.com","google.com.hk","xvideos.com","blogger.com","google.it","tmall.com","google.es","imdb.com","soso.com","craigslist.org","sohu.com","360.cn","go.com","amazon.co.jp","stackoverflow.com","bbc.co.uk","xhamster.com","google.com.mx","neobux.com","google.ca","fc2.com","cnn.com","imgur.com","alibaba.com","wordpress.org","flickr.com","espn.go.com","adcash.com","huffingtonpost.com","odnoklassniki.ru","t.co","conduit.com","thepira
const subnetMap = { 8: 16777214, 9: 8388606, 10: 4194302, 11: 2097150, 12: 1048574, 13: 524286, 14: 262142, 15: 131070, 16: 65534, 17: 32766, 18: 16382, 19: 8190, 20: 4094, 21: 2046, 22: 1022, 23: 510, 24: 254, 25: 126, 26: 62, 27: 30, 28: 14, 29: 6, 30: 2, 31: 1};
const AWS_IP_RANGE_URL = 'https://ip-ranges.amazonaws.com/ip-ranges.json';
const CORS_URL = 'https://jsonp.afeld.me/?url=' + AWS_IP_RANGE_URL;
function filterUnique(p, c, i) { ~~p.indexOf(c) && p.push(c); return p; };
fetch(CORS_URL)
.then(function(response) {
response
@n-johnson
n-johnson / ssl.sh
Last active October 26, 2015 13:03
ssl cert parsing
_ssl() {
local adr=$1;
local _d;
_d=$(
echo -n \
| openssl s_client -connect "$adr":443 2>/dev/null \
| openssl x509 -noout -text \
);
@n-johnson
n-johnson / dig_any.sh
Last active November 26, 2015 19:18
Replacement for dig -t any since cloudflare now refuses to answer the query with the response: 'Please stop asking for ANY" "See draft-jabley-dnsop-refuse-any"'
_dig() {
local domain=$1;
local type=$2;
dig "$domain" -t "$type" \
| sed -n '/;; ANSWER SECTION/,/^$/p' \
| sed '1d' \
| sed '/^$/d';
}
@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 {}
@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 / 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)'