Skip to content

Instantly share code, notes, and snippets.

View pelle's full-sized avatar

Pelle Braendgaard pelle

View GitHub Profile
int gold_coin;
int* dollar_bill;
gold_coin = 100;
dollar_bill = &gold_coin;
if (dollar_bill == gold_coin )
printf("Dollar bill has same intrinsic value as gold coin\n");
else
printf("Dollar bill does not have same intrinsic value as gold coin\n");
FUNGIBLE = [:coin, :coin, :coin, :coin]
INFUNGIBLE = [:coin, :cow, :wine, :kebab]
# Is each unit in the list of assets interchangeable?
def fungible?(assets)
if assets.all?{ |unit| assets.all? {|other_unit| unit==other_unit }}
puts "#{assets.inspect} is fungible"
else
puts "#{assets.inspect} is not fungible"
end
end
#!/usr/bin/env python
import hashlib, urllib, time
def digest( content ):
return hashlib.sha1( content ).hexdigest()
def timecert( content):
url = "http://timecert.org/%s.time"%digest(content)
timestamp = urllib.urlopen( url ).read()
return time.strptime(timestamp,"%a %b %d %H:%M:%S %Z %Y")
@pelle
pelle / sha1.rb
Created June 1, 2009 01:53
How to call timecert
require 'digest/sha1'
require 'open-uri'
# Calculate the digest of content
def digest(content)
Digest::SHA1.hexdigest(content)
end
# Gets the timecert timestamp for a given piece of content
def timecert(content)
@pelle
pelle / article.rb
Created May 31, 2009 23:58
Embedding TimeCert in your rails app
require 'digest/sha1'
class Article < ActiveRecord::Base
before_save :update_digest
def full_text
"#{title}\n\n#{body}"
end
protected
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.-
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:159:in `decrement_open_transactions'
/Library/Ruby/Gems/1.8/gems/aslakhellesoy-cucumber-0.1.99.23/bin/../lib/cucumber/rails/world.rb:61:in `__instance_exec0'
/Library/Ruby/Gems/1.8/gems/rspec-1.2.0/lib/spec/matchers/extensions/instance_exec.rb:19:in `send'