Skip to content

Instantly share code, notes, and snippets.

View jocubeit's full-sized avatar
🎯
Focusing

Dom Jocubeit jocubeit

🎯
Focusing
View GitHub Profile
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@attilagyorffy
attilagyorffy / .powenv
Created March 2, 2012 12:20
Easily enable ruby debugger under Pow
export ENABLE_REMOTE_DEBUGGER_UNDER_POW=true
@attilagyorffy
attilagyorffy / rmate
Created January 23, 2012 13:48 — forked from leon/rmate
Setup TextMate's ssh rmate function
#!/usr/bin/env ruby
# encoding: UTF-8
$VERBOSE = true # -w
$KCODE = "U" if RUBY_VERSION < "1.9" # -KU
require 'optparse'
require 'socket'
require 'fileutils'
@ryanlecompte
ryanlecompte / gist:1420133
Created December 1, 2011 21:47
Alternative to modifying Proc directly
# alternative to what is explained in the article Ruby Blocks as Dynamic Callbacks:
# http://www.mattsears.com/articles/2011/11/27/ruby-blocks-as-dynamic-callbacks
class Twitter
def tweet(msg, &block)
proxy = DSL[block]
publish(msg)
proxy.respond_with(:success)
rescue => e
proxy.respond_with(:failure, e.message)
@boriscy
boriscy / install-ruby-debug-ubuntu-ruby-1.9.3
Created November 1, 2011 18:57
ruby-debug in ruby-1.9.3 and ubuntu
#To install ruby-debug on Ubuntu ruby-1.9.3 you need to download from http://rubyforge.org/frs/?group_id=8883
linecache19-0.5.13.gem
ruby_core_source-0.1.5.gem
ruby-debug19-0.11.6.gem
ruby-debug-base19-0.11.26.gem
#Then in your console
export RVM_SRC=/your/path/to/ruby-1.9.3
@jasoncodes
jasoncodes / create_item_children_count.rb
Created October 23, 2011 19:04
Create ActiveRecord models for database views
class CreateItemChildrenCountView < ActiveRecord::Migration
def self.up
execute <<-SQL
CREATE VIEW item_children_count AS
SELECT parent_id AS item_id, COUNT(*) as children_count
FROM items GROUP BY parent_id;
SQL
end
def self.down
@agnellvj
agnellvj / friendly_urls.markdown
Created September 11, 2011 15:52 — forked from jcasimir/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@Marchino
Marchino / rsend.rb
Created June 20, 2011 08:20
Recursive send method for Ruby Objects
# Lets you call object.rsend('method1.method2.method3') instead of object.send('method1').send('method2).send('method3)
class Object
def rsend(method, *params)
method.to_s.split('.').inject(self) { |obj, mth| obj.send(mth.to_sym, *params) }
end
end
@juggy
juggy / call_template.rb
Created May 17, 2011 19:25
Render a complete page in rails 3 without controller
# create the template
template = PageOfflineTemplate.new
template.quote = quote
template.pages = quote.build_pages
# Here I render a template with layout to a string then a PDF
pdf = PDFKit.new template.render_to_string(:template=>"quotes/review.html.haml")
@dbi
dbi / edit.html.mustache
Created May 4, 2011 09:31
Rails form helper for mustache spike/proof of concept
<!-- A scaffolded edit view converted to mustache -->
<h1>Editing post</h1>
{{#form}}
{{#errors?}}
<div id="error_explanation">
<h2>{{error_header}}</h2>
</div>
<ul>