Skip to content

Instantly share code, notes, and snippets.

View PatrickTulskie's full-sized avatar

Patrick Tulskie PatrickTulskie

View GitHub Profile
#IRC Response
=begin
Needs some work, but I could definitely see this helping those people who like to sit in IRC and be jerks when people ask questions.
You could leave your computer and continue be just as unhelpful as you could if you were still there.
=end
def irc_person_response(question)
answer = question.gsub(/How do I/, "Why would you want to")
if answer == question
answer = "Why?"
=begin
Written by: Patrick Tulskie (http://github.com/patricktulskie)
WARNING: This will delete any previous fixture dumps that you've made with the script before it runs.
Review the code and understand it before running it.
=end
namespace :db do
desc 'Create YAML test fixtures from data in an existing database. Defaults to development database automagically.
Set RAILS_ENV to override. Set FIXTURES to specify what fixtures to extract.'
task :extract_fixtures => :environment do
#!/usr/bin/env ruby
#
# usage: script/server_restarter
#
# Rails autoloading, while nice in theory, frequently doesn't work. Since Rails 2.3+
# is so fast when completely reloading the server, I wrote this script to listen to the
# given directories, and kill/restart the server when any file is changed.
#
# It's quick, simple, and it reliably reloads your application when changes are made.
#
class Array
def antiuniq
duplicates = []
clone = [] + self
while clone.length > 0
item = clone.pop
duplicates.push(item) if clone.include?(item) || duplicates.include?(item)
class AnnoyingKid
def self.why?(answer)
self.why?(answer)
end
end
AnnoyingKid.why?('because')
module Hpricot
module Hextensions
def hashify(xml_data)
hsh = {}
xml_data.each_child do |b|
key_name = b.name.strip
if key_name.length > 0
%w(rubygems benchmark).each { |gem| require gem }
puts "Outside: " + Benchmark.measure { |a| puts "Inside: " + (Benchmark.measure { |b| 10000.times { |val| puts "#{val} bananas!" } }).to_s }.to_s
%w(rubygems activesupport).each { |g| require g }
class KanyeWest
def self.outburst(name, item)
"Yo #{name}. I'm really happy for you. I'm gonna let you finish, but Beyonce had one of the best #{item.pluralize} of all time. One of the best #{item.pluralize} of all time!"
end
end
require 'rubygems'
require 'mash'
require 'hashie'
require 'benchmark'
huge_hash = { }
big_block_of_text = ";dfngsd;gndsfgnsdf;gnsdf;hndfs'hfgnh'isfgng'asifnsd;iofgbdsf;hugsdbf;isdangliusdfgn;sdfing'disv c;jvb f;jb fs;ib s;div d;dfngsd;gndsfgnsdf;gnsdf;hndfs'hfgnh'isfgng'asifnsd;iofgbdsf;hugsdbf;isdangliusdfgn;sdfing'disv c;jvb f;jb fs;ib s;div d;dfngsd;gndsfgnsdf;gnsdf;hndfs'hfgnh'isfgng'asifnsd;iofgbdsf;hugsdbf;isdangliusdfgn;sdfing'disv c;jvb f;jb fs;ib s;div d;dfngsd;gndsfgnsdf;gnsdf;hndfs'hfgnh'isfgng'asifnsd;iofgbdsf;hugsdbf;isdangliusdfgn;sdfing'disv c;jvb f;jb fs;ib s;div d;dfngsd;gndsfgnsdf;gnsdf;hndfs'hfgnh'isfgng'asifnsd;iofgbdsf;hugsdbf;isdangliusdfgn;sdfing'disv c;jvb f;jb fs;ib s;div d;dfngsd;gndsfgnsdf;gnsdf;hndfs'hfgnh'isfgng'asifnsd;iofgbdsf;hugsdbf;isdangliusdfgn;sdfing'disv c;jvb f;jb fs;ib s;div d;dfngsd;gndsfgnsdf;gnsdf;hndfs'hfgnh'isfgng'asifnsd;iofgbdsf;hugsdbf;isdangliusdfgn;sdfing'disv c;jvb f;jb fs;ib s;div d;dfngsd;gndsfgnsdf;gnsdf;hndfs'hfgnh'isfgng'asifnsd;iofgbdsf;hugsdbf;isdang
@PatrickTulskie
PatrickTulskie / array_of_hashes_total.rb
Created October 22, 2009 16:03
Used to total an array of hashes that have similar keys
require 'rubygems'
require 'money'
require 'yaml'
class Array
def total_hashes
self.inject({}) do |totals, hsh|
hsh.each { |key, value| (totals[key] = totals[key] ? value + totals[key] : value) unless %w(String Hash Array).include?(value.class.to_s) } if hsh.is_a?(Hash)
totals