Skip to content

Instantly share code, notes, and snippets.

@matthewphilyaw
matthewphilyaw / reverseProxy.js
Created January 12, 2014 16:55
Simple reverse proxy. forwards /api to a different server. Keeps path after api/ in that if you have api/somecall?test=blah it will forward has /somecall?test=blah.
var express = require('express'),
request = require('request'),
url = require('url');
var port = 8080;
var app = express();
app.use(function(req, res, next) {
var proxyUrl = req.path.match(/^\/api(.*)$/);
if (proxyUrl) {
@matthewphilyaw
matthewphilyaw / user.json
Created February 25, 2014 04:47
api-handlers builder
{
"filterBy": [
{ "property": "id", "type": "num" },
{ "property": "name", "type": "string"}
],
"data": [
{
"id": 1,
"name": "tphilyaw",
"firstName": "tommy",
extern mod extra;
use extra::arc::Arc;
fn main() {
let x = ~5;
let y = Arc::new(x); // x is no longer pointer to ~5, and y points to the pointer x was that is not to the value but the
// but the pointer x held.
let z = y.clone(); // same semantics, the clone produces a pointer to the pointer x was.
println!("{}", **(y.get())); // see we have that double reference we have to deref twice.
@matthewphilyaw
matthewphilyaw / fmt.rs
Created March 18, 2014 11:05
use of traits
use std::fmt;
struct Name {
first: ~str,
last: ~str
}
// I'm printing a string here, but
// in reality this could be binary output
impl fmt::Binary for Name {
// these two are taken from the docs
struct Point {
x: f64,
y: f64
}
// They use shape later in the docs to show pattern matching
// but I'm going to attempt to explain it
define("app/templates/application", ["exports"], function(__exports__){ __exports__["default"] = function anonymous(Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Ember.Handlebars.helpers); data = data || {};
var buffer = '', stack1, helper, options, self=this, helperMissing=helpers.helperMissing;
function program1(depth0,data) {
data.buffer.push("Builder");
}
@matthewphilyaw
matthewphilyaw / convertolist.ex
Last active August 29, 2015 14:20
Elixir bit syntax example
speed = 500
angle = -200
# being very explicit here, I believe the default
# unit is 8, and the endianess is big
#
# So I do need to pack this message in particular way according to the
# specs for the roomba serial interface, which is the like this
#
# command [optional bytes]
@matthewphilyaw
matthewphilyaw / Maybe.cs
Last active December 26, 2015 20:29
Maybe monad in C#
using System;
namespace Maybe
{
interface Maybe<T>
{
T Value();
bool HasValue();
Maybe<T> Bind(Func<T, Maybe<T>> f);
}
open System
type Maybe<'a> =
| Just of 'a
| Nothing
let Unit (x: 'a) : Maybe<'a> =
Just x
let Bind (f: 'a -> Maybe<'b>) (mx: Maybe<'a>) =
@matthewphilyaw
matthewphilyaw / Maybe2.cs
Created December 27, 2015 16:37
Maybe Monad take 2
using System;
namespace Maybe
{
abstract class Maybe<T> {
public static Maybe<T> Return(T val)
{
return new Just<T> (val);
}