I hereby claim:
- I am kenpratt on github.
- I am kenpratt (https://keybase.io/kenpratt) on keybase.
- I have a public key whose fingerprint is DEB1 C9E5 A9CB 6FF9 0D43 6DA8 F9D6 133C F21F 6CD3
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
trait Polygon { | |
fn area(&self) -> f32; | |
} | |
struct Circle<'a> { | |
radius: &'a f32, | |
} | |
impl<'a> Polygon for Circle<'a> { | |
fn area(&self) -> f32 { |
trait Polygon { | |
fn area(&self) -> f32; | |
} | |
struct Circle { | |
radius: f32, | |
} | |
impl Polygon for Circle { | |
fn area(&self) -> f32 { |
enum Test { | |
One(String), | |
Two(String), | |
Three(uint), | |
Four(bool) | |
} | |
fn check(s: Test) { | |
match s { | |
Some("x") => println!("got an x"), |
// works, but ugly | |
fn check1(s: Option<String>) { | |
match s { | |
Some(t) => { | |
match t.as_slice() { | |
"test" => println!("yep"), | |
_ => println!("nope") | |
} | |
}, | |
None => println!("nope") |
#[deriving(Show)] | |
struct SampleError<'a> { | |
message: &'a str | |
} | |
fn generate_err() -> Result<(), SampleError> { | |
let m = format!("sample dynamic error: {}", 42); | |
Err(SampleError { message: m.as_slice() }) | |
} |
#[deriving(Show)] | |
enum Token<'a> { | |
Integer(int), | |
String(&'a str) | |
} | |
fn generate_int() -> Token { | |
Integer(23) | |
} |
fn generate() -> &str { | |
let s = format!("meaning of life: {}", 42); | |
s.as_slice() | |
} | |
fn main() { | |
println!("{}", generate()); | |
} | |
/* |
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
body { | |
font-family: Tahoma, Geneva, sans-serif; | |
} | |
div { | |
display: inline; |
var WebSocketServer = require('ws').Server | |
, wss = new WebSocketServer({port: 8088}) | |
, _ = require("underscore"); | |
var connections = []; | |
wss.on('connection', function(ws) { | |
connections.push(ws); | |
ws.on('message', function(message) { | |
console.log('received: %s', message); |