Skip to content

Instantly share code, notes, and snippets.

View bturnbull's full-sized avatar

Brian Turnbull bturnbull

View GitHub Profile
@bturnbull
bturnbull / accum.ex
Created August 30, 2016 18:48
Elixir Stream.transform Accumulation
# Simplified representation of source data
data = ["A", "B", "B", "A", "C", "A", "D"]
Stream.transform(data, "", fn(line, acc) ->
if line == "A" do
if acc == "", do: {[], line}, else: {[acc], line}
else
{[], acc <> line}
end
end) |> Enum.to_list
# Desired: ["ABB", "AC", "AD"]
@bturnbull
bturnbull / gist:1243484
Created September 26, 2011 21:38
CoffeeScript Namespacing
#### app/assets/javascripts/foo.js.coffee
Foo =
bar: ->
"baz"
# Have to add this to get Foo into the global namespace
# so Jasmine tests can see it
window.Foo = Foo
@bturnbull
bturnbull / twitter_quitter_lister.rb
Created June 1, 2011 15:55 — forked from bcardarella/twitter_quitter_lister.rb
Quickly find out who among the people you follow are not following you back
require 'twitter'
# You'll need to get this info from your Twitter Developer account
Twitter.configure do |config|
config.consumer_key = YOUR_CONSUMER_KEY
config.consumer_secret = YOUR_CONSUMER_SECRET
config.oauth_token = YOUR_OAUTH_TOKEN
config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
end
map.resources :teams, :member => {:review => :get, :completed => :any, :disqualify => :put, :post_receive_hook => :post},
:collection => {:statistics => :get, :dashboard => :get, :search => :get} do |team|
team.resources :invites, :controller => 'team_invites'
team.resources :comments, :controller => 'comments'
team.resources :verification_results, :as => 'verification-results', :only => [:index, :show, :create]
team.resources :members, :controller => 'teams', :only => [:destroy]
end
source /Users/reinh/.screenrc
# Default screens
split
screen -t autospec 1 ./script/autospec
focus
screen -t shell1 0
module CTGW
class Application < Sinatra::Base
helpers do
def protect!
unless authorized?
response['WWW-Authenticate'] = %(Basic realm="ClearTool Remote Gateway")
response['Content-Type'] = 'application/x-yaml'
halt [401, CTGW::Response.new(
:status => 'error',
## monit.d/memcached.monitrc
check process memcached
group memcached
with pidfile /var/run/memcached/memcached.pid
start program = "/etc/init.d/memcached start"
stop program = "/etc/init.d/memcached stop"
if failed port 11211 4 times within 5 cycles then restart
if 4 restarts within 5 cycles then timeout
depends on memcached_bin
#
# apache tuned to just exhaust memory under load with mri
#
# ree shows system savings of ~60 MB over mri with 4 concurrent requests under light load
# for approx 23% decrease in memory usage
#
# free/swap idle -- 272008 / 30288
# free/swap ree -- 71812 / 30288
# free/swap idle -- 271748 / 30284
# free/swap mri -- 12908 / 32324
# First extend ActiveRecord::Base to allow us to override connections
module ActiveRecord
class Base
# Sets the active connection to conn and runs the given block. Active
# connection is reset to it's previous value once the block finishes.
def self.using_connection(conn)
old_connection = use_connection(conn)
ret = yield if block_given?
use_connection(old_connection)