Skip to content

Instantly share code, notes, and snippets.

View codahale's full-sized avatar
🦆
Look at all these chickens

Coda Hale codahale

🦆
Look at all these chickens
View GitHub Profile
// createFile creates a file in the given root and returns it with a defer to close it
func createFile(root *os.Root, filename string) (*os.File, error) {
f, err := root.Create(filename)
if err != nil {
return nil, err
}
return f, nil
}
### Keybase proof
I hereby claim:
* I am codahale on github.
* I am codahale (https://keybase.io/codahale) on keybase.
* I have a public key whose fingerprint is 5D14 B50E 62D6 279D 6C41 52DC DC59 AFA3 840C 3C96
To claim this, I am signing this object:
pub fn estimate(&self, e: &E) -> u64 {
indexes(e, self.width)
.take(self.depth)
.enumerate()
.map(|(i, idx)| self.counters[i][idx])
.min()
.unwrap()
}
14:17:33 ~ $ rustc --version
rustc 1.0.0-nightly (44a287e6e 2015-01-08 17:03:40 -0800)
14:17:36 ~ $ cargo --version
cargo 0.0.1-pre-nightly (8c01b6b 2015-01-08 20:52:43 +0000)
14:17:47 ~ $ cd /tmp
14:17:49 /tmp $ cargo new --bin hello-world
14:18:00 /tmp $ cd hello-world/
/tmp/hello-world
14:18:04 /tmp/hello-world [git:master?] $ cargo run
An unknown error occurred
5.0 +
|
|
| +-----*-----+
|
4.0 +
|
|
| +-----*-----+
@codahale
codahale / blah.go
Created June 16, 2014 00:27
Only you can prevent race conditions.
package blah
import (
"sync/atomic"
)
var (
n uint64
)
fn main() {
let (port, chan): (Port<int>, Chan<int>) = stream();
let mut i = 0;
while i < 30 {
do spawn {
chan.send(1);
}
i += 1;
}
@codahale
codahale / SetBenchmark.java
Created April 3, 2013 18:49
An example of how to use Caliper: http://code.google.com/p/caliper/.
import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;
import java.util.HashSet;
import java.util.TreeSet;
public class SetBenchmark extends SimpleBenchmark {
// If you add a main function, you can run it from your IDE.
public static void main(String[] args) throws Exception {
new Runner().run(
[INFO] +- com.sun.jersey.jersey-test-framework:jersey-test-framework-inmemory:jar:1.12:compile
[INFO] | \- com.sun.jersey.jersey-test-framework:jersey-test-framework-core:jar:1.12:compile
[INFO] | +- javax.servlet:javax.servlet-api:jar:3.0.1:compile
[INFO] | \- com.sun.jersey:jersey-client:jar:1.12:compile
@codahale
codahale / pom.xml
Last active October 26, 2024 07:45
Take this and save it as pom.xml in your project directory.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- none yet -->