Skip to content

Instantly share code, notes, and snippets.

View technicalpickles's full-sized avatar

Josh Nichols technicalpickles

View GitHub Profile
@technicalpickles
technicalpickles / gist:3980449
Created October 30, 2012 14:24
Inspecting defined Rails routes, by controller
1.9.3p194 :032 > user_routes = Authmachine::Application.routes.set.select {|r| r.defaults[:controller] == 'users' }
=> [#<Journey::Route:0x007fecfd1853c0 @name="user", @app=#<ActionDispatch::Routing::RouteSet::Dispatcher:0x007fecfd186bd0 @defaults={:action=>"create", :controller=>"users"}, @glob_param=nil, @controllers={}>, @path=#<Journey::Path::Pattern:0x007fecfd1866d0 @anchored=true, @spec=/user(.:format), @requirements={}, @separators="/.?", @names=["format"], @optional_names=nil, @required_names=nil, @re=nil, @offsets=nil>, @verb=/^POST$/, @ip=//, @constraints={:request_method=>/^POST$/}, @defaults={:action=>"create", :controller=>"users"}, @required_defaults=nil, @required_parts=nil, @parts=[:format], @decorated_ast=nil, @precedence=2>, #<Journey::Route:0x007fecfd046bf8 @name="new_user", @app=#<ActionDispatch::Routing::RouteSet::Dispatcher:0x007fecfd03ef20 @defaults={:action=>"new", :controller=>"users"}, @glob_param=nil, @controllers={}>, @path=#<Journey::Path::Pattern:0x007fecfd03ebd8 @anchored=true,
@technicalpickles
technicalpickles / gist:3977685
Created October 30, 2012 01:01
Inspecting a controller's action methods
1.9.3p194 :016 > UsersController.action_methods
=> #<Set: {"_callback_before_128", "_callback_before_130", "show", "me", "new", "create", "edit", "update", "destroy"}>
1.9.3p194 :017 > UsersController.action_methods.reject {|m| m =~ /^_callback_/ }
=> ["show", "me", "new", "create", "edit", "update", "destroy"]
@technicalpickles
technicalpickles / gist:3623243
Created September 4, 2012 16:38
Trying to store regular expression results (if a thing is a match) in ActiveRecord can be tricky
# Consider this initial model
class IpAddress < ActiveRecord::Base
attr_accessible :description
end
# At some point, we want to add a boolean field, :primary, and populate that based on if the description matches /primary/i
# Here's the obvious thing to do:
IpAddress.find_each do |ip_address|
primary = ip_address =~ /primary/i
ip_address.update_attributes :primary => primary
@technicalpickles
technicalpickles / nyoooo.coffee
Created May 22, 2012 19:00
hubot script for pasting darth vader exclaiming noooooooooooo
# Nyoooooooooooooooooooooooooooooooooooooo
#
# nyoooo - Display darth vader's exclamation
# nooooo - Display darth vader's exclamation
module.exports = (robot) ->
robot.hear /ny?oo+\b/i, (msg) ->
msg.send "http://imgur.com/8MslB.jpg"
@technicalpickles
technicalpickles / puppet-type-reference.coffee
Created May 11, 2012 14:06
Hubot puppet type reference
# Quick access to Puppet Type Reference. No longer be thrawted by googling!
#
# puppet me <type> - get <type> reference URL
module.exports = (robot) ->
robot.respond /puppet (?:me ?)(.*)/i, (msg) ->
msg.send "http://docs.puppetlabs.com/references/latest/type.html##{msg.match[1]}"
@technicalpickles
technicalpickles / gist:2029140
Created March 13, 2012 14:32
Rails template
gem 'haml', '>= 3.0.0'
gem 'haml-rails'
gem 'jquery-rails'
gem 'rspec-rails', '>= 2.0.1', :group => [:development, :test]
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
initializer 'generators.rb', <<-RUBY
Rails.application.config do |config|
@technicalpickles
technicalpickles / gist:2026264
Created March 13, 2012 02:44
Fun with memory & profiling
%w(debug? info? warn? error? fatal?).map(&:to_sym).each do |level|
define_method level do
non_nil_loggers = @loggers.find_all{|l| l.level}
matching_loggers = non_nil_loggers.map{|l| l.send(level)}
matching_loggers.any?
end
end
var gif = document.location.toString().split('#')[0] + $('#gif img').attr('src');
var gifInput = '<input type="text" style="width: 100%" value="' + gif + '"/>';
$('body').prepend(gifInput);
@technicalpickles
technicalpickles / gist:1133074
Created August 8, 2011 23:51
[Draft] Fresh from the stills: moonshine_couchdb

Thanks to our friends at PeepCode, I'm happy to announce moonshine_couchdb, the moonshine way of managing couchdb.

Combine it with PeepCode's excellent CouchDB with Rails screencast, you will be relaxing with couch in no time.

Usage

moonshine_couchdb is pretty straightforward as far as things go. Install it as a Rails plugin: