Skip to content

Instantly share code, notes, and snippets.

@bmarini
bmarini / chef-server-virtualbox-bootstrap.sh
Created January 3, 2011 19:56
Quick start to setup a chef server on virtualbox
#!/bin/bash
#
# Install virtualbox:
# - http://www.virtualbox.org/wiki/Downloads
# - Download iso: http://releases.ubuntu.com/10.10/
# - Create a new virtualbox using the iso as the install media
# - Change network adapter to bridged
# - Use ifconfig to get ip address
#
# Once you have a clean install of ubuntu...
@bmarini
bmarini / default.vcl.pl
Created June 30, 2011 18:01
A good varnish config for a Rails app
# https://www.varnish-cache.org/docs/2.1/tutorial/vcl.html
# https://www.varnish-cache.org/trac/wiki/VCLExamples
# Summary
# 1. Varnish will poll the backend at /health_check to make sure it is
# healthy. If the backend goes down, varnish will server stale content
# from the cache for up to 1 hour.
# 2. Varnish will pass X-Forwarded-For headers through to the backend
# 3. Varnish will remove cookies from urls that match static content file
# extensions (jpg, gif, ...)
@bmarini
bmarini / progress_bar.rb
Created September 14, 2011 21:55
CLI progress bar in ruby
class ProgressBar
def initialize(units=60)
@units = units.to_f
end
def print(completed, total)
norm = 1.0 / (total / @units)
progress = (completed * norm).ceil
pending = @units - progress
Kernel.print "[#{'=' * progress }#{' ' * ( pending )}] #{percentage(completed, total)}%\r"
@bmarini
bmarini / app.coffee
Created November 7, 2013 23:45
ui router logging...
App.run ($rootScope, $filter, $log) ->
$rootScope.$on( '$stateChangeStart', (ev, to, toParams, from, fromParams) ->
$log.info('state change from ', from.name, $filter('json')(fromParams), ' to ', to.name, $filter('json')(toParams))
)
@bmarini
bmarini / threads-and-queues.rb
Created May 4, 2013 18:00
Playing with threads and queues.
#!/usr/bin/env ruby
require 'thread'
# Usage ./list-files [DIRECTORY]
WORKERS = 5
queue = Queue.new
@results = Queue.new
threads = []
@bmarini
bmarini / msplit.rb
Created March 3, 2013 20:47
Multi Split == Multi Recursion
module MultiSplit
def msplit(*delimiters)
return [ self ] if delimiters.empty?
if idx = index( delimiters.first )
[ self[ 0...idx ] ] + self[ ( idx + delimiters.first.length )..-1 ].msplit( *delimiters )
else
msplit( *delimiters[1..-1] )
end
end
@bmarini
bmarini / Procfile
Created May 25, 2012 17:51
Goliath app to serve static files
web: bundle exec ruby app.rb -sv -e prod -p $PORT
@bmarini
bmarini / .gitconfig
Created March 17, 2012 22:03
My global git config
[color]
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
@bmarini
bmarini / potential-ff-api.rb
Created January 28, 2012 00:30
Toying with apis
it "has a nice api" do
# To set the video bitrate of the output file to 64kbit/s:
# ffmpeg -i input.avi -b:v 64k output.avi
builder = FastForward.build do |ff|
ff.input "input.avi"
ff.output "output.avi" do |o|
o.bitrate("64k").stream("video")
end
end
@bmarini
bmarini / ui.js.coffee
Created January 2, 2012 18:54
Half-assed port of event-map feature from backbone
class UI
container: null
events: { }
constructor: () ->
this.bindEvents()
bindEvents: () ->
for event_type_and_selector, callback of @events
[event_type, selector] = event_type_and_selector.split(' ')