Skip to content

Instantly share code, notes, and snippets.

@grahamking
grahamking / send.go
Last active Aug 29, 2015
ICMP raw send
View send.go
package main
import (
"log"
"net"
"syscall"
)
func main() {
var err error
@grahamking
grahamking / recv.go
Last active Aug 29, 2015
ICMP raw receive
View recv.go
package main
import (
"fmt"
"os"
"syscall"
)
func main() {
fd, _ := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, syscall.IPPROTO_ICMP)
View alloc.s
.text
.global _start
_start:
mov $12, %rax # brk syscall number
mov $0, %rdi # 0 is invalid, want to get current position
syscall
mov %rax, %rsi # rsi now points to start of heap mem we'll allocate
@grahamking
grahamking / redis_queue.py
Created Jan 26, 2012
Celery alternative?
View redis_queue.py
"""Task queue using redis.
Redis client:
LPUSH work "say Hello world!"
LPUSH work "log This goes into syslog"
"""
import redis
from multiprocessing import Pool
@grahamking
grahamking / gist:5463592
Last active Dec 16, 2015
rust question
View gist:5463592
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
fn main() {
println("Hello World!");
}
@grahamking
grahamking / ask_name.rs
Last active Dec 16, 2015
Rust: Ask your name
View ask_name.rs
/* 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));
}
@grahamking
grahamking / loop.rs
Last active Dec 16, 2015
Rust: Loop three ways
View loop.rs
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));
}
@grahamking
grahamking / load_file.rs
Created Apr 26, 2013
Rust: Load a file
View load_file.rs
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();
@grahamking
grahamking / load_file_2.rs
Created Apr 26, 2013
Rust: Load a file v2
View load_file_2.rs
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(),