View redis_queue.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Task queue using redis. | |
Redis client: | |
LPUSH work "say Hello world!" | |
LPUSH work "log This goes into syslog" | |
""" | |
import redis | |
from multiprocessing import Pool |
View gist:5463592
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Point { | |
x: int, | |
y: int | |
} | |
fn one() { | |
let mut a = ~Point{x: 10, y: 20}; | |
a.x = 42; | |
println(a.x.to_str()); | |
} |
View hello_world.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
println("Hello World!"); | |
} |
View ask_name.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Ask the user for their name */ | |
fn ask_name(prompt: ~str) -> ~str { | |
println(prompt); | |
return io::stdin().read_line(); | |
} | |
fn main() { | |
let name = ask_name(~"What is your name?"); | |
println(fmt!("Hello %s", name)); | |
} |
View loop.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
for 2.times { | |
println("Basic loop sugar") | |
} | |
2.times(||{ println("Basic loop closure"); true }); | |
for [1,2,3].each |var| { | |
println(fmt!("Sugary loop %d", *var)); | |
} |
View load_file.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn load(filename: ~str) -> ~[~str] { | |
// The simple way: | |
// let read_result = io::file_reader(~path::Path(filename)); | |
let read_result: Result<@Reader, ~str>; | |
read_result = io::file_reader(~path::Path(filename)); | |
if read_result.is_ok() { | |
let file = read_result.unwrap(); |
View load_file_2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn load(filename: ~str) -> ~[~str] { | |
// The simple way: | |
// let read_result = io::file_reader(~path::Path(filename)); | |
let read_result: Result<@Reader, ~str>; | |
read_result = io::file_reader(~path::Path(filename)); | |
match read_result { | |
Ok(file) => return file.read_lines(), |
View net_fetch.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern mod std; | |
use std::{net_tcp,net_ip}; | |
use std::uv; | |
fn fetch(code: ~str) -> ~[~str] { | |
let ipaddr = net_ip::v4::parse_addr("205.156.51.232"); | |
let iotask = uv::global_loop::get(); | |
let connect_result = net_tcp::connect(ipaddr, 80, &iotask); |
View use_sqlite.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern mod sqlite; | |
fn db() { | |
let database = | |
match sqlite::open("test.db") { | |
Ok(db) => db, | |
Err(e) => { | |
println(fmt!("Error opening test.db: %?", e)); | |
return; |
View memory_example.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let name: ~str, | |
other: ~str; | |
name = ~"Bob"; | |
other = name; | |
println(other); |
OlderNewer