This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for key, val in dictionary.iteritems(): | |
print key, val | |
for key in dictionary.iterkeys(): | |
print key | |
for val in dictionary.itervalues(): | |
print val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var someFunc = function() {}; | |
function f() { | |
var some = new someFunc(); // this won't be garbage collected!!! | |
function unreachable() {}; | |
return function() {}; | |
} | |
window.f_ = f(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blahhing away |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"net" | |
"os/user" | |
"time" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Resize Linux partition without any disks/cds/usb things! | |
Works on Ubuntu 14.04, probably fine on others | |
1. | |
sudo losetup /dev/loop0 | |
2. /path/to/file is found with 1., xxx is the number of MiBs to allocate, note: 1MiB ~ 1MB | |
sudo dd if=/dev/zero bs=1MiB of=/path/to/file conv=notrunc oflag=append count=xxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pretend this is an actual big struct in which it would be | |
// expensive to copy by value. | |
struct BigStruct { | |
one: int, | |
two: int, | |
// etc | |
one_hundred: int, | |
} | |
// An antipattern would be for the return type to be |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(macro_rules)] | |
macro_rules! loop_x { | |
($e: expr) => { | |
// $e will not interact with this 'x | |
// refers to the 'x in the outside loop | |
'x: loop { | |
println!("Hello!"); | |
$e | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Copyright 2012 The Go Authors. All rights reserved. | |
# Use of this source code is governed by a BSD-style | |
# license that can be found in the LICENSE file. | |
# git gofmt pre-commit hook | |
# | |
# To use, store as .git/hooks/pre-commit inside your repository and make sure | |
# it has execute permissions. | |
# |
OlderNewer