Skip to content

Instantly share code, notes, and snippets.

View betawaffle's full-sized avatar

Andrew Hodges betawaffle

View GitHub Profile
function knife-ips {
knife search node "name:$1" -aec2.public_ipv4 | grep 'ec2.public_ipv4' | awk '{print $2}'
}
# example: knife-ips "my-node-name-prefix*"
@betawaffle
betawaffle / elixir-0.10.2
Last active December 22, 2015 07:19
Dockerfiles
FROM ubuntu
MAINTAINER Andrew Hodges "[email protected]"
ENV REFRESHED_AT 2013-09-04
RUN sed 's/main$/main universe/' -i /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y
defmodule Macro do
# ...
def extract_expressions({ :__block__, _, exprs }), do: exprs
def extract_expressions(nil), do: []
def extract_expressions(expr), do: [expr]
# ...
end
defmodule BitString.Example do
import BitString
defbitstring data_frame do
_ :: 1
stream_id :: 31
flags :: 8
length :: 24
_ :: 1
_ :: 7
@betawaffle
betawaffle / in_fibers.rb
Created May 17, 2013 11:43
Extensions to Enumerable for Threads and Fibers
require 'fiber' # for Fiber#alive?
module Enumerable
DEFAULT_MAX_FIBERS = 20
def each_in_fibers(max_fibers = nil, &block)
# If the enumerable object can tell us how big it is, cool.
# Unlike #each_in_threads, it doesn't really matter here.
# BUT I'M GOING TO DO THIS ANYWAY! BWAHAHAHAA!
if respond_to? :size
#!/bin/sh
lsof | grep facebook | awk -F'>' '{print $2}' | sort | uniq -c
CREATE OR REPLACE VIEW table_stats AS (
SELECT t.relname AS table,
n_live_tup AS approx_rows,
heap_blks_read + heap_blks_hit AS reads,
round(100 * heap_blks_hit::numeric / (heap_blks_hit + heap_blks_read + 0.0001), 3) AS cache_hit_rate,
round(100 * idx_blks_hit::numeric / ( idx_blks_hit + idx_blks_read + 0.0001), 3) AS idx_cache_hit_rate,
round(100 * idx_scan::numeric / ( seq_scan + idx_scan + 0.0001), 3) AS idx_usage_pct
FROM pg_statio_user_tables AS t
FULL OUTER
JOIN pg_stat_user_tables
module WithArchive
def with_archive
columns = column_names
archive_class = const_get(:Archive)
archive_columns = columns.map { |c| c == 'state' ? "'disabled' AS state" : c }
from <<-sql
(#{unscoped.select(columns.join(', ')).to_sql}
UNION
#{archive_class.unscoped.select(archive_columns.join(', ')).to_sql}
) as #{table_name}
-module(trie).
%% Compile Options
-compile({no_auto_import, [get/2, put/2]}).
%% API
-export([get/2,
new/0,
put/2,
put/3]).
@betawaffle
betawaffle / bash_expansion.erl
Created September 29, 2012 00:20
Bash Expansion Interview Answer
expand(Bin) ->
expand_1(Bin, [<<>>], []).
append(C, Prefixes) ->
lists:map(fun (Prefix) ->
<<Prefix/binary, C>>
end, Prefixes).
expand_1(Bin, Prefixes, Acc) ->
expand_1(Bin, Prefixes, Prefixes, Acc).