Skip to content

Instantly share code, notes, and snippets.

View travisdahlke's full-sized avatar

Travis Dahlke travisdahlke

View GitHub Profile
<!DOCTYPE html>
<html >
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="csrf-param" content="authenticity_token" />
<meta name="csrf-token" content="MNt1KcKC+OArhq5ZheeoEGzsYX/OzEPvLFI9XrIL2N03Fuimu2oISR9+I23+2eTxljGnh1/OnyZ70LBZMR7MZA==" />
<meta name="twitter:card" content="summary" />
travisdahlke /
Created November 7, 2014 18:57
Ledger to Beancount
import ledger
import sys
import re
def account_name(post):
account = post.account.fullname().replace(" ","").replace("(","").replace(")","").replace("'","")
return re.sub(r'\:(\d)',r':X\1', account)

Keybase proof

I hereby claim:

  • I am travisdahlke on github.
  • I am travisd ( on keybase.
  • I have a public key whose fingerprint is 1D08 EC6D 3564 9388 EB17 3193 AB2B F207 D73E E5F8

To claim this, I am signing this object:

travisdahlke / gist:7107244
Last active December 26, 2015 06:19
Ruby variable scoping can be tricky sometimes. Ruby will initialize the local variable 'foo' even though that line is never executed. Since it's now in the local scope, the method 'foo' doesn't get run during the second if.
class Thing
def foo
def bar
puts foo
if foo.nil?
foo = "bar"
# This option has the most clarity, but I generally hate local variables in a
# method, preferring to use tap.
def calculated_foo
available_foos = []
available_foos << bar
available_foos << baz.qux if baz
# It's a little less clear, unless you know what tap is, and `end.max` is
travisdahlke / mongo_add_test.js
Created March 19, 2013 20:11
Mongo 2.4 $add nulls test
use agg_test;
test_add = function() {
var t = db.things;
t.insert({a: 2, b: 3});
var total1 = t.aggregate({$project:{total:{$add:["$a","$b"]}}}).result[0].total;
print("a + b = " + total1);
var total2 = t.aggregate({$project:{total:{$add:["$a","$b","$c"]}}}).result[0].total;
print("a + b + c = " + total2);