Skip to content

Instantly share code, notes, and snippets.

# 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

works in erlang

1> Bbsl = fun(Bin,Shift) -> <<_:Shift,Rest/bits>> = Bin, <<Rest/bits,0:Shift>> end.
#Fun<erl_eval.12.50752066>

fails in elixir (1.3.4)

@bjhaid
bjhaid / service-checklist.md
Created September 23, 2016 15:11 — forked from acolyer/service-checklist.md
Internet Scale Services Checklist

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?
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: "",
@bjhaid
bjhaid / sip.conf
Last active August 29, 2015 14:27
[general]
transport=udp
localnet=192.168.29.0/255.2
directmedia=nonat
externaddr=x.x.x.x
disallow=all
bindaddr=192.168.29.184
context=public
allowoverlap=no
udpbindaddr=192.168.29.184
@bjhaid
bjhaid / gist:175c7ac4601a4beb8fb5
Created July 18, 2015 00:53
Vigenère Cipher (Hex XOR Variant)
VigenereHexXOR = fun(Plain, KeyList) -> G = fun([H|T], [B|R], Q, List, F) ->
F(T, R, Q, [H bxor list_to_integer(B, 16)|List], F);
(Act, [], Q, List, F) ->
F(Act, Q, Q, List, F);
([], _, _, List, _) -> [integer_to_list(X, 16) || X <- lists:reverse(List)]
end,
G(Plain, KeyList, KeyList, [], G)
end.
VigenereHexXOR("cool!", ["01", "3F"]).
@bjhaid
bjhaid / all_elixir_auto_complete.bash
Last active March 25, 2017 10:29
Bash Auto Completion for elixir
_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
@bjhaid
bjhaid / random_tail.sh
Created June 16, 2015 20:41
How to view random parts of a stream
awk 'BEGIN {srand()} !/^$/ { if (rand() <= .01) print $0}'
@bjhaid
bjhaid / test.erl
Created May 18, 2015 00:55
Compilation errors with bitstring spec
-module(test).
-compile([export_all]).
-spec foo(<<_:32, _:_*8>>) -> list.
foo(<<X:32, Y/binary>>) -> [X, Y].
-module(isbn).
-export([generate_signed_url/2]).
%%http://docs.aws.amazon.com/AWSECommerceService/latest/DG/rest-signature.html
generate_signed_url(Secret, Url) -> [H, T] = sort_url_params(append_timestamp(Url)),
H ++ "?" ++ T ++ "&Signature=" ++ hash_url_params(Secret, prepend_request_header(T)).
encode_url(Url) -> http_uri:encode(Url).