Skip to content

Instantly share code, notes, and snippets.

@jrom
jrom / config.ru
Created October 27, 2010 00:02
Rack app that demonstrates Herkou limitation in header size
run lambda { |env|
headers = { "key"=> ("a" * 3455)} # 3454 works, 3455 don't
[200, headers, "Hello World!\n"]
}
@jrom
jrom / download-from-s3.rb
Created November 2, 2010 12:02
For downloading assets (in this case Paperclip attachments) from S3 to local filesystem
require 'aws/s3'
AWS::S3::Base.establish_connection!(
:access_key_id => 'id',
:secret_access_key => 'secret'
)
missing_uploads = [1,2,3,4] # ID's from the attachments you want to download
log = File.open('file-import-log.txt','w')
@jrom
jrom / scrolling.js
Created November 8, 2010 15:17
smooth scrolling for jQuery
$(function() {
$('a[href^=#]:not([href=#])').click(function() {
var $target = $(this.hash);
$target = $target.length && $target
|| $('[name=' + this.hash.slice(1) +']');
if ($target.length) {
var targetOffset = $target.offset().top;
$('html,body')
.animate({scrollTop: targetOffset}, 1000);
return false;
@jrom
jrom / .ackrc
Created December 9, 2010 17:31
~ $ cat .ackrc
--type-add=ruby=.haml,.rake,.rsel
--type-set=sass=.sass,.scss
@jrom
jrom / udplisten.js
Created June 9, 2011 09:36
Listens to an UDP port and logs received messages
var dgram = require('dgram');
var server = dgram.createSocket('udp4', function (msg, rinfo) {
console.log(msg.toString());
});
server.bind(8125);
@jrom
jrom / config.ru
Created June 14, 2011 14:05
Redirect with a rack heroku app to support
run lambda { |env| [301, {"Location" => "http://help.teambox.com/", "Content-Type" => "text/plain"}, ["You're being redirected..."]] }
@jrom
jrom / thin_model.rb
Created June 16, 2011 09:55
Hack to create a new skinny model from an existing one
# By James Urquhart (jamesu)
class ActiveRecord::Base
def self.thin_model
table = table_name
@@thin_model ||= Class.new(superclass).tap do |anon|
anon.class_eval { set_table_name table }
end
end
end
@jrom
jrom / gist:1162348
Created August 22, 2011 13:15
Requeue failed resque jobs
(Resque::Failure.count-1).downto(0).each { |i| Resque::Failure.requeue(i) }
@jrom
jrom / README.md
Created October 26, 2011 10:16
Middleware YAML Recorder

This is a WIP, the idea is to copy VCR's behavior but with intercepted Rack requests.

TODO

  • Specify which URL's must be intercepted/recorded
  • Ensure complex bodies are safely stored in the YAML
  • Keep some kind of application-wide list of accessed requests so tests can see what has been issued and with what parameters.
  • Add query_string to the file name so we can have two different mocks for the same URL with different query strings.
  • Whatever we find useful for it!
@jrom
jrom / statify-trimmer.rb
Created January 3, 2012 17:36
Saves trimmer templates to tmp/trimmer
tmp_path = 'tmp/trimmer'
FileUtils.mkdir_p(tmp_path)
I18n.available_locales.each do |locale|
app.get("/trimmer/#{locale}.js")
File.open("#{tmp_path}/#{locale}.js", 'w') do |f|
f.write(app.response.body.force_encoding('utf-8'))
end
end