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 |
@quux00
quux00 / hof-reordered.rs
Last active January 4, 2016 21:19
Hof in Rust
fn double(a: int) -> int { a * 2 }
fn ntimes(f: proc(int) -> int, times: int) -> proc(int) -> int {
proc(x: int) {
match times {
0 => { x },
_ => { f(ntimes(f, times - 1)(x)) } // swap the order relative to the original example
}
}
}
use std::io::File;
use std::str;
fn main() {
let file_name_abs = ~"foo";
let mut response =~ "";
match File::open(&Path::new(file_name_abs)) {
Some(html_file) => {
let mut html_file_mut = html_file;
@quux00
quux00 / telephonic-whispers-with-maxprocs.go
Created January 26, 2014 17:15
Telephonic whispers with GOMAXPROCS set in Go.
package main
import (
"fmt"
"runtime"
)
func whisper(left, right chan int) {
left <- 1 + <- right
}
@quux00
quux00 / atomicbooltest.rs
Created January 24, 2014 03:15
rust enums
use std::sync::atomics::AtomicBool;
use std::sync::atomics::Ordering;
// error unresolved import: there is no `Relaxed` in `std::sync::atomics::Ordering`
// use std::sync::atomics::Ordering::Relaxed;
fn main() {
let mut ab = AtomicBool::new(false);
let val1 = ab.load(Ordering::Relaxed); // error: unresolved import:
// there is no `Relaxed` in `std::sync::atomics::Ordering`
@quux00
quux00 / proc.rs
Last active January 3, 2016 13:09
// Trying to learn closures/procs in Rust // Want to capture a variable whose private state I can mutate // Currently failing
//
// Trying to learn closures/procs in Rust
// Want to capture a variable whose private state I can mutate
//
fn main() {
fn call_proc(b: proc(u64) -> u64) {
let x = b(10u64);
println!("{:?}", x);
}
@quux00
quux00 / chinese-whispers.rs
Created January 16, 2014 04:58
Chinese Whispers in Rust Based on example by Rob Pike in http://www.youtube.com/watch?v=f6kdp27TYZ
static N:int = 100000;
//
// Chinese Whispers in Rust
// Based on example by Rob Pike
// in http://www.youtube.com/watch?v=f6kdp27TYZs
//
fn main() {
let (leftmost_port, leftmost_chan) = Chan::new();
let mut leftc: Chan<int> = leftmost_chan;
@quux00
quux00 / chinese-whispers.go
Created January 16, 2014 04:56
Chinese Whispers example by Rob Pike http://www.youtube.com/watch?v=f6kdp27TYZs
package main
import "fmt"
//
// Chinese Whispers example by Rob Pike
// See http://www.youtube.com/watch?v=f6kdp27TYZs
//
func whisper(left, right chan int) {
left <- 1 + <- right
@quux00
quux00 / tckill.rs
Last active January 3, 2016 01:49
Mutable pointers in Rust
use std::run;
use std::str;
fn main() {
let options = run::ProcessOptions::new();
let process = run::Process::new("fuser", &[~"-m", ~"/media/truecrypt3"], options);
match process {
Some(mut p) => {
let outdata = p.finish_with_output();
let outtxt = str::from_utf8(outdata.output);
@quux00
quux00 / monster.rs
Last active January 2, 2016 23:49
Learning Rust traits ... poorly
fn main() {
let mut mon1: ~Sleestak = ~Monster::new();
let mut mon2: ~Reaver = ~Monster::new();
let mut monsters = [mon1 as ~Monster, mon2 as ~Monster];
println!("{:?}", monsters);
println("------------------------------");
// attempt 1: fail
for m in monsters.iter() {