Skip to content

Instantly share code, notes, and snippets.

@possan
possan / cqs.cs
Created March 6, 2012 14:27
Minimal command query separation
namespace MakeMyDay
{
public interface ICommand { }
public interface ICommandHandler<T> where T : ICommand
{
void Handle(T cmd);
}
public interface ICommandValidator<T> where T : ICommand
@possan
possan / microAjax.js
Created April 19, 2012 11:21
microAjax fix
function microAjax(url, callbackFunction) {
var o = {};
o.bindFunction = function (caller, object) {
return function () {
return caller.apply(object, [object]);
};
};
o.stateChange = function (object) {
if (o.request.readyState == 4)
o.callbackFunction(o.request.responseText);
@possan
possan / RegexRouter.cs
Created April 23, 2012 08:21
Regex router mvc
// collection.Add(new RegexRoute("(^|[a-z0-9/]*/)[0-9]+/[0-9]+/[0-9]+/[a-z0-9_.-]*__([0-9]+)/flush$", "sectionpath,pageid", new { controller = "misc", action = "flush" }, new MvcRouteHandler()));
public class RegexRoute : RouteBase
{
private readonly string _match;
private readonly string _names;
private readonly RouteValueDictionary _defaults;
private readonly IRouteHandler _handler;
public RegexRoute(string match, string names, object defaults, IRouteHandler handler)
@possan
possan / test.js
Created April 28, 2012 18:36
Harassing some sifteo cubes with javascript
function Simulator(){
var ret = {}
var _callback = undefined;
var _queue = [];
var _counter = 0;
ret.fireCallback = function(json) {
// console.log('Fire event '+json);
if( _callback ) _callback(json);
}
@possan
possan / talkie.sh
Created June 4, 2012 12:03
Colloquy walkie talkie script (bash part)
tail -f ~/Documents/Colloquy\ Transcripts/* | awk 'BEGIN{FS="</event>";OFS="</event>\n\n"}{$1=$1}1' | python parse.py
@possan
possan / parse.py
Created June 4, 2012 12:04
Colloquy walkie talkie script (python part)
import re
import subprocess
import os
voices = ['Agnes','Kathy','Princess','Vicki','Victoria','Bruce','Fred','Junior','Ralph']
def voiceFromName(name):
x = 0
for c in name:
<html>
<head>
<link rel="stylesheet" href="sp://import/css/eve.css" />
<script src="jquery.min.js"></script>
<script>
$(document).ready(function() {
sp = getSpotifyApi(1);
var m = sp.require("sp://import/scripts/api/models");
@possan
possan / gist:2975870
Created June 23, 2012 00:00
Arduino RFID Ethernet junk
#include <SPI.h>
#include <Ethernet.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 9);
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x88 };
IPAddress server(91,123,198,230); // Google
int port = 80;
EthernetClient client;
int sent = 0;
@possan
possan / gist:3083478
Created July 10, 2012 14:08
Simple asynchronous mapper in javascript
Array.prototype.mapAsync = function(mapper, finalcallback) {
var waiting = 0;
var that = this;
var newlist = [];
this.forEach(function(item) {
// console.log('starting async mapper', item);
waiting ++;
setTimeout(function() {
mapper(item, function(newitem) {
@possan
possan / gist:3090607
Created July 11, 2012 14:13
Asynchronous mapper in javascript with timeout
Array.prototype.mapAsync = function(mapper, finalcallback, timeout) {
var mappertimeout = timeout || 10000;
var waiting = 0;
var that = this;
var newlist = [];
var _donecallback = function() {
waiting --;
console.log('after async mapper done');
if (waiting === 0) {