Skip to content

Instantly share code, notes, and snippets.

View rrichardson's full-sized avatar
💭
⚔️ Hacking Away

Rick Richardson rrichardson

💭
⚔️ Hacking Away
View GitHub Profile
import itertools
def possible_combos(n, m):
ary = [0,0,0,0]
j = 0
while j < m:
j += 1
for i in range(n-1, -1, -1):
ary[i] = ary[i] + 1
#[inline]
fn struct_to_bytes<T>(t: &T) -> &[u8] { unsafe {
mem::transmute(raw::Slice::<u8> {
data: t as *const T as *const u8,
len: mem::size_of::<T>(),
})
}}
#[inline]
fn bytes_to_struct<'a, T>(t: &'a [u8]) -> Option<&'a T> {
pub struct DropCopyProto;
impl Protocol for DropCopyProto {
type Output = DropCopy;
fn new() -> DropCopyProto {
DropCopyProto
}
fn append(&mut self, buf: &AROIobuf) -> Option<(<Self as Protocol>::Output, AROIobuf, u32)> {
Compiling rx v0.0.2 (file:///home/rick/Projects/RxRust)
src/reactor.rs:125:20: 125:41 error: the parameter type `T` may not live long enough
src/reactor.rs:125 proto: <T as Protocol>::new(),
^~~~~~~~~~~~~~~~~~~~~
src/reactor.rs:125:20: 125:41 help: consider adding an explicit lifetime bound `T: 'static`...
src/reactor.rs:125 proto: <T as Protocol>::new(),
^~~~~~~~~~~~~~~~~~~~~
src/reactor.rs:125:20: 125:41 note: ...so that the declared lifetime parameter bounds are satisfied
src/reactor.rs:125 proto: <T as Protocol>::new(),
^~~~~~~~~~~~~~~~~~~~~
pub trait Subscriber {
type Input;
fn on_next(&mut self, t: Self::Input) -> bool;
fn on_subscribe(&mut self, usize) {
debug!("on_subscribe called");
}
fn on_error(&mut self, err: &str) {
error!("on_error called: {:?}", err);
}
@rrichardson
rrichardson / gist:27784b3771ff8044c1e2
Created January 10, 2015 21:54
ExpressJS boilerplate / starter
var express = require("express");
var expressSession = require("express-session");
var bodyParser = require("body-parser");
var http = require("http");
var path = require("path");
var passport = require("passport");
stack backtrace:
1: 0x7f843f6c6850 - sys::backtrace::write::h5b05e7b061a35107Czt
2: 0x7f843f6e8a60 - failure::on_fail::h1e9b7e3de59488d1aPz
3: 0x7f843f6565e0 - rt::unwind::begin_unwind_inner::h23dcfb4c37870bd62tz
4: 0x7f843d7c3960 - rt::unwind::begin_unwind::h13789887957783664646
5: 0x7f843db5e580 - middle::ty::lookup_trait_def::h4590f6ca5c5cdfe2YK8
6: 0x7f843db7fcb0 - middle::ty::predicates_for_trait_ref::hb3e019a71a18e2d75L8
7: 0x7f843db57c30 - middle::traits::util::Elaborator<'cx, 'tcx>.Iterator::next::hbd30b487fd03287cfiU
8: 0x7f843db5cb60 - middle::traits::util::Supertraits<'cx, 'tcx>.Iterator::next::hcd7ed39c8850ea00QkU
9: 0x7f843eedac80 - astconv::ast_ty_to_ty::unboxed_closure.29245
unsafe fn struct_to_bytes<T>(t: &T) -> &[u8] {
mem::transmute(raw::Slice::<u8> {
data: t as *const T as *const u8,
len: mem::size_of::<T>(),
})
}
use std::ops::{Shl, Shr};
pub trait Subscriber<A> {
fn on_subscribe(&mut self, uint);
fn on_next(&mut self, t: A);
fn on_error(&mut self, err: &str);
fn on_complete(&mut self, force: bool);
}
pub trait Publisher<B> {
fn run<F> (endpoints: Vec<String>,
batch_size: uint,
query: String,
init_strings: Option<Vec<String>>,
f: F) -> Sender<Control<T>>
where F : Send + Fn(&Prepared, &T) -> Statement
{
let (tx1, rx1) : (Sender<Control<T>>, Receiver<Control<T>>) = channel();
spawn(|:| {