Skip to content

Instantly share code, notes, and snippets.

@quux00
quux00 / JavaStringSplits.java
Created October 19, 2014 15:52
Microbenchmarks of four ways to tokenize a Java string
package mechsympathy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Fork;
@quux00
quux00 / spell_checker_distance_finder.go
Created October 16, 2014 01:18
A spelling checker / Levenshtein distance finder in Go
package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
"strings"
"time"
@quux00
quux00 / gist:952ce6837485b15be7ae
Last active August 29, 2015 14:07
Notes on publishing Java artifacts to maven central
fn main() {
// works
let a = [1, 2, 3, 4, 5];
let b: ~[int] = a.iter().map(|&x| x * 2).collect();
println!("{:?}", b);
// fails
let c = [1, 2, 3, 4, 5];
let d: ~[int] = a.iter().filter(|&x| *x > 2).collect();
@quux00
quux00 / select.rs
Last active August 29, 2015 13:57
select! issue in Rust
use std::io::Timer;
struct A {
c: Sender<~str>,
p: Receiver<~str>
}
fn main() {
compiles();
use std::str::StrVector;
struct A<'a> {
field: &'a StrVector
}
fn main() {
let vs = ~[~"one", ~"two", ~"three"];
let cc = vs.concat();
println!("{:?}", cc); // works
@quux00
quux00 / memcached.rs
Last active August 29, 2015 13:56
How to import C enum into Rust?
// Rust code
use std::libc;
use std::ptr;
struct memcached_st;
struct memcached_server_st;
struct memcached_server_list_st;
type in_port_t = i32;
#[repr(C)]
@quux00
quux00 / refer.rs
Last active August 29, 2015 13:56
Reference functions in an impl
struct MyThing {
val: int
}
impl MyThing {
fn remove_first(s: &str) -> ~str {
s.slice_from(1).to_owned()
}
fn remove_last(&self, s: &str) -> ~str {
@quux00
quux00 / snippet.rs
Last active August 29, 2015 13:56
Snippet of web server code in Rust
use std::io::EndOfFile;
use std::io::io_error;
// ...
fn respond_with_static_file(stream: Option<std::io::net::tcp::TcpStream>, path: &Path) {
let mut stream = stream;
let sz = 16384;
let result = io::result(|| File::open(path));
use std::io::process;
use std::io::process::{Process, ProcessConfig};
use std::comm::{Port, Chan};
fn main() {
let (port, chan) = Chan::new();
spawn(proc(){taskEntry(port)});
chan.send(~"ls");
}