Skip to content

Instantly share code, notes, and snippets.

@sam
sam / gist:1622281
Created January 16, 2012 18:47
Destroy unused dump zvol
zfs destroy zones/dump
@sam
sam / gist:1635893
Created January 18, 2012 21:40
Script to move repositories to Github.
export LOCAL_GIT_SERVER="[email protected]"
export GITHUB_ACCOUNT="organization"
export GITHUB_USER="username:password"
export REPOS_API="http://github.com/api/v2/json/repos"
function moveit() {
local repository="$1"
if curl -s --user $GITHUB_USER $REPOS_API/show/$GITHUB_ACCOUNT/$repository | grep "error" > /dev/null; then
curl -F "name=$GITHUB_ACCOUNT/$repository" -F "public=0" --user $GITHUB_USER $REPOS_API/create
@sam
sam / gist:1642114
Created January 19, 2012 19:44
ls filters
(master ✓) sam.github.com ls [RG]*
Gemfile Gemfile.lock Rakefile
(master ✓) sam.github.com ls [GemCN]*
CNAME Gemfile Gemfile.lock
@sam
sam / gist:1642129
Created January 19, 2012 19:46
ls with grep
(master ✓) sam.github.com ls | grep -E '^(R|G)'
Gemfile
Gemfile.lock
Rakefile
(master ✗) sam.github.com ls | grep -E '^(Gem|CN)'
CNAME
Gemfile
Gemfile.lock
@sam
sam / gist:1644593
Created January 20, 2012 02:31
Count Sources
find . \
-type d -name .git -prune \
-o -type f -name '*.gz' -prune \
-o -type f -name '*.tgz' -prune \
-o -type f -name '*.conf' -prune \
-o -type f -exec wc -l {} \; | awk '{ SUM += $1 + 1 } END {print SUM}'
module Harbor
module MailServers
class Sendmail < Abstract
attr_accessor :filter
def initialize(config = {})
@sendmail = config[:sendmail] || `which sendmail`.chomp
@filter = config[:delivery_address_filter]
@sender = config[:sender] || "bounce"
@sam
sam / config.ru
Created February 22, 2012 05:26
Harbor::Controller
require "pathname"
require Pathname(__FILE__).dirname.parent + "lib/harbor"
class Foo < Harbor::Application
class Bar < Harbor::Controller
# GET: /bar/baz
get "baz" do
response.puts "Hello World!"
end
@sam
sam / gist:2002262
Created March 8, 2012 17:36
Router Benchmark
require "benchmark"
tree_router = nil
regexp_router = nil
Benchmark::bmbm do |x|
tree_router = Router.new
regexp_router = Set.new
x.report("INSERTION: Tree") do
class Petshop < Harbor::Application
class Home < Harbor::Controller
get "/" do
# If the block doesn't return true, the request is immediately halted and you're given a 403.
basic_auth { |username, password| [ username, password ] == [ "sam", "harbor" ] }
puts "Hello World!"
end
@sam
sam / dbcompare
Created April 2, 2012 19:37
dbcompare
#!/usr/bin/env bash
SOURCE=
TARGET=
DATABASE=
TABLE=
function usage() {
cat <<"EOS"
USAGE: dbcompare -h source target database [ table ]