Skip to content

Instantly share code, notes, and snippets.

View mdarby's full-sized avatar
💭
pending validation

Matt Darby mdarby

💭
pending validation
View GitHub Profile
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
ASDF
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@mdarby
mdarby / gist:19195
Created October 23, 2008 20:41
Here is an Textmate snippet that allows you to easily convert HTML and ERB templates to Haml. It also re-converts certain characters back to their normal form after conversion (for some reason html2haml converts stuff like less-than signs and quotes to th
#!/bin/sh
html2haml -r "$TM_FILEPATH" | sed 's/&gt;/>/g' | sed 's/&lt;/</g' | sed 's/- end//g' | sed 's/&quot;/"/g' | sed 's/&amp;/\&/g'
>> require 'benchmark'
=> []
>> n = 1000
=> 1000
>> Benchmark.bm do |x|
> x.report{User.find(:first, :order => "rand()")}
>> x.report{User.random}
>> end
user system total real
0.000000 0.000000 0.000000 ( 0.007087)
def get_parent_resource(target_klass, path)
# Convert the requested path into hash form
hash = ActionController::Routing::Routes.recognize_path(path, :method => :get)
# Loop through path keys and see if any end in '_id'
# and our child class belongs_to the associated AR Class
pair = hash.detect do |k, v|
k.to_s.ends_with?("_id") && target_klass.columns_hash.has_key?(k.to_s)
end
<a href="/timesheet/day/1772-04-28">Sun (04/28)</a>
<a href="/timesheet/day/2008-11-17">Mon (11/17)</a>
<a href="/timesheet/day/2245-06-08">Tue (06/08)</a>
<a href="/timesheet/day/2481-12-27">Wed (12/27)</a>
<a href="/timesheet/day/2718-07-19">Thu (07/19)</a>
<a href="/timesheet/day/2955-02-06">Fri (02/06)</a>
<a href="/timesheet/day/3191-08-28">Sat (08/28)</a>
# Usage:
# >> User.random
# => #<User login: ...
class ActiveRecord::Base
def self.random
begin
find(rand(count))
rescue ActiveRecord::RecordNotFound
# application_helper.rb
# Generic form label styling
def box_label(text)
text = "#{text}:" unless text.end_with?(":")
"<span class=\"box_label\">#{text}</span>"
end
# A generic box to encapsulate some text
def box(title = nil, *args, &block)
# /some_object/show.html.erb
<% box('Name:') do %>
<%=h @some_object.name %>
<% end %>
<div class="box">
<span class="box_label">Name:</span>
J080119 - Technology Department
</div>