This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def output name=((default=true); "caius") | |
| puts "name: #{name.inspect}" | |
| puts "default: #{default.inspect}" | |
| end | |
| output | |
| # >> name: "caius" | |
| # >> default: true | |
| output "avdi" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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. | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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' |