Skip to content

Instantly share code, notes, and snippets.

View jqr's full-sized avatar

Elijah Miller jqr

View GitHub Profile
-- 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
module Enumerable
def group_by_individual
grouped = {}
each do |item|
yield(item).each do |key|
grouped[key] ||= []
grouped[key] << item
end
end
grouped
require 'rational'
class Numeric
def to_r(rounding = 10_000)
Rational((self * rounding).to_i, rounding)
end
end
class Rational
def to_proper
require 'rubygems'
require 'httparty'
require 'time'
require 'active_support'
File.read("#{ENV['HOME']}/.gitconfig").match(/token = (\w+)/)
TOKEN = $1
class Github
include HTTParty
# jQuery style method chaining https://twitter.com/grossberg/status/1297223439
class Thing
attr_accessor :name
def initialize(name)
self.name = name
end
def announce
#!/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
@jqr
jqr / nginx.conf
Created March 26, 2009 19:52
Nginx cache busting rewriter
# 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;
}
#!/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
def make_class(klass)
::Object.class_eval "
class #{klass} < #{self}
end
"
end
88888!