1> Bbsl = fun(Bin,Shift) -> <<_:Shift,Rest/bits>> = Bin, <<Rest/bits,0:Shift>> end.
#Fun<erl_eval.12.50752066>
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
_mix() | |
{ | |
local cur prev opts | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
if [[ ! -f /tmp/__mix_completion__ ]]; then | |
opts=$(for i in `mix help | grep -ve "current:" | grep -ve "iex" | awk '{ print $2" " }'`; do echo $i; done); | |
echo $opts > /tmp/__mix_completion__; | |
else |
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
# split windows like vim | |
# vim's definition of a horizontal/vertical split is reversed from tmux's | |
bind s split-window -v -c "#{pane_current_path}" | |
bind v split-window -h -c '#{pane_current_path}' | |
bind ^s split-window -v -c "#{pane_current_path}" | |
bind ^v split-window -h -c "#{pane_current_path}" | |
# move around panes with hjkl, as one would in vim after pressing ctrl-w | |
bind h select-pane -L |
A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."
- Does the design expect failures to happen regularly and handle them gracefully?
- Have we kept things as simple as possible?
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
KafkaEx.create_worker(:foo, uris: Application.get_env(:kafka_ex, :brokers), consumer_group: "bar") | |
Enum.each(1..1000, fn x -> KafkaEx.produce("foo", 0, "bar#{x}") end) | |
KafkaEx.fetch("foo", 0, worker_name: :foo, max_bytes: 100) | |
# output | |
""" | |
[%KafkaEx.Protocol.Fetch.Response{partitions: [%{error_code: 0, | |
hw_mark_offset: 1002, last_offset: 2, | |
message_set: [%KafkaEx.Protocol.Fetch.Message{attributes: 0, | |
crc: 2491399380, key: "", offset: 0, value: "bar"}, | |
%KafkaEx.Protocol.Fetch.Message{attributes: 0, crc: 702483308, key: "", |
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
CSV.open('/tmp/sub.csv').each_with_object(Hash.new(0)) { |x,hash| hash[x[1]] += 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
get '/twitter/:name' do | |
content_type :json | |
sorted_influencers(params[:name]) | |
end | |
def sorted_influencers(name) | |
# get first 2 tweets | |
tweets = client.user_timeline(name)[0,1] | |
# for each tweet, get the retweeters | |
arr = tweets.map do |tweet| |
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
class RomanNumerals | |
NUM_TO_ROMAN = { 1000 => 'M', 900 => 'CM', 500 => 'D', 400 => 'CD', 100 => 'C', 90 => 'XC', 50 => 'L', 40 => 'XL', 10 => 'X' , 9 => 'IX', 5 => 'V', 4 => 'IV', 1 => 'I' } | |
class << self | |
def to_roman(num) | |
NUM_TO_ROMAN.each_with_object("") { |(k,v), mem| mem << (v * (num / k)); num = num % k } | |
end | |
def from_roman(roman) |
In this article, I'll walk through a basic Rails (3.2.x) setup for creating a nested resource for two models. Nested resources work well when you want to build out URL structure between two related models, and still maintain a RESTful convention. This code assumes you are running RVM to manage Ruby/Gem versions, and Git for version control.
$ mkdir family # create rvm gemset
$ echo "rvm use --create ruby-1.9.2@family" > family/.rvmrc
$ cd family # install rails
$ gem install rails # create new rails project
$ rails new . # version control
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
def fib(n) | |
(0..n).inject([1,0]) { |(a,b), _| [b, a+b] }[0] | |
end |