Skip to content

Instantly share code, notes, and snippets.

View jameskeane's full-sized avatar
🏠
Working from home

James Keane jameskeane

🏠
Working from home
View GitHub Profile
@jameskeane
jameskeane / gist:4993362
Last active December 13, 2015 23:39
Pondering Django Server-Sent Events
# Uses django-signals behind the scenes to throw the events around
# Also uses gevent.pywsgi.WSGIServer to stream the event source.
# Basic usage
from django.dispatch import Events
from django.contrib.auth.models import User, Group
# Basic support for individual users
user = User.objects.get(id=1)
user.subcribe('event:name another:event') # subscriptions are session persistent (configurable to db)?
@jameskeane
jameskeane / api.js
Created October 1, 2012 16:33
Working draft of 3rd party module API
// Top hat monocle - third party module API
// =====
// ## Module Discovery
// All 3rd party modules _must_ be discoverable based on a simple http resource URI
// i.e.
// GET /modules/question
{
name: "Question Module",
Coffeescript + types + haskell = compiled language
=========
- Increments an infinite precision number, represented as a linked list with least significant digit as head
increment = (x: [Num]) ->
switch x
when [] then [1]
when (9::tail) then 0::increment(tail)
when (h::t) then (h+1)::t
@jameskeane
jameskeane / coffee.cpp
Created July 9, 2011 08:30
Static Coffeescript
#include <utility>
#include <vector>
#include <unordered_map>
#include <initializer_list>
using namespace std;
template<typename T> vector<T> StaticVector(initializer_list<T> list) { return list; }
template<typename T, typename Y> unordered_map<T, Y> StaticHashMap(initializer_list< pair<T, Y> > list) {
unordered_map<T, Y> ret;
for (auto it = list.begin(); it != list.end(); it++)
@jameskeane
jameskeane / Levenshtein.go
Created July 6, 2011 23:42
Levenshtein Distance
func min(a1 int, a2 int, a3 int) int {
min := a1
if a2 < min {
min = a2
}
if a3 < min {
min = a3
}
return min
}
@jameskeane
jameskeane / posterous.css
Created July 6, 2011 08:11
My Posterous style
* {padding:0;margin:0;}
img {border:0;}
.clear {clear:both;font-size:5px;}
.left {float:left;}
.right {float:right;}
.text-right {text-align:right;}
.center {text-align:center;}
.small {font-size:.857em !important;} /* 12px */
.xsmall {font-size:.786em !important;} /* 11px */
@jameskeane
jameskeane / lazy.cpp
Created July 6, 2011 07:54
C++0x Lazy list (simple)
#include <functional>
template<typename T>
class LazyList
{
public:
typedef std::function<T(unsigned int, LazyList<T>*)> Generator;
LazyList(Generator gen)
: m_gen(gen)
{
@jameskeane
jameskeane / fib.cpp
Created July 6, 2011 07:53
C++0x lazy list example
LazyList<int> fibonacci([](unsigned int index, LazyList<int> *obj) -> int
{
if(index < 2) return index;
return (*obj)[index-1] + (*obj)[index-2];
});
/* Print the first 20 fibonacci numbers */
for(int i = 0; i < 20; i++)
printf("%d ", fibonacci[i]);