Public Gists by jqr

Gravatar
Fri Nov 13 08:05:04 -0800 2009
1
2
3
class ActiveRecord::Base
  def self.soft_destroyable(column = :destroyed_at)
    define_method(:destroy_without_callbacks) do
Gravatar
Tue Nov 10 15:23:35 -0800 2009
1
2
3
    var grouped_products = [[]];
    var group_index = 0;
    _.each(products, function(product, index) {
Gravatar
Sat Oct 31 08:29:34 -0700 2009
1
2
3
// easy refresh-css keybinding to alt-w
// alt-r was taken in IE, so consider this a CSS Weefresh
 
Gravatar
Wed Oct 28 12:05:56 -0700 2009
1
2
3
Then /^open IRB$/ do
  require 'irb'
  original_argv = ARGV
Gravatar
Fri Oct 23 05:40:01 -0700 2009
1
2
3
require 'rubygems'
require 'bert'
require 'json'
Gravatar
Sun Sep 27 11:07:15 -0700 2009

      
Gravatar
Fri Jul 03 07:49:43 -0700 2009
1
2
3
#!/usr/bin/env ruby
 
home = File.expand_path('~')
Gravatar
Tue Jun 30 09:34:41 -0700 2009
1
2
3
class User < ActiveRecord::Base
  def score=(value)
    super(value * 1_000_000) # pinball scores do it, why not Users?
Gravatar
Mon Jun 22 08:44:15 -0700 2009
1
2
3
>> Person.scoped(:conditions => { :company_id => 1 }).scoped(:conditions => { :company_id => 3 }).size
  SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
  Person Columns (2.6ms) SHOW FIELDS FROM `people`
Gravatar
Fri Jun 19 16:59:52 -0700 2009
1
2
3
require 'benchmark'
 
count = 10_000_000
Gravatar
Wed Jun 10 14:46:03 -0700 2009
1
2
3
# In ruby 1.9
 
{:one => 1, :two => 2}.select {|k,v| k == :one} #=> {:one=>1}
Gravatar
Wed Jun 10 14:29:31 -0700 2009
1
2
require 'activesupport'
{:one => 1, :two => 2}.slice(:one) #=> {:one=>1}
Gravatar
Wed Jun 10 11:32:09 -0700 2009
1
2
3
class Account < ActiveRecord::Base
  has_many :users
  belongs_to :first_user, :class_name => 'User'
Gravatar
Wed May 27 12:25:27 -0700 2009
1
2
3
# Watches a value change over time showing you current value and rate of
# change.
#
Gravatar
Tue May 12 11:08:26 -0700 2009
1
2
3
module Breadcrumb
  def breadcrumbs
    if parent
Gravatar
Wed May 06 16:50:22 -0700 2009
1
2
3
require 'rubygems'
require 'httparty'
 
Gravatar
Fri Apr 24 21:21:03 -0700 2009
1
2
3
class A
  def initialize
    puts "A initialized"
Gravatar
Fri Apr 24 19:24:38 -0700 2009
1
2
3
<script type="text/python">
def pyFunc():
  window.alert("hi, i'm python")
gist: 101101 Automatically Generate the ...
Gravatar
Fri Apr 24 06:24:16 -0700 2009
1
2
3
namespace :heroku do
  desc "Generate the Heroku gems manifest from gem dependencies"
  task :gems do
Gravatar
Thu Apr 23 13:43:18 -0700 2009
1
2
3
irb(main):001:0> thing
NameError: undefined local variable or method `thing' for main:Object
from (irb):1