Skip to content

Instantly share code, notes, and snippets.

View jeffreyolchovy's full-sized avatar

Jeffrey Olchovy jeffreyolchovy

View GitHub Profile
@jeffreyolchovy
jeffreyolchovy / gist:508217
Created August 4, 2010 14:28
Simple inheritance model for JavaScript
function extend(p, c)
{
var f = function() {};
f.prototype = p.prototype;
c.prototype = new f();
c.prototype.constructor = c;
}
function mixin(p, c)
{
@jeffreyolchovy
jeffreyolchovy / gist:508768
Created August 4, 2010 20:45
Inheritance model for JavaScript
function Debug() {
var frame = window.open("", "Debugger", "location=no,scrollbars=yes,height=300,width=400");
var console = frame.document.createElement("div");
console.setAttribute("id", "console");
console.style.margin = "auto";
console.style.width = "350px";
console.style.overflow = "auto";
frame.document.body.appendChild(console);
@jeffreyolchovy
jeffreyolchovy / gist:721229
Created November 30, 2010 05:50
Simple type class for formatting objects as JSON or XML
package com.olchovy.format
import scala.xml._
import net.liftweb.json.JsonAST._
trait Formatter[-A, B] {
def format(a: A): B
}
object Formatters {
@jeffreyolchovy
jeffreyolchovy / primitive_fgc.py
Created May 25, 2011 21:32
Primitive Example of PubSub using the Flow Platform for Feedgen
import sys, json
import flow
class Context(object):
def __init__(self, client):
client.set_logger_file('fgc.out')
self.client = client
self.create_application()
self.create_application_flows()
@jeffreyolchovy
jeffreyolchovy / complex_fgc.py
Created May 26, 2011 18:08
Complex Example of PubSub using the Flow Platform for Feedgen
import sys, json
import flow
class Context(object):
CATEGORIES = {
'a': { 'parent': None },
'b': { 'parent': 'a' },
'c': { 'parent': 'a' },
'd': { 'parent': 'b' },
'e': { 'parent': 'd' },
@jeffreyolchovy
jeffreyolchovy / type_classes_via_dynamic_programming.py
Created July 14, 2011 16:52
Type classes in Python via Dynamic Programming
#!/usr/bin/env python2.6
import abc
class Kind(object):
__metaclass__ = abc.ABCMeta
kindtypes = dict()
datatypes = list()
@jeffreyolchovy
jeffreyolchovy / objectid.erl
Created September 14, 2011 15:24
Convert a BSON ObjectId from binary to hex.
-module(objectid).
-author("[email protected]").
-export([binary_to_hex/1]).
extract_binary_data(BsonObjectId) ->
case BsonObjectId of {Binary} -> Binary; Binary -> Binary end.
binary_to_hex(BsonObjectId) ->
Binary = extract_binary_data(BsonObjectId),
list_to_binary(lists:flatten([io_lib:format("~2.16.0b", [X]) || <<X:8>> <= Binary])).
@jeffreyolchovy
jeffreyolchovy / LRUCache.scala
Created August 6, 2012 21:19
LRU cache implementation in Scala
import akka.stm._
import scala.collection.immutable.ListMap
case class LRUCache[A, B](private val MAX_ENTRIES: Int)
{
protected val cache = Ref(ListMap.empty[A, B])
def getOrElse(key: A)(fn: => B): B = {
get(key).getOrElse {
val result = fn
@jeffreyolchovy
jeffreyolchovy / RecursiveStreams.scala
Created August 30, 2012 15:15
Recursive Streams in Scala
import scala.math.{BigInt, BigDecimal}
object RecursiveStreams
{
// natural numbers
lazy val N: Stream[BigInt] = Stream.cons(BigInt(1), N.map(_ + 1))
// fibonacci series
lazy val fib: Stream[BigInt] = Stream.cons(BigInt(0), Stream.cons(BigInt(1), fib.zip(fib.tail).map(a => a._1 + a._2)))
@jeffreyolchovy
jeffreyolchovy / build.sbt
Created December 15, 2014 06:00
sbt-build-info
sbtPlugin := true
name := "sbt-build-info"
organization := "com.tapad"
version := "0.1.3"
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")