Skip to content

Instantly share code, notes, and snippets.

# With callback methods, if they return false, it will halt the chain and your model won't be saved.
# Ninety-nine out of a hundred times, this is only an issue if you're 'caching' a boolean value based on
# an association status or other convoluted evaluation
class Entity < ActiveRecord::Base
named_scope :publicly_available, :conditions => {:publicly_available => true}
has_many :items
belongs_to :user
using System.Reflection;
using System.Collections;
public static void ShowProperties(Object myObject){
Hashtable PropertiesOfMyObject = new Hashtable();
Type t = myObject.GetType();
PropertyInfo[] pis = t.GetProperties();
for (int i=0; i<pis.Length; i++) {
PropertyInfo pi = (PropertyInfo)pis.GetValue(i);
Console.WriteLine(pi.Name);
>> Business.search(:conditions => { :state => "paid" }).length
=> 20
>> Business.find_all_by_state("paid").length
=> 321
@subtleGradient
subtleGradient / Paste to Gist_GitHub Anonymously.tmCommand
Created July 28, 2008 19:13 — forked from pieter/gistie.rb
gistie.rb Paste code to gist.github.com from the shell!
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>bundleUUID</key>
<string>2E6B9F06-DDB6-4707-A2BB-8751CF1722A0</string>
<key>command</key>
<string>cat|gist -a "$TM_FILENAME"
require "test/unit"
class Module
alias_method :old_private, :private
def private(*args)
old_private(*args)
end
end
// ==UserScript==
// @name techon - read article without register
// @namespace http://d.hatena.ne.jp/youpy/
// @include http://techon.nikkeibp.co.jp/article/*
// @require http://gist.github.com/raw/2040/577979fb1e473146cc7a9ca9942b18e2aa90166c
// ==/UserScript==
(function() {
$X('//div[@id="nocookie"]')[0].style.display = 'none';
})();
it 'should save both the object and parent if both are new' do
pending('This is a bug that should be fixed') do
area1 = Area.new(:name => 'area1')
area1.machine = Machine.new(:name => 'machine1')
area1.save
area1.machine_id.should == area1.machine.id
end
end
require 'date'
class DateTime
def to_f
days_since_unix_epoch = self - ::DateTime.civil(1970)
(days_since_unix_epoch * 86_400).to_f
end
end
foo = DateTime.now
class MonitoredTopic
include DataMapper::Resource
property :id, Serial
belongs_to :user
belongs_to :topic
end
class Topic
%w[rubygems ncurses xmpp4r].each {|dep| require dep }
Ncurses.keypad(@window = Ncurses.initscr, true)
Ncurses.cbreak
Ncurses.refresh
at_exit { Ncurses.endwin }
Jabber::logger = Logger.new('jabberlog.txt')
Jabber::debug = true