Skip to content

Instantly share code, notes, and snippets.

View pelle's full-sized avatar

Pelle Braendgaard pelle

View GitHub Profile

Keybase proof

I hereby claim:

  • I am pelle on github.
  • I am pelle (https://keybase.io/pelle) on keybase.
  • I have a public key whose fingerprint is 3810 F094 D2F8 9DDF 6468 2B72 CB8D 0835 0187 B1A9

To claim this, I am signing this object:

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'
@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
@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)
#!/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")
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
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");
contract EscrowContract {
address buyer;
address seller;
address agent;
// Each party has an entry here with the timestamp of their acceptance
uint[3] acceptances;
bool active;
@pelle
pelle / Escrow.sol
Created January 10, 2016 21:14
Simple Escrow with Agent
contract Escrow {
address buyer;
address seller;
address agent;
function Escrow(address _agent, address _seller) {
// In this simple example, the person sending money is the buyer and sets up the initial contract
buyer = msg.sender;
agent = _agent;
seller = _seller;
@pelle
pelle / accounts.clj
Created May 8, 2012 14:37
Using database functions in Datomic transactions and annotating transaction history
(use '[datomic.api :only [q db] :as d])
(def uri "datomic:mem://accounts")
;; create database
(d/create-database uri)
;; connect to database
(def conn (d/connect uri))