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 / closure.js
Created July 20, 2014 03:31
closure library for ternjs
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
return mod(require("../lib/infer"), require("../lib/tern"));
if (typeof define == "function" && define.amd) // AMD
return define(["../lib/infer", "../lib/tern"], mod);
mod(tern, tern);
})(function(infer, tern) {
"use strict";
var WG_TEMP_OBJ = 40;
<link rel="import" href="../polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;
<link rel="import" href="../topeka-elements/theme.html">
<link rel="import" href="../topeka-elements/topeka-resources.html">
<link rel="import" href="../topeka-elements/topeka-app.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
@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 / 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]);
@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 / 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 / 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++)
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 / 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",