Skip to content

Instantly share code, notes, and snippets.

View ericychoi's full-sized avatar

Eric Choi ericychoi

  • SendGrid
  • Anaheim, CA
View GitHub Profile

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns                     on recent CPU
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  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs 4X memory

@ericychoi
ericychoi / httpsink.js
Created February 20, 2015 01:10
Simple HTTP POST Sink
var http = require('http');
http.createServer(function(request,response){
var body = "";
request.on('data', function(chunk) { body += chunk; });
request.on('end', function() {
console.log('POST: ' + body + "\n");
response.writeHead(200);
response.end();
});
}).listen(8000);
@ericychoi
ericychoi / mp3tag.pl
Last active August 29, 2015 14:25
A Perl script that sets mp3 tags based on filename
use MP3::Tag;
use Encode qw/encode decode/;
use Data::Dumper;
use strict;
use warnings;
# run it in the same directory as mp3s
# sets mp3v2 tags based on file names (assumes filenames are encoded UTF-8, which should be)
#
# filename example: 085. 2PM-01-우리집.mp3
@ericychoi
ericychoi / parse.pl
Last active January 15, 2016 18:56
SImple MIME Parser from STDIN
#!/opt/perl/bin/perl
use MIME::Parser;
use strict;
use warnings;
my $parser = MIME::Parser->new();
$parser->output_to_core(1);
$parser->decode_bodies(1);
@ericychoi
ericychoi / base64_test.go
Last active February 26, 2016 01:08
Benchmark and compare regexp vs base64 decoding for a given payload
package base64Benchmark
import (
"bytes"
"encoding/base64"
"flag"
"io/ioutil"
"os"
"regexp"
"testing"
curl -s -X GET "apidendpointp1mdw1.sendgrid.net:8082/api/swimlane/user/delete.json?userid=1886158"
curl -s -X GET "apidendpointp1mdw1.sendgrid.net:8082/api/swimlane/user/delete.json?userid=1886162"
curl -s -X GET "apidendpointp1mdw1.sendgrid.net:8082/api/swimlane/user/delete.json?userid=1886163"
curl -s -X GET "apidendpointp1mdw1.sendgrid.net:8082/api/swimlane/user/delete.json?userid=1886179"
curl -s -X GET "apidendpointp1mdw1.sendgrid.net:8082/api/swimlane/user/delete.json?userid=1886184"
curl -s -X GET "apidendpointp1mdw1.sendgrid.net:8082/api/swimlane/user/delete.json?userid=1886205"
curl -s -X GET "apidendpointp1mdw1.sendgrid.net:8082/api/swimlane/user/delete.json?userid=1886207"
curl -s -X GET "apidendpointp1mdw1.sendgrid.net:8082/api/swimlane/user/delete.json?userid=1886208"
curl -s -X GET "apidendpointp1mdw1.sendgrid.net:8082/api/swimlane/user/delete.json?userid=1886209"
curl -s -X GET "apidendpointp1mdw1.sendgrid.net:8082/api/swimlane/user/delete.json?userid=1886211"
@ericychoi
ericychoi / max_units.go
Created July 13, 2016 21:57
Go: Max Numbers
package main
import "fmt"
const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1
func main() {
@ericychoi
ericychoi / goget.sh
Created November 4, 2016 17:36
Go Get using Git Clone
# use git clone to clone the go repo to the right location in your gopath
function goget() {
# github.com/foo/bar
GIT_PATH="$@"
# git@github.com:foo/bar.git
GIT_CLONE_PATH=`echo "$GIT_PATH" | perl -lape 's!(.+?)/!git\@$1:!'`
mkdir -p "$GOPATH/src/$GIT_PATH" && git clone "$GIT_CLONE_PATH" "$GOPATH/src/$GIT_PATH"
}
@ericychoi
ericychoi / httpsink.js
Created November 9, 2016 20:40
A simple http sink in node.js
var http = require('http');
var jsonResp = {
"type": "free"
};
var jsonRespPaid = {
"type": "Paid"
}
var port = process.argv[2];
@ericychoi
ericychoi / perl-bin-script-template.pl
Last active February 19, 2017 05:10
Perl bin script template
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use Term::ANSIColor;
# usage:
#