Skip to content

Instantly share code, notes, and snippets.

@ryanbriones
ryanbriones / config-initializers-mongrel_fix.rb
Created September 28, 2009 12:05
fix for using mongrel_rails with Rails ~> 2.3.3
require 'rewindable_input'
ActionController::Dispatcher.middleware.insert_before ActionController::ParamsParser, RewindableInput
@ryanbriones
ryanbriones / e
Created October 24, 2009 05:25
script for opening Emacs.app from mac command-line
#!/bin/sh
# -*- bash -*-
if [ $# -gt 0 ]; then
if [ ! -f $1 ] && [ ! -d $1 ]; then
touch $1
fi
if [ -d $1 ]; then
realpath=`cd $1;pwd`
@ryanbriones
ryanbriones / gist:220552
Created October 28, 2009 15:46
overriding clearance default routes
# i think the way to do it is that the route definitions in app/config/routes.rb need to be exactly the same,
# but with your additions, as the route definitions in the clearance gem. then, your definitions will override
# clearance's ...or something
# in my case though, i actually have a SessionsController and UsersController in my app that inherit from
# clearance's, but confirmations still works. don't remember the specifics
ActionController::Routing::Routes.draw do |map|
map.root :controller => 'home'
map.dashboard '/dashboard', :controller => 'home', :action => 'dashboard'
describe SomeController do
before(:each) do
# exisiting mock setup
end
# add to mocks, placement after before is key
it_should_behave_like "a before filter thingie"
it "blah"
end
@ryanbriones
ryanbriones / gist:240942
Created November 23, 2009 07:03
first pass at what my sinatra-like java servlet would look like
import org.sinatraLikeServlet.*;
public class MyApplication extends SinatraLikeHTTPServlet {
@get("/")
public void index(SinatraLikeHTTPServletRequest req
SinatraLikeHTTPServletResponse resp) {
MyResource[] resources = MyResource.findAll();
req.setAttribute("resources", resources);
}
@ryanbriones
ryanbriones / gist:246599
Created December 1, 2009 20:17
send email to gmail (STARTTLS) using ruby >=1.8.7
# send email using STARTTLS; Net::SMTP#enable_starttls requires ruby >=1.8.7
# this hack is needed for rails <2.3; apparently >=2.3 has something for this already
ActionMailer::Base.class_eval do
private
def perform_delivery_smtp(mail)
destinations = mail.destinations
mail.ready_to_send
smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
@ryanbriones
ryanbriones / gist:251748
Created December 8, 2009 15:57
ahh, my first night in chicago after my iPhone, my only alarm clock, broke. good times.
require 'time'
loop do
if Time.now > Time.parse('06:30')
`/usr/bin/open "/Users/ryanbriones/Music/iTunes/iTunes Music/Daft Punk/Discovery/01 One More Time.mp3"`
break
end
puts "#{Time.now} not #{Time.parse('06:30')}"
sleep 5
if [ "$1" ]; then
BRANCH=$1
else
BRANCH=$(git branch | grep '*' | cut -d ' ' -f2)
fi
REMOTE=$(git config --get branch.$BRANCH.remote)
REMOTE_BRANCH=$(git config --get branch.$BRANCH.merge)
echo "$REMOTE/${REMOTE_BRANCH##*/}"
@ryanbriones
ryanbriones / gist:266619
Created December 31, 2009 04:53
find node with the maximum value of a specific attribute
//node()[@attribute and not(@attribute <= preceding-sibling::node()/@attribute) and not(@attribute <=following-sibling::node()/@attribute)]
# getting more power out of Enumerable
# this is to convert an RGB data structure, into RGBA
RGB_WIDTH = 3
raw_data = [1,1,1,2,2,2,3,3,3,4,4,4]
# returns an enumerable object with the raw data split up into chunks of 3
pixels = raw_data.enum_slice( RGB_WIDTH )