Skip to content

Instantly share code, notes, and snippets.

View bpoweski's full-sized avatar

Ben Poweski bpoweski

View GitHub Profile
source ~/bin/git-completion.sh
parse_git_branch (){
git name-rev HEAD 2> /dev/null | sed 's#HEAD\ \(.*\)# (git::\1)#'
}
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='\[\033[0;35m\]\h \[\033[0;33m\]\w\[\033[00m\]\[\033[01;00m\]$(__git_ps1):'
begin
memcached_config_path = File.join(Rails.root, 'config', 'memcached.yml')
if File.exists?(memcached_config_path)
# create a memcache instance with multiple servers
memcached_config = YAML::load(File::read(memcached_config_path))
args = [:mem_cache_store]
args << memcached_config[:defaults][:servers]
args << { :namespace => memcached_config[:defaults][:namespace] }
args.flatten!

Rounded rectangle with gradient background on the iPhone, NSTokenFieldCell style.

Screenshot

Unlike my previous implementation, this one is drawn inside a single view using Core Graphics. It can thus be used for optimized, fast-scrolling cells per Apple's TableViewSuite sample.

The gradient shades are changed from that implementation, too, and the border itself is gradiented (by drawing a smaller rectangle inside a larger one that becomes the border).

You need to include the uicolor-utilities category by Ars Technica.

@bpoweski
bpoweski / gist:974870
Created May 16, 2011 17:11
Route53 gem chef recipe
define :cname_record, :hostname => nil do
name = params[:name]
hostname = params[:hostname]
subdomain = name.split(".").tap(&:shift).join(".")
remote_file "/home/#{node[:owner_name]}/.route53" do
source "route53.yml"
cookbook 'supply_chain_db'
owner node[:owner_name]
group node[:owner_name]
@bpoweski
bpoweski / benchmark.rb
Created August 6, 2011 21:29
Benchmark
require "benchmark"
require "mongoid"
require "./perf/models"
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db("mongoid_perf_test")
end
Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
@bpoweski
bpoweski / iostat_output.txt
Created August 12, 2012 21:06
Bonnie++ Extra Large Instance (m1.xlarge) EBS-Optimized (io1 with 1000 provisioned IOPS)
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
xvdap1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
xvdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
xvdc 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
xvdd 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
xvde 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
xvdk 0.00 0.00 0.00 636.00 0.00 27948.00 87.89 143.42 223.31 0.00 223.31 1.57 100.00
;;(require 'copterj.git-version) ;; Pick up DRY'd version numbers
(require 'clojure.contrib.io) ;; Needed to locate newrelic
(let [java-agent (str "-javaagent:" (clojure.contrib.io/pwd) "/lib/newrelic.jar")]
(defproject apij ~(copterj.git-version/git-describe)
:description "Hotelicopter's API"
:dependencies
[[com.hotelicopter/copterj "1.0.0-SNAPSHOT"]
@bpoweski
bpoweski / init.el
Created November 11, 2012 01:10
Emacs Clojure
(require 'package)
(defun arrange-frame (w h x y)
(let ((frame (selected-frame)))
(delete-other-windows)
(set-frame-position frame x y)
(set-frame-size frame w h)))
(arrange-frame 190 90 1200 5)
@bpoweski
bpoweski / gist:5034188
Created February 25, 2013 23:08
High memory 8XL
$ free -m
total used free shared buffers cached
Mem: 245751 12945 232805 0 967 7148
-/+ buffers/cache: 4829 240921
Swap: 1999 0 1999
@bpoweski
bpoweski / accuracy.R
Created March 29, 2014 21:27
Calculating Pi
attempts <- seq(1000, 1000000, by=10000)
estimated <- sapply(attempts, function(x) calc.pi(make.pi(x)))
ggplot(data.frame(estimated=estimated, n=attempts)) + geom_point(aes(x=n, y=estimated)) + geom_hline(yintercept=pi, color="green")