Skip to content

Instantly share code, notes, and snippets.

@achambers
achambers / indextank_create_index.rb
Created August 26, 2011 17:16
Indextank Create Index
require 'indextank'
client = IndexTank::Client.new("http://my-indextank-api-url.api.indextank.com")
index = client.indexes("my_index_name")
index.add()
print "Waiting for index to be ready"
while not index.running?
print "."
@achambers
achambers / indextank_gem_install.rb
Created August 26, 2011 17:07
Indextank Gem Install
gem install 'indextank'
@achambers
achambers / include_vs_extend.rb
Created August 26, 2011 16:24
Include vs Extend
module Tweet
def save
puts 'Tweet saved'
end
end
class Foo
include Tweet # Add methods from Tweet as Instances Methods
end
@achambers
achambers / gist:1109964
Created July 27, 2011 17:48
insufficient_funds_ruby
def withdraw account_number, withdrawal_amount do
account = Account.find account_number
unless account.sufficient_funds? withdrawal_amount do
raise "Insufficient funds"
end
#...more code...
end
@achambers
achambers / gist:1109960
Created July 27, 2011 17:46
insufficient_funds_java
public Account withdraw(long accountNumber, BigDecimal withdrawalAmount) {
Account account = accountDao.get(accountNumber);
if(!account.hasSufficientFunds(withdrawalAmount)) {
throw new InsufficientFundsException();
}
//some code here
return account;