Skip to content

Instantly share code, notes, and snippets.

J. Whiteman jwhiteman

Block or report user

Report or block jwhiteman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jwhiteman / example.ex
Last active Dec 11, 2015
Elixir vs Ruby (pattern matching vs conditional logic)
View example.ex
# elixir
defmodule Example do
def work(_msg) do
IO.puts "called 1st function"
def work(_msg, data=[_a, _b, _c]) do
IO.puts "called 2nd function #{inspect data}"
jwhiteman / gist:7634421
Last active Dec 29, 2015
notes on getting hadoop (both single node and a cluster) going on Ubuntu LTS; there are just notes to myself and have some gaps in them. Not meant to be a tutorial or a walkthrough.
View gist:7634421
sudo apt-get update
sudo apt-get install vim
# generate keys and copy them over
ssh-copy-id -i vagrant@hnclient # move node ssh key to the client
# update /etc/hosts on each node to know at least the master; the master about the slave nodes
# make sure master can ssh into localost
cat .ssh/ >> .ssh/authorized_keys
# re-read:
jwhiteman / binary_tree.exs
Created Jan 22, 2016
invert a binary tree in Elixir
View binary_tree.exs
defmodule BinaryTree do
def invert([n, list]) when is_integer(n) and is_list(list) do
[n, invert(list)]
def invert([n, nc, m, mc])
when is_integer(n) and is_integer(m)
and is_list(nc) and is_list(mc) do
jwhiteman / pipe.rb
Created Nov 18, 2016
Simple pipeline using Threads and Queues
View pipe.rb
require "thread"
stage_one =
stage_two =
stage_three =
stage_one_worker = do
100.times do |n|
stage_one << n
View join.rb
# A reminder that join conceptually combines the stacks of the parent and child threads.
# If you consider that the stack grows downard, the child stack will sit below the parent
# stack. See output below.
def main?
Thread.current == Thread.main
def name
if main?
jwhiteman /
Created Dec 30, 2016
sort strace output
strace cmd 2> /dev/stdout | cut -d '(' -f 1 | sort | uniq | grep -v "[+=]" | sort -rn -k1,1
jwhiteman / client.rb
Last active Jan 7, 2017
UDP in Ruby - packing socket manually
View client.rb
# or `echo some-request | nc localhost 8181 -4u `
MAX_READ = 1024 * 8
s = Socket.pack_sockaddr_in 8181, ""
c.send("some-request", FLAGS, s)
res = c.recv(MAX_READ)
View processes-and-pubsub.rb
require 'httparty'
require 'redis'
require 'json'
require 'timeout'
$publisher =
$subscriber =
CHANNEL = 'omg'
jwhiteman / dfa.exs
Created Jan 27, 2017
basic DFA simulation
View dfa.exs
defmodule DFA do
def accepts?(accept: accept_states, rules: rules, s: string) do
|> String.graphemes
|> List.foldl(1, fn(char, state) -> next(state: state, char: char, rules: rules) end)
|> member?(accept_states)
defp next(state: nil, char: _char, rules: _rules) do
jwhiteman / s3.rb
Created Jan 30, 2017
Basic Aws::S3::Client usage
View s3.rb
"AccessKey": {
"UserName": "",
"Status": "Active",
"CreateDate": "2016-11-04T16:25:27.123Z",
"SecretAccessKey": "secret",
"AccessKeyId": "access"
You can’t perform that action at this time.