Skip to content

Instantly share code, notes, and snippets.

@pshc
pshc / keybase.md
Created September 11, 2017 23:44
Keybase proof

Keybase proof

I hereby claim:

  • I am pshc on github.
  • I am paulcollier (https://keybase.io/paulcollier) on keybase.
  • I have a public key ASCz0h-a2TV3_qKV68KZ26iWSQpLiOUdwieO6tsu6OIX_wo

To claim this, I am signing this object:

macro_rules! guard {
(let $($tt:tt)*) => {
let guard!(@lets (_) let $($tt)*)
= guard!(@step (()) let $($tt)*)
};
(match $($tt:tt)*) => {
let guard!(@lets (_) match $($tt)*)
= guard!(@step (()) match $($tt)*)
};
fn unwrappin_life() {
guard! {
let decl = match blk.stmts[0].node { StmtDecl(ref decl, _) };
let item = match decl.node { DeclItem(ref item) };
let expr = match item.node { ItemStatic(_, _, ref expr) };
let ptr = match expr.node { ExprAddrOf(_, ref ptr) };
let array = match ptr.node { ExprVec(ref array) };
else return nope!("lack of array of strings")
}
}
@pshc
pshc / dep.rs
Created December 1, 2014 09:48
#[cfg(test)] internal export hack
// HACK
#[cfg(test)]
pub use self::secret::internal;
mod secret {
pub fn internal() -> bool {
println!("you've broken my secret elbow!");
true
}
@pshc
pshc / gist:c44ca26f7038b772eb3c
Last active August 29, 2015 14:06
Toy tokenizer
use std::io;
use std::io::IoResult;
use std::owned::BoxAny;
use std::task;
#[deriving(Show)]
enum Token {
Equals,
Lit(int),
Let,
@pshc
pshc / bugsnag.py
Created August 21, 2013 01:57
Bugsnag exception dumping script
#!/usr/bin/env python2
API_KEY = "YOUR_API_KEY_HERE"
import pickle
import re
import requests
import sys
def request(path, **kwargs):
@pshc
pshc / gist:5427000
Last active December 16, 2015 11:19
fn hex_to_bytes(hex: &str) -> ~[u8] {
let n = hex.len();
assert!(n % 2 == 0);
return vec::from_fn(n / 2, |i| {
u8::from_str_radix(hex.substr(i*2, 2), 16).expect("bad hex")
});
}
fn bytes_to_hex(bytes: &[u8]) -> ~str {
let hex_chars = ~"0123456789abcdef";
@pshc
pshc / handler.js
Created April 14, 2011 22:32
Mongrel2 WebSockets testcase
var crypto = require('crypto'),
util = require('util'),
zeromq = require('zeromq');
var pullSocket = zeromq.createSocket('pull');
var publishSocket = zeromq.createSocket('pub');
pullSocket.connect('ipc://node.push.request.sock');
publishSocket.connect('ipc://node.sub.response.sock');
var myUUID = 'nodejs';