Skip to content

Instantly share code, notes, and snippets.

@sbimikesmullin
sbimikesmullin / iperf_notes.sh
Created March 3, 2018 23:42
testing network performance
# install on ubuntu
apt-get install iperf
# The quality of a link can be tested as follows:
# - Latency (response time or RTT): can be measured with the Ping command.
# - Jitter (latency variation): can be measured with an Iperf UDP test.
# - Datagram loss: can be measured with an Iperf UDP test.
# udp test
iptables -I INPUT -p udp --dport 5001 -j ACCEPT # firewall exclusion
@sbimikesmullin
sbimikesmullin / iptables-mitm-easy.sh
Created January 28, 2017 17:49
MITM proxy iptables easy setup
./forward.sh 192.30.253.113 80 172.1.9.1 9000
./forward.sh 192.30.253.113 443 172.1.9.1 9000
vim forward.sh
# setup virtual ips
# detect os
if [ "$(uname -a | cut -d' ' -f1)" == "Linux" ]; then # Ubuntu
sudo ifconfig eth0:1 172.1.9.1 up
sudo ifconfig eth0:2 172.1.9.2 up
elif [ "$(uname -a | cut -d' ' -f1)" == "Darwin" ]; then # OS/X
@sbimikesmullin
sbimikesmullin / whale.sh
Last active January 24, 2017 17:52
Aliases wrapper makes simpler interface for Docker CLI
#!/usr/bin/env bash
#
# Whale: a simpler interface for docker cli
# LICENSE: GPLv3
#
# - `whale build` # builds Dockerfile in current directory
# - `whale run` # runs last `whale build` container
# - `whale buildrun` # same as `whale build && whale run`
# - `whale sh` # opens `/bin/ash` on last `whale build` container (you can optionally specify another shell like `/bin/bash` as the first argument)
# - `whale buildrun -p 8080:80` # build and run the container with options
@sbimikesmullin
sbimikesmullin / async-fn.js
Last active April 3, 2016 18:21
Smallest Asynchronous Flow Control implementation in JavaScript
// use like: forEachAsyncSerial(Post.find(), (next, post) => { /* ... */ next(); }, () => { /* done! */ });
static forEachAsyncSerial(a, each_cb, done_cb) {
let i = 0;
const next = () => {
if (i >= a.length || false === each_cb(next, a[i++])) {
if ('function' == typeof done_cb) done_cb();
}
};
process.nextTick(next);
}
@sbimikesmullin
sbimikesmullin / recover-swap.conf.sh
Last active September 15, 2015 21:02
Upstart Automatic Swap Recovery
# /etc/init/recover-swap.conf
# author: mike smullin <mike dot smullin at wildworks dot com>
# see also: http://askubuntu.com/a/90399
# usage: start recover-swap; tailf /var/log/upstart/recover-swap.log
#
# WARNING: it is a little bit dangerous to swapoff while your service is still running;
# means OOM killer may come reap your process if it need to swap again while swapoff is going,
# which does take over an hour in our case.
#
@sbimikesmullin
sbimikesmullin / rxjava.java
Created March 15, 2015 21:07
RxJava Example
// RxJava example
String names[] = new String[]{ "Ben", "George" };
rx.Observable.from(names).subscribe((String s) -> {
System.out.println("Hey "+s+"!");
});
@sbimikesmullin
sbimikesmullin / mysql_size.sql
Created March 14, 2015 18:24
MySQL Table/Database/Index Size on Disk
SELECT table_schema, table_name AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC
LIMIT 10;
@sbimikesmullin
sbimikesmullin / mini-async.coffee
Created February 10, 2015 21:22
miniature async
module.exports =
class async
@serial: (a, cb) ->
return cb() unless a.length
a.push cb
(next = (err, result) ->
if err or 1 is a.length
a[a.length-1] err, result
a = []
return
@sbimikesmullin
sbimikesmullin / Q.coffee
Last active March 3, 2018 23:42
Q: oversimplified asynchronous flow control
# oversimplified asynchronous flow control
module.exports = new: ->
Q = []
Q.then = (fn, args...) -> Q.push(-> args.push Q.next; fn.apply null, args); @
Q.next = (err) -> Q.splice 0, Q.length-1 if err; Q.shift()?.apply null, arguments
Q.finally = (fn, args...) -> Q.push(-> fn.apply null, args); Q.next()
Q
@sbimikesmullin
sbimikesmullin / TestingScalaMBeans.scala
Last active August 29, 2015 13:57
MBeans in Scala
import java.lang.management.ManagementFactory
import javax.management.ObjectName
import scala.beans.BeanProperty
trait DamnitJimMBean {
def getCount(): Int
}
class DamnitJim extends DamnitJimMBean {
@BeanProperty var count = 0