Skip to content

Instantly share code, notes, and snippets.

sed "s/,/\\`echo -e '\n\r'`/g"
@jrom
jrom / node-server.js
Created February 2, 2012 13:34
Super simple node file server
require('http').Server(function (req, res) {
require('fs').readFile(__dirname + require('url').parse(req.url).pathname, function (err, data) {
res.end(data);
});
}).listen(9000);
@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
@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 / 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 / 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 / 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 / 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 / .ackrc
Created December 9, 2010 17:31
~ $ cat .ackrc
--type-add=ruby=.haml,.rake,.rsel
--type-set=sass=.sass,.scss
@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;