This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# elixir | |
defmodule Example do | |
def work(_msg) do | |
IO.puts "called 1st function" | |
end | |
def work(_msg, data=[_a, _b, _c]) do | |
IO.puts "called 2nd function #{inspect data}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get update | |
sudo apt-get install vim | |
# generate keys and copy them over | |
ssh-copy-id -i id_rsa.pub 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/id_rsa.pub >> .ssh/authorized_keys | |
# re-read: http://stackoverflow.com/questions/8872807/hadoop-datanodes-cannot-find-namenode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://is.gd/NzZxYT | |
defmodule BinaryTree do | |
def invert([n, list]) when is_integer(n) and is_list(list) do | |
[n, invert(list)] | |
end | |
def invert([n, nc, m, mc]) | |
when is_integer(n) and is_integer(m) | |
and is_list(nc) and is_list(mc) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "thread" | |
stage_one = Queue.new | |
stage_two = Queue.new | |
stage_three = Queue.new | |
stage_one_worker = Thread.new do | |
100.times do |n| | |
stage_one << n | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
end | |
def name | |
if main? | |
"main" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
strace cmd 2> /dev/stdout | cut -d '(' -f 1 | sort | uniq | grep -v "[+=]" | sort -rn -k1,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# or `echo some-request | nc localhost 8181 -4u ` | |
MAX_READ = 1024 * 8 | |
FLAGS = 0 | |
c = Socket.new :INET, :DGRAM | |
s = Socket.pack_sockaddr_in 8181, "127.0.0.1" | |
c.send("some-request", FLAGS, s) | |
res = c.recv(MAX_READ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
require 'redis' | |
require 'json' | |
require 'timeout' | |
$publisher = Redis.new | |
$subscriber = Redis.new | |
CHANNEL = 'omg' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule DFA do | |
def accepts?(accept: accept_states, rules: rules, s: string) do | |
string | |
|> String.graphemes | |
|> List.foldl(1, fn(char, state) -> next(state: state, char: char, rules: rules) end) | |
|> member?(accept_states) | |
end | |
defp next(state: nil, char: _char, rules: _rules) do | |
nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
{ | |
"AccessKey": { | |
"UserName": "s3.deploy.foo", | |
"Status": "Active", | |
"CreateDate": "2016-11-04T16:25:27.123Z", | |
"SecretAccessKey": "secret", | |
"AccessKeyId": "access" | |
} | |
} |