Skip to content

Instantly share code, notes, and snippets.

View travisdahlke's full-sized avatar

Travis Dahlke travisdahlke

View GitHub Profile
@travisdahlke
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.drop();
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);
# 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
available_foos.max
end
# It's a little less clear, unless you know what tap is, and `end.max` is
@travisdahlke
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
"foo"
end
def bar
puts foo
if foo.nil?
foo = "bar"
end

Keybase proof

I hereby claim:

  • I am travisdahlke on github.
  • I am travisd (https://keybase.io/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
travisdahlke / ledger2beancount.py
Created November 7, 2014 18:57
Ledger to Beancount
#!/usr/bin/python
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)
<!DOCTYPE html>
<html >
<head>
<title>deco</title>
<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==" />
<title>Deco</title>
<meta name="twitter:card" content="summary" />
0493501e5e56d04d536e2756649222383e40c082d59547f51516bf5a425f705d1335b34e15b7e824a7ff7089c86a5c46b00bcbad3ed9c4c18d19b598d45221ee45