Skip to content

Instantly share code, notes, and snippets.

View bkeepers's full-sized avatar

Brandon Keepers bkeepers

View GitHub Profile
class Position < ActiveRecord::Base
attr_protected :account_id, :created_at, :updated_at
belongs_to :account
#### Option 1 ####
attr_restricted :job_id
# assigns attribute if this method returns true
def allow_job_id_assignment?(id)
(function($) {
$.fn.delayedObserver = function(delay, callback) {
return this.keyup(function() {
var element = this, $element = $(this);
if(!$element.data('delayedObserver')) {
$element.data('delayedObserver', setTimeout(function() {
callback.apply(element);
$element.removeData('delayedObserver');
}, delay * 1000));
// easy refresh-css keybinding to alt-w
// alt-r was taken in IE, so consider this a CSS Weefresh
// original code from http://paulirish.com/2008/how-to-iterate-quickly-when-debugging-css/
$(document).keyup(function(e){
if (e.which == 87 && e.altKey) {
$('link').each(function() {
if((/stylesheet/i).test(this.rel) && this.href) {
var href = this.href.replace(/(&|\?)forceReload=\d+/,'');
this.href = href + ((/\?/).test(href) ? '&' : '?' ) + 'forceReload=' + new Date;
class Address < DataMapper::Type
include DataMapper::Resource
property :address, String
property :city, String
property :state, String
property :zip, Integer
end
class User
include DataMapper::Resource
@bkeepers
bkeepers / gist:263218
Created December 24, 2009 15:14
script to post hours from harvest in campfire
require 'rubygems'
require 'harvest'
require 'tinder'
@harvest = Harvest(
:email => "email",
:password => "password",
:sub_domain => "subdomain"
)
# Just drop this little diddy in your app to get some (not perfect) information on query times and such
# This will eventually become an official plugin but for those who can't wait, enjoy.
if defined?(NewRelic)
module MMNewRelicTracing
def self.included(model)
model.metaclass.class_eval do
add_method_tracer :find, 'Database/#{self.name}/find'
add_method_tracer :find!, 'Database/#{self.name}/find!'
add_method_tracer :paginate, 'Database/#{self.name}/paginate'
add_method_tracer :first, 'Database/#{self.name}/first'
@bkeepers
bkeepers / application.js
Created March 3, 2010 18:35
Get timezone offset from the browser and use it for timezones in Rails
jQuery(function() {
$.cookie('tz', (new Date()).getTimezoneOffset());
});
// jQuery.fn.or
//
// $('.dont-exist').or('.does-exist') //=> [.does-exist];
// $('.does-exist').or('.dont-exist') //=> [.does-exist];
$.fn.extend({
or: function(selector, context) {
if ($(this).length > 0) {
return $(this);
} else {
after 'deploy:update_code', 'solr:symlink'
after 'deploy:restart', 'solr:restart'
namespace :solr do
task :symlink do
run "ln -nfs #{shared_path}/solr #{release_path}/solr"
end
task :reindex, :roles => :app do
run "cd #{current_path} && rake sunspot:solr:reindex RAILS_ENV=#{rails_env}"
end
task :start, :roles => :app do
class Hash
def rmerge!(other_hash)
merge!(other_hash) do |key, oldval, newval|
oldval.class == self.class ? oldval.rmerge!(newval) : newval
end
end
def rmerge(other_hash)
r = {}
merge(other_hash) do |key, oldval, newval|