Skip to content

Instantly share code, notes, and snippets.

@namelessjon
namelessjon / xkcd.rb
Created October 30, 2008 20:12
xkcd application
#!/usr/bin/env ruby
require "rubygems"
require "sinatra"
require "hpricot"
require "open-uri"
class XKCD
attr_accessor :all
@namelessjon
namelessjon / split_repo.bash
Created March 24, 2010 02:44 — forked from pk/split_repo.bash
Script to split out the subdirectory from a repository to it's own repo
#!/bin/bash
FROM=$1
TO=$2
echo "Spliting '$TO' from '$FROM'"
git clone --no-hardlinks $FROM $TO
cd $TO
git filter-branch --prune-empty --subdirectory-filter $TO HEAD -- --all
git reset --hard
git gc --aggressive
git prune
@namelessjon
namelessjon / gist:342496
Created March 24, 2010 17:01
cpio and xz archiving script
#!/usr/bin/ruby
# cpioxz.rb
# Jonathan D. Stott <jonathan.stott@gmail.com>
if ARGV.empty?
warn "Usage: #{$0} directory [directories+]"
exit 1
end
ARGV.each do |dir|
@namelessjon
namelessjon / gist:352597
Created April 2, 2010 00:54
brute-force history rewriting for dm adapters
#!/usr/bin/ruby
# rewrite_history.rb
# Jonathan D. Stott <jonathan.stott@gmail.com>
require 'fileutils'
adapters = %w{
mysql_adapter.rb
postgres_adapter.rb
sqlite3_adapter.rb
oracle_adapter.rb
@namelessjon
namelessjon / repo_combine.bash
Created April 2, 2010 16:03
script to merge two dispirate bits of history for dm adapters
#!/bin/bash -e
repo_combine () {
ADAPTER=$1
if [ ! -d dm-more ]; then
echo "Cloning solnic's adapter"
git clone git://github.com/solnic/dm-more.git
cd dm-more
git fetch
@namelessjon
namelessjon / dm-more-rewrite.rb
Created April 10, 2010 10:30
Split and re-write dm-more history
#!/usr/bin/ruby
# Jonathan D. Stott <jonathan.stott@gmail.com>
require 'fileutils'
require 'octopi'
include Octopi
def sh(command)
system command || abort(command)
end
@namelessjon
namelessjon / own-mustache.rb
Created June 8, 2010 14:27
Simple implentation for embedding mustache template in a script
#!/usr/bin/ruby
# Copyright (c) 2010 Jonathan Stott, unless otherwise noted
#
# Permission is hereby granted, free of charge, to any person ob-
# taining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restric-
# tion, including without limitation the rights to use, copy, modi-
# fy, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is fur-
# nished to do so, subject to the following conditions:
@namelessjon
namelessjon / unicorn.config.dev.rb
Created June 8, 2010 18:00
Simple-ish reloading of the important parts of an app on changes
# Sample configuration file for Unicorn (not Rack)
worker_processes 1
# listen on the sinatra port
listen 4567
# feel free to point this anywhere accessible on the filesystem
pid "#{ENV['XDG_CACHE_HOME']}/unicorn.pid"
stdout_path "#{ENV['XDG_CACHE_HOME']}/unicorn.log"
@namelessjon
namelessjon / gist:467349
Created July 7, 2010 21:57
basic hit counter in redis
#!/usr/bin/ruby
# Copyright (c) 2010,2011 Jonathan Stott
#
# Permission is hereby granted, free of charge, to any person ob-
# taining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restric-
# tion, including without limitation the rights to use, copy, modi-
# fy, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is fur-
# nished to do so, subject to the following conditions:
@namelessjon
namelessjon / gist:667660
Created November 8, 2010 12:42
Code to recursively clean a params hash.
# Copyright (c) 2010,2011 Jonathan Stott
#
# Permission is hereby granted, free of charge, to any person ob-
# taining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restric-
# tion, including without limitation the rights to use, copy, modi-
# fy, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is fur-
# nished to do so, subject to the following conditions:
#