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
-- Demonstration of MySQL bug and a work-around. | |
-- See http://bugs.mysql.com/bug.php?id=36772 | |
-- It is fixed in MySQL 5.0.74 | |
DROP TABLE `test`; | |
CREATE TABLE `test` ( | |
`id` INT | |
); | |
INSERT INTO `test` VALUES |
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 Enumerable | |
def group_by_individual | |
grouped = {} | |
each do |item| | |
yield(item).each do |key| | |
grouped[key] ||= [] | |
grouped[key] << item | |
end | |
end | |
grouped |
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
require 'rational' | |
class Numeric | |
def to_r(rounding = 10_000) | |
Rational((self * rounding).to_i, rounding) | |
end | |
end | |
class Rational | |
def to_proper |
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
require 'rubygems' | |
require 'httparty' | |
require 'time' | |
require 'active_support' | |
File.read("#{ENV['HOME']}/.gitconfig").match(/token = (\w+)/) | |
TOKEN = $1 | |
class Github | |
include HTTParty |
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
# jQuery style method chaining https://twitter.com/grossberg/status/1297223439 | |
class Thing | |
attr_accessor :name | |
def initialize(name) | |
self.name = name | |
end | |
def announce |
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/ruby | |
files = {} | |
Dir.glob('**/*').each do |file| | |
basename = File.basename(file).downcase | |
if File.file?(file) | |
files[basename] ||= [] | |
files[basename] << file | |
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
# Nginx cache busting rewriter, best used on assets that have long-lived expires. | |
# | |
# Rewrites like so: | |
# blah.com/release_ab2ea212312.../file.css => blah.com/file.css | |
# | |
location ~ ^/release_(.*?)/ { | |
rewrite ^/release_(.*?)/(.*)$ /$2 last; | |
} |
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 /some/rails/project/script/runner | |
# Shows every class that contains capitalized method names and the "offending" methods. | |
methods = {} | |
ObjectSpace.each_object(Class) do |klass| | |
capitalized_methods = klass.methods.select { |m| m =~ /[A-Z]/ } | |
unless capitalized_methods.empty? | |
methods[klass] = capitalized_methods | |
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
def make_class(klass) | |
::Object.class_eval " | |
class #{klass} < #{self} | |
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
88888! |