Skip to content

Instantly share code, notes, and snippets.

View domluna's full-sized avatar
🐺
howling time

Dominique Luna domluna

🐺
howling time
View GitHub Profile
@domluna
domluna / unreachable.js
Created November 13, 2013 03:32
Example of unreachable function in JS closure, good to keep in mind for when writing JS code Note browsers need functions in closures to be "explicitly unreachable" in order for garbage collection.
var someFunc = function() {};
function f() {
var some = new someFunc(); // this won't be garbage collected!!!
function unreachable() {};
return function() {};
}
window.f_ = f():
struct Foo<'self> {
name: ~str,
ref_bar: &'self Bar // Bar lives as long as Foo
// When Foo is freed, Bar is freed
// No memory leaks!
}
struct Bar {
name: ~str
}
@domluna
domluna / append.go
Last active December 20, 2015 21:09
You ever have two slices in Go you wanted to combine? Of course you did. Did you use a for loop? Of course you did. Now what if I told you that for loop was bogus!
a := []int{1,2,3}
b := []int{4,5,6}
// Bad way
for _, number := range b {
a = append(a, number)
}
// Super awesome way
a = append(a, b...)
@domluna
domluna / dict_iterate.py
Created April 30, 2013 16:23
Better way to iterate over dictionaries
for key, val in dictionary.iteritems():
print key, val
for key in dictionary.iterkeys():
print key
for val in dictionary.itervalues():
print val