Skip to content

Instantly share code, notes, and snippets.

View betawaffle's full-sized avatar

Andrew Hodges betawaffle

View GitHub Profile
class Timers
def initialize
@timers = SortedSet.new
@mutex = Mutex.new
@mutex.synchronize do
@thread = Thread.new { loop }
@thread.abort_on_exception = true
end
end
@acapilleri
acapilleri / gist:6898533
Last active December 25, 2015 01:49
Rails App ruby 2.1 MRI vs Rubinius 2.0
Server:
iMac
Mac10,1
Intel Core 2 Duo
3,06 GHz
Cache L2: 3 MB
RAM: 8 GB
bus: 1,07 GHz
@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
@jpetazzo
jpetazzo / README.md
Last active August 21, 2019 17:55
Give network superpowers to docker

Unionize: network superpowers for your docker containers

Unionize lets you connect together docker containers in arbitrarily complex scenarios.

Note: I recommend to use https://github.com/jpetazzo/pipework instead.

  • pipework is a better name than unionize
  • it's hosted on a "real" github repo instead of a small gist :-)

Now if you want Unionize, it's still here. Just check those examples.

#!/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
@ewoodh2o
ewoodh2o / a_description.md
Created October 3, 2012 19:50
Bash-Style Curly Brace Expansion

Bash-Style Curly Brace Expansion

Expands the curly-brace notation as supported by Bash.

expand "ab{c,d}e"
  => [ "abce", "abde" ]

expand "ab{c,d}e{1,2}"
 => [ "abce1", "abce2", "abde1", "abde2" ]
@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).
@ferd
ferd / app_deps.erl
Created September 23, 2012 05:33
Quick escript to generate a visualization of app dependencies in Erlang/OTP.
%%% Run with 'escript app_deps.erl'
%%% Change the path in filelib:wildcard/1 as required to capture all
%%% your dependencies.
%%%
%%% Rectangular nodes will represent library apps (no processes involved)
%%% and the circular nodes will represent regular apps. An arrow going from
%%% 'A -> B' means 'A depends on B'.
%%%
%%% This script depends on graphviz being present on the system.
-module(app_deps).
@abeluck
abeluck / gpg-offline-master.md
Last active October 22, 2023 02:59 — forked from KenMacD/cmd.md
GPG Offline Master Key w/ smartcard