Skip to content

Instantly share code, notes, and snippets.

View jgarber's full-sized avatar

Jason Garber jgarber

View GitHub Profile
@jgarber
jgarber / gist:1354025
Created November 10, 2011 03:28
IndyHall Community app
* Member directory with photos
* Messages
** Multiple categories
** Email subscription
** Unsubscribe from a category
** Mute a thread if you're not interested
** Proper threading in Gmail
** Proper preview snippet in Gmail
** Take a convo off-list
** Reply to original author
@jgarber
jgarber / gist:1367789
Created November 15, 2011 17:56
Fetching most popular items in the last seven days using charlotte-ruby/impressionist
Impression.where("created_at>=? and created_at<=?",7.days.ago,Time.now).select("impressionable_id").group("impressionable_id").order("count_impressionable_id DESC").limit(7).count
@jgarber
jgarber / gist:1474739
Created December 14, 2011 01:09
Example refactoring for Greg's Rspec talk
describe TournamentRegistration do
it "should parameterize itself with id" do
registration = Factory.create(:tournament_registration, :team_name => "Mighty Badgers")
registration.to_param.should == "#{registration.id}-mighty-badgers"
end
end
@jgarber
jgarber / which_string_coercion_is_faster.rb
Created January 24, 2012 16:10
What's the fastest way to convert from a subclass of String to a String?
#!/usr/bin/env ruby
require 'benchmark'
TIMES_TO_REPEAT = 10_000_000
class SpecialString < String; end
Benchmark.bmbm do|b|
b.report("''.to_s") do
str = ''

Give RedCloth a try!

A simple paragraph with
a line break, some emphasis and a link

  • an item
  • and another
  1. one
  2. two
class HtmlTag < Parslet::Parser
root(:tag)
rule(:tag) do
( open_tag | close_tag | self_closing_tag ).as(:html_tag)
end
rule(:self_closing_tag) { str("<") >> tag_name >> attributes? >> (spaces? >> str("/")) >> str(">") }
rule(:open_tag) { str("<") >> tag_name >> attributes? >> str(">") }
rule(:close_tag) { str("</") >> tag_name >> str(">") }
@jgarber
jgarber / gist:1993171
Created March 7, 2012 13:38
Remove default field sizes in Rails 3.2.2
class ActionView::Helpers::InstanceTag
DEFAULT_FIELD_OPTIONS.delete("size")
DEFAULT_TEXT_AREA_OPTIONS.delete("rows")
DEFAULT_TEXT_AREA_OPTIONS.delete("cols")
end
@jgarber
jgarber / gist:2349973
Created April 10, 2012 09:56
Spec for a tagging front-end Rails plugin or jQuery library

Need a Rails plugin that can also be used as just a jQuery library.

  • Written in CoffeeScript
  • Has Jasmine tests
  • Only requires jQuery — not jQuery UI
  • Based off of and styles itself after a single text form field
  • Can be downloaded with a minified JS version ready to go
  • Rails form helper for creating the field
  • SimpleForm detection and helper as well
  • Can specify separator characters like Tag-it
@jgarber
jgarber / wtf-commerce.php
Created May 4, 2012 23:02
ODEARGODSAVEMEFROMTHISINSANITY!!!!
<script>
function hightlightPaymentMethodLogo(payment_method_id) {
if(payment_method_id > 0) {
var payment_method_logo_id = 'payment_method_logo_' + payment_method_id;
var obj = document.getElementById(payment_method_logo_id);
obj.style['border-style'] = "solid";
obj.style['border-width'] = "2px";
obj.style['-moz-border-radius'] = "6px";
obj.style['-webkit-border-radius'] = "6px";
obj.style['border-color'] = "#00ff00";
$ rails c
1.9.2p320 :007 > ActiveRecord::Base.connection.send :postgresql_version
=> 90102
$ rake staging console
ActiveRecord::Base.connection.send :postgresql_version
=> 80311
$ rake production console
ActiveRecord::Base.connection.send :postgresql_version