Skip to content

Instantly share code, notes, and snippets.

View gregbell's full-sized avatar

Greg Bell gregbell

View GitHub Profile
# Find all the proper employees
employees = Employee.find(:all, :conditions => 'conditions to get the right employees')
# Add the employee that we want (by email address)
# to the top of the list
# Then call uniq on it to remove the duplicate
employees.unshift(employees.find{ |employee| employee.email_address == "email we want at the top" }).uniq
class Player < ActiveRecord::Base
has_many :game_participations
has_many :games, :through => :game_participations
end
class Game < ActiveRecord::Base
has_many :game_participations
has_many :players, :through => :game_participations
end
// Assuming jQuery is on the page, this will append the search tweets
// to an element with the id of 'twitter'
$.getJSON("http://search.twitter.com/search.json?q=adobe+sucks&callback=?", function(data){
$.each(data.results, function(i, tweet){
var tweetContent = '<div class="tweet">';
tweetContent += '<p class="tweet-body">' + tweet.text + '</p>';
tweetContent += '<p class="tweet-meta"><a href="http://twitter.com/' + tweet.from_user + '">' + tweet.from_user + '</a> at ' + tweet.created_at + '</p></div>';
$('#twitter').append(tweetContent);
});
})
class FormBuilder
attr_reader :calls
def initialize(&block)
@calls = []
@current = @calls
block.call(self)
end
module HasMoney
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
#
# has_money :default_price

VersaPay REST API v 0.1

Messages

Response Formats

Add one of the following formats to the end of the url

.json .xml

@gregbell
gregbell / index.html.erb
Created May 24, 2011 19:24
Arbre components in ERB
<% self.class.send :include, Arbre::HTML %>
<%= panel("Hello"){ h2 @test_assign } %>
<%= panel("Hello World"){ } %>
@gregbell
gregbell / products.rb
Created September 20, 2011 18:53
Active Admin - Show screen with default content
ActiveAdmin.register Product do
# Will show the default main content...
show do
# Do stuff before
default_main_content
# Do stuff after
end
# ... Or if you want to customize further
@gregbell
gregbell / batch_review.rb
Created November 23, 2011 17:20 — forked from pcreux/batch_review.rb
Batch gitmine review a bunch of tickets.
#!/user/env ruby
#
# Batch gitmine review a bunch of tickets.
#
# Usage: ruby batch_review.rb 7585 7603 7623 7640 7663 7665
#
ARGV.each do |issue_id|
system("gitmine checkout #{issue_id} && git pull && git diff master...HEAD")
puts "Merge into master?"
@gregbell
gregbell / active-admin-run-tests-on-fork.sh
Created February 18, 2012 17:16
Active Admin: run-tests-on-fork
#!/bin/bash
set -e
# Run the script:
# ./active-admin-run-tests-on-fork GITHUBUSERNAME BRANCHNAME
# Change this to wherever you want tests to run
tests_dir=~/code/personal/active_admin_forks