Skip to content

Instantly share code, notes, and snippets.

View rubysolo's full-sized avatar

Solomon White rubysolo

View GitHub Profile
@rubysolo
rubysolo / gist:1047951
Created June 26, 2011 20:38 — forked from clarkware/gist:1046693
View Source for Ruby
# Toss this in your ~/.irbrc file for a convenient way
# to peruse Ruby source code in TextMate. This
# only works in Ruby 1.9!
#
# Use it in irb like so:
#
# >> require 'active_record'
# >> ActiveRecord::Base.source_for_method(:create)
class Object
@rubysolo
rubysolo / descriptive_sql_load_log.rb
Created July 19, 2011 20:42 — forked from JackDanger/descriptive_sql_load_log.rb
Let Rails display file names and line numbers for log activity.
module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
protected
# Turn:
# User Load (6.3ms) SELECT * FROM "users"
# Into:
# User Load /app/views/_partial.erb:27 (6.3ms) in `_app_views_partial_erb` SELECT * FROM "users"
@rubysolo
rubysolo / etc_init.d_unicorn_example.co.uk
Created October 27, 2011 20:04 — forked from scottlowe/etc_init.d_unicorn_example.co.uk
Ruby on Rails server setup on Ubuntu 11.04 with Nginx, Unicorn, Rbenv
#! /bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
def output name=((default=true); "caius")
puts "name: #{name.inspect}"
puts "default: #{default.inspect}"
end
output
# >> name: "caius"
# >> default: true
output "avdi"
@rubysolo
rubysolo / gist:1590176
Created January 10, 2012 17:39 — forked from jstorimer/hilong.rb
hilong -- A simply utility to show character counts for each line of input and highlight lines longer than 80 characters.
#!/usr/bin/env ruby
# A simply utility to show character counts for each line of input and
# highlight lines longer than 80 characters.
#
# Written as an example for http://jstorimer.com/2011/12/12/writing-ruby-scripts-that-respect-pipelines.html
#
# Examples:
#
# $ hilong Gemfile
@rubysolo
rubysolo / unicorn.sh
Created January 31, 2012 20:26 — forked from troex/unicorn.sh
Unicorn start/stop/restart script for debian / ubuntu
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: unicorn initscript
# Description: Unicorn is an HTTP server for Rack application
### END INIT INFO
@rubysolo
rubysolo / code2png.rb
Created February 19, 2012 22:02 — forked from peterc/code2png.rb
code2png - Render code to an image on OS X
#!/usr/bin/env ruby
# code2png - Render code to an image on OS X
# Peter Cooper (@peterc)
# MIT license
#
# code2png converts source code into a PNG graphic
# (with syntax coloring, if you want). Ideal for
# Kindle document production, RSS feeds, etc.
#
class PrimeFactor
def initialize(number)
@factors = Fiber.new do
divisor = 2
while divisor < number
while number % divisor == 0
Fiber.yield divisor
number = number / divisor
end
divisor = divisor + 1
@rubysolo
rubysolo / ar.rb
Created March 6, 2012 14:02 — forked from jbarnette/ar.rb
class ActiveRecord::Base
attr_accessible nil
def update_attributes *args
raise "Don't call #{self.class.name}#update_attributes. " +
"Mass assignment is pure evil."
end
end
@rubysolo
rubysolo / gist:1986444
Created March 6, 2012 14:03 — forked from codeincontext/gist:1831643
Upload a random twitter avatar from a directory
#!/usr/bin/env ruby
# Heavily based on https://github.com/ip2k/twitter-avatar-update
# ==== Gems ====
require 'twitter_oauth'
require 'oauth'
require 'nokogiri'
require 'open-uri'
require 'yaml'