This file contains 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
require "test/unit" | |
class GHUserTest < Test::Unit::TestCase | |
def setup | |
@user = GHUser.new("bensie") | |
end | |
def test_has_a_name | |
assert_equal "James Miller", @user.name | |
end |
This file contains 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
require "bundler/setup" | |
require "nokogiri" | |
builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| | |
xml.name "James" do | |
xml.number 1234 | |
end | |
end |
This file contains 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
# Any unmatched request within the /api/ namespace should render 404 as JSON | |
# Stop the request here so that JSON gets returned instead of having it | |
# run through the whole Rails stack and spit HTML. | |
get "/*" do | |
halt_with_404_not_found | |
end | |
post "/*" do | |
halt_with_404_not_found | |
end |
This file contains 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
require "celluloid" | |
class Runner | |
include Celluloid | |
def initialize | |
if block_given? | |
puts "starting instance run" | |
yield self | |
puts "finished instance run" |
This file contains 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 Time | |
def self.iso8601(time) | |
formatter = NSDateFormatter.alloc.init | |
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" | |
formatter.dateFromString time | |
end | |
end |
This file contains 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
# Assumes you're looking to add a unique index to [:field1, :field2] and want to find duplicates to remove/fix them | |
SELECT id, field1, field2, count(*) FROM table GROUP BY field1, field2 HAVING count(*) > 1 |
This file contains 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
for i in `sudo /usr/local/src/passenger-XXX/bin/passenger-memory-stats | grep "Passenger RackApp" | awk '{if ($4>400) print $1}'`; do kill -9 $i; done |
This file contains 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 NoWww | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request = Rack::Request.new(env) | |
if request.host.starts_with?("www.") | |
[301, {"Location" => request.url.sub(/www./, "")}, self] |
This file contains 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
SELECT table_schema "DB Name", SUM( data_length + index_length) / 1024 / 1024 "DB Size in MB" FROM information_schema.TABLES GROUP BY table_schema; |
This file contains 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
>> SSHKey.generate.ssh_public_key | |
ArgumentError: invalid string for Integer | |
from { } in SSHKey#ssh_public_key_conversion at /Users/jkmiller/.rvm/gems/rbx-head/gems/sshkey-1.3.0/lib/sshkey.rb:160 | |
from Array#each at kernel/bootstrap/array.rb:66 | |
from SSHKey#ssh_public_key_conversion at /Users/jkmiller/.rvm/gems/rbx-head/gems/sshkey-1.3.0/lib/sshkey.rb:159 | |
from SSHKey#ssh_public_key at /Users/jkmiller/.rvm/gems/rbx-head/gems/sshkey-1.3.0/lib/sshkey.rb:128 | |
from { } in Object#irb_binding at (irb):5 | |
from Rubinius::BlockEnvironment#call_on_instance at kernel/common/block_environment.rb:72 |