Skip to content

Instantly share code, notes, and snippets.

My measurements for the "kernel interrupt timing" programs:
|--------------------+-----------------+-------------+------------------------------|
| SIGALRM Interval | Program version | Measured Hz | Measured Interval Avg (usec) |
|--------------------+-----------------+-------------+------------------------------|
| (init setting) 250 | Rust | 4001 | 250 |
| (init setting) 250 | C | 4016 | 249 |
|--------------------+-----------------+-------------+------------------------------|
| 500 | Rust | 2001 | 500 |
| 500 | C | 2004 | 499 |
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");
}
@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));
@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 / 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)]
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 / 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();
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 / gist:952ce6837485b15be7ae
Last active August 29, 2015 14:07
Notes on publishing Java artifacts to maven central
@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"