Skip to content

Instantly share code, notes, and snippets.

@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
{
@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 / 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 / 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 / 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 / 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 / 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 ) {
zlib = require 'zlib'
module.exports = (robot) ->
robot.respond /(stack|ss) ?(find:.*) ?(tags:.*)/i, (msg)->
query = msg.match[2]
query2 = msg.match[3]
query = query.replace /find:/i, ""
query2 = query2.replace /tags:/i, ""
@arobson
arobson / Dependency URLs
Created March 8, 2012 10:02
A Cartographer Starter HTML Page
These URLs should be to the actual script files and can be used for to populate tools like JS Fiddle.
Cartographer:
https://raw.github.com/arobson/cartographer.js/master/lib/cartographer.min.js
jQuery:
http://code.jquery.com/jquery-1.7.1.min.js
Underscore:
https://raw.github.com/documentcloud/underscore/master/underscore-min.js
@arobson
arobson / forkjoin-mockjax-defs.js
Created March 22, 2012 08:58
Mockjax Definitions for my Fork Join Blog post
$.mockjax( {
url: "http://api.github.com/users/arobson",
type: "GET",
status: 200,
data: {
"name": "Alex Robson",
"company": "appendTo",
"public_repos": 31,
"followers": 18,
"following": 4,