Skip to content

Instantly share code, notes, and snippets.

View trevorturk's full-sized avatar

Trevor Turk trevorturk

  • Chicago
View GitHub Profile
# Run rake db:size to get a print of your database size in bytes.
# Run rake db:tables:size to get the sizes for individual tables
# Works for MySQL and PostgreSQL. Not tested elsewhere.
namespace :db do
desc 'Print data size for entire database'
task :size => :environment do
database_name = ActiveRecord::Base.connection.instance_variable_get("@config")[:database]
adapter = ActiveRecord::Base.connection.adapter_name.downcase
class JsonHax
def initialize(app)
@app = app
end
def call(env)
if env['CONTENT_TYPE'] == 'application/json'
env['CONTENT_TYPE'] = 'application/xml'
env['REQUEST_URI'].gsub!(/\.json/, '.xml')
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
Rails CMS alternatives
======================
Active projects:
---------------
adva-cms
repo: http://github.com/svenfuchs/adva_cms/
site: http://adva-cms.org/
Last update: 11/24/09
"the cutting edge Rails CMS platform"
@trevorturk
trevorturk / shortwave.txt
Created October 16, 2009 14:34 — forked from mislav/waves.txt
Shortwave config
> This is a Shortwave configuration file for http://shortwaveapp.com/
* http://%s http://
g http://www.google.com/search?q=%s Google Search
gm http://gmail.com Gmail
gc http://google.com/calendar Google Calendar
gd http://docs.google.com Google Docs
gg http://groups.google.com Google Groups
gw http://wave.google.com Google Wave
ip http://instapaper.com/u Instapaper
@trevorturk
trevorturk / gist:188334
Created September 17, 2009 03:40 — forked from dhh/gist:45076
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName example.com
# ServerAlias *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
@trevorturk
trevorturk / deploy.rb
Created September 9, 2009 16:41 — forked from Sutto/deploy.rb
task :check_revision do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "***************************************************"
puts "WARNING: HEAD != origin/master... need to git push?"
puts "***************************************************"
end
end
before "deploy", "check_revision"
# how to follow bit.ly style urls to get at the real url
require 'rubygems'
require 'curb'
client = Curl::Easy.new('http://bit.ly/fleakr') do |config|
config.follow_location = true
config.max_redirects = 5
end
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
# Lighter -- Campfire from the command line
# usage: ruby lighter.rb subdomain "Main Room" macournoyer@gmail
require "rubygems"
require "tinder"
require "readline"
require "highline/import"
class Lighter
def initialize(room)
@room = room