Skip to content

Instantly share code, notes, and snippets.

View DylanLukes's full-sized avatar

Dylan Lukes DylanLukes

View GitHub Profile
var noflo = require('noflo');
var fbp = require('fbp');
var fs = require('fs');
var path = require('path');
var util = require('util');
var browserify = require('browserify');
var coffeeify = require('coffeeify');
var through = require('through2');
var stream = require('stream');
var wait = require('wait.for');
-- | Garden variety prime sieve
isPrime x = not $ any divisible $ takeWhile bounded [2..] where
divisible y = x `mod` y == 0
bounded y = y * y <= x
-- | Germain prime sieve
isGermainPrime x = (isPrime x) && (isPrime (2*x + 1))
-- | All of the Germain primes
// this is the "generated" code (loading from fs is still 'generating'...)
module.exports = function() { console.log('hello world'); }
trait Arrow<B, C> {
fn apply(&self, B) -> C;
}
impl<'a, B, C> Arrow<B, C> for 'a |B| -> C {
fn apply(&self, b: B) -> C { (*self)(b) }
}
fn compose<A, B, C>(g: &Arrow<B, C>, f: &Arrow<A, B>) -> ~Arrow<A, C> {
~|a: A| -> C { g.apply(f.apply(a)) } as ~Arrow<A, C>
trait Arrow<B, C> {
fn call(&self, B) -> C;
fn compose<A, G: Arrow<A, B>, H: Arrow<A, C>>(&self, G) -> H;
}
trait Arrow<A, B> { }
trait Category {
fn id<A, F: Arrow<A, A>>() -> F;
//fn compose<A, B, C, F: Arrow<A, B>, G: Arrow<B, C>, H: Arrow<A, C>>(f: F, g: G) -> H;
}
/* closures */
impl<'a, A, B> Arrow<A, B> for 'a |A| -> B { }
trait Category<S, T> {
fn id<A, AA: Category<A, A>>() -> AA;
fn compose<A, B, C, AB: Category<A, B>, BC: Category<B, C>, AC: Category<A, C>>(BC, AB) -> AC;
}
impl<'a, S, T> Category<S, T> for ('a |S| -> T) {
fn id<A, |A| -> A>() -> ('a |A| -> A) {
|a: A| -> A { a }
}
struct Thing { ... }
struct Collection { things: ~[~Thing] }
impl Collection {
fn get_thing(&self) -> Thing<$self> { ... }
fn get_other_thing(&self) -> Thing<$self> { ... }
fn compare(t1: Thing<$a>, t2: Thing<$a>) -> uint { ... };
}
fn foo(c1: Collection, c2: Collection) -> uint {
use std::libc::*;
#[link_args="src/httpparser/http_parser.c src/httpparser/stubs.c"]
extern {
fn http_parser_version() -> c_ulong;
fn http_parser_stubs_alloc() -> HttpParserPtr;
}
#[fixed_stack_segment]
#[inline(never)]
@DylanLukes
DylanLukes / calc.rs
Last active December 21, 2015 09:29
use std::iterator::{Peekable};
fn accept<T: Iterator<char>>(it: &mut Peekable<char, T>, c: char) -> bool {
if *(it.peek().unwrap()) == c {
it.next();
return true;
}
return false;
}