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 'open-uri' | |
def read_zip(io) | |
gz = Zlib::GzipReader.new(io) | |
html = gz.read | |
gz.close | |
html | |
end | |
html = nil |
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
lib/core_extensions.rb | |
class ::Object | |
# --- USE WISELY --- Trys to call the method name on self, returns the result | |
# of the method or nil if the method does not exist. | |
# | |
# Example: | |
# 'A String'.try(:downcase) # => "a string" | |
# 'A String'.try(:gsub, ' ', '-') # => "A-String" | |
# 'A String'.try(:nothing) # => nil |
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
Find hotmail addresses to whom mail was rejected as spam. | |
grep hotmail * | grep spam | ruby -e 'e = []; STDIN.each_line {|s| s.match(/to=\<([^\>]*)\>/); e << $~[1] unless $~.nil? }; puts e.uniq.join("\n")' |
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
#!/usr/bin/env ruby | |
def running?(pid) | |
begin | |
return Process.getpgid(pid) != -1 | |
rescue Errno::ESRCH | |
return false | |
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
#!/usr/bin/ruby | |
dir = 'app/views/user_mailer/' | |
`ls #{dir}`.each_line do |f| | |
f.chop! | |
next if f.index('_') == 0 | |
if f.match(/(.*)\.text\.erb/) | |
base = $~[1] | |
puts "mv #{dir}#{f} #{dir}#{base}.text.plain.erb" | |
`mv #{dir}#{f} #{dir}#{base}.text.plain.erb` | |
elsif f.match(/(.*)\.html\.haml/) |
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 ControllerHelper | |
include Singleton | |
include ActionView::Helpers | |
end | |
def url_helpers | |
ControllerHelper.instance | |
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
module ActionMailer | |
class Base | |
# I want layouts to apply to email parts seperately! | |
# An html layout is useless for the text portion and vise versa | |
# peanut butter monkey patch time! | |
def render_message(method_name, body, layout = nil) | |
if method_name.respond_to?(:content_type) | |
@current_template_content_type = method_name.content_type | |
end | |
render :file => method_name, :body => body, :layout => layout |
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
wget --save-cookies=cookies.txt --keep-session-cookies -O /dev/null --post-data="username=foo&password=bar" http://mysite.com/sign_in | |
# get the cookie out of cookies.txt | |
ab -c 3 -n 40 -C _mysite_session=c83abbab343278b168e140d33 http://mysite.com |
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
#!eruby | |
<% | |
require "cgi" | |
require 'MSNSearchServiceClient.rb' | |
# Create new CGI object for extracting search parameters | |
cgi = CGI.new | |
h = cgi.params | |
# Search criteria |
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
Giles on Rails: | |
I've been coding Ruby near-exclusively for years now. On the one hand, I want to tell you we're not all like that. On the other hand, RailsConf is just weeks away, and I'm dreading it so much that words fail me, because even though we're not all like that, an awful lot of us are exactly like that. I'm not at all surprised to find idiots defending the presentation, and that shameful, ridiculous unpology the presenter delivered is par for the course. | |
I got a similar unpology from another Rails guy after I threatened to kick his ass at a conference. This guy and his partner do a podcast, and in one episode, they had included an mp3 of a black man using racist epithets, including that mother of all racist epithets which starts with the letter N. This other Rails guy was at this conference. He's black. He had been listening to this podcast with his three-year-old daughter playing in the room. She asked him, what's that word mean, Daddy? and he didn't really want to get into that discussion at that |