Discover gists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> Business.search(:conditions => { :state => "paid" }).length | |
=> 20 | |
>> Business.find_all_by_state("paid").length | |
=> 321 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "test/unit" | |
class Module | |
alias_method :old_private, :private | |
def private(*args) | |
old_private(*args) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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'; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MonitoredTopic | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :user | |
belongs_to :topic | |
end | |
class Topic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 |