Skip to content

Instantly share code, notes, and snippets.

@arobson
arobson / binder.js
Created September 2, 2011 05:53
An ugly POC for decoupled 'binding' in Javascript
var DomWriter = function (target, namespace) {
var instance = this;
var template = namespace;
var coalesce = function( value, defaultValue ) {
return typeof(value) != 'undefined' ?
value : defaultValue;
};
this.isObject = function( value ) {
@arobson
arobson / gist:1167335
Created August 24, 2011 04:52
Improved Approach To Limiting Asynchronous Calls with Rx
Action<IList<XElement>> saveAction = SaveChunk;
var loader = new BulkPostLoader(@"e:\stackoverflow\062010 so\posts.xml");
var batches = loader.BufferWithCount(5000);
var results = batches.Select(x => saveAction.BeginInvoke(x, null, null));
results
.Aggregate(new HashSet<IAsyncResult>(), (set, result) =>
{
set.RemoveWhere(x => x.IsCompleted);
set.Add(result);
@arobson
arobson / coffee-pubsub
Created August 10, 2011 04:57
coffeescript pub/sub demo for rabbitmq
sys = require "sys"
rabbit = require "amqp"
console.log "Connecting to rabbit..."
connection = rabbit.createConnection { host: "localhost", port: 5672 }
connection.on "ready", () ->
exchangeOptions = { type: "fanout", autoDelete: true }
connection.exchange(
@arobson
arobson / http_server1
Created June 17, 2011 19:07
Snippet of the 'Dynamic' HTTP server that accomodates RESTful requests and static content using Misultin.
handle_request(Req) ->
#req{uri={_,Uri}} = Req:raw(),
Ext=filename:extension(Uri),
handle_request(Req, Uri, Ext).
handle_request(Req, _Uri, []) ->
Segments = Req:resource([urldecode]),
Method = get_atom(Req:get(method)),
[Resource|Arguments]=Segments,
ResourceModule = get_atom(Resource),
@arobson
arobson / RiakDemo.cs
Created February 8, 2011 01:27
A really cheesy example of how the Repository and KeyValue APIs work for Riak.
class Program
{
static void Main(string[] args)
{
Assimilate
.Core<StructureMapAdapter>()
.AddConsoleLogger<RiakService>( x => x.Info().MessageLayout( m => m.Message().Newline() ) )
.Messaging()
.Daemon( x => x.Arguments( args ).Name( "Riak Demo" ) )
.Riak( x => x.AddNode( r => r.Address( "192.168.1.100" ) ) )
@arobson
arobson / OWINFileServer.cs
Created January 26, 2011 20:05
A contrived but fun example of how to build a OWIN compliant file server using Symbiote.
using System;
using System.Collections.Generic;
using Symbiote.Core;
using Symbiote.Http;
using Symbiote.Http.Impl;
using Symbiote.Http.Owin;
using Symbiote.StructureMap;
using Symbiote.Daemon;
using Symbiote.Messaging;
using Symbiote.Actor;
@arobson
arobson / RingBuffer.cs
Created January 24, 2011 05:37
This is a very different approach I took from initial attempts that relied on volatile arrays and a crap ton of pointers. This is more fun :)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Machine.Specifications;
namespace ringbuffer
{