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
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
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
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
-- 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
import os, re | |
class CachedFileSearch(object): | |
"""Cached File Search""" | |
def __init__(self, dir): | |
self.dir = dir | |
self.all_files = os.popen('find ' + dir).read() | |
self.clear_cache() | |
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 ApplicationHelper | |
def self_url(options = {}) | |
url_for(request.path_parameters.merge(options)) | |
end | |
end | |
describe ApplicationHelper do | |
describe '#self_url' do | |
before(:each) do | |
# using params we can easily detect a reverse merge with |
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
# Re: http://twitter.com/danielmorrison/status/1149336565 | |
require 'rubygems' | |
require 'httparty' | |
require 'hpricot' | |
url = 'http://rubyonrails.org' | |
document = Hpricot.parse(HTTParty.get(url)) | |
scrape = { |
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
# http://facets.rubyforge.org/doc/api/core/classes/Array.html#M000145 | |
require 'rubygems' | |
require 'facets' | |
class Array | |
def permutations(min = 0, max = size + 1) | |
variations = [] | |
(min..max).each do |permutation_size| | |
permutation(permutation_size) do |permutation| |
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 'pathname' | |
class File | |
def self.relative_symlink(old_file, new_file) | |
symlink(relative_path(File.dirname(new_file), old_file), new_file) | |
end | |
def self.relative_path(base_path, file) | |
Pathname.new(File.expand_path(file)).relative_path_from(Pathname.new(File.expand_path(base_path))).to_s | |
end | |
end |