Skip to content

Instantly share code, notes, and snippets.

# tested with hbase 0.19.3 and jython 2.2.1
import java.lang
from org.apache.hadoop.hbase import HBaseConfiguration, HTableDescriptor, HColumnDescriptor, HConstants
from org.apache.hadoop.hbase.client import HBaseAdmin, HTable
from org.apache.hadoop.hbase.io import BatchUpdate, Cell, RowResult
# First get a conf object. This will read in the configuration
# that is out in your hbase-*.xml files such as location of the
# hbase master node.
package packman;
import static packman.Game.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
@karmi
karmi / .gitignore
Created November 27, 2010 16:26
`tail -f` in Node.js and WebSockets
.DS_Store
*.log
tmp/
@ofan
ofan / lisp.cpp
Last active April 11, 2024 11:28
Lisp interpreter in 90 lines of C++
Lisp interpreter in 90 lines of C++
I've enjoyed reading Peter Norvig's recent articles on Lisp. He implements a Scheme interpreter in 90 lines of Python in the first, and develops it further in the second.
Just for fun I wondered if I could write one in C++. My goals would be
1. A Lisp interpreter that would complete Peter's Lis.py test cases correctly...
2. ...in no more than 90 lines of C++.
Although I've been thinking about this for a few weeks, as I write this I have not written a line of the code. I'm pretty sure I will achieve 1, and 2 will be... a piece of cake!
// akka-actor cheatsheet
// extract from http://doc.akka.io/actors-scala
class MyActor extends Actor { // Logging is included in Actor
// messages
def receive = {
case "foo" =>
doBar
case "logging" =>
@palladin
palladin / gist:1084507
Created July 15, 2011 11:20
Norvig's Spelling Corrector
// Norvig's Spelling Corrector: http://norvig.com/spell-correct.html
open System.IO open System.Text.RegularExpressions
let edits1 (word : string) =
let splits = [for i in 0 .. word.Length do yield (word.[0..i-1], word.[i..])]
let deletes = [for a, b in splits do if b <> "" then yield a + b.[1..]]
let transposes = [for a, b in splits do if b.Length > 1 then yield a + string b.[1] + string b.[0] + b.[2..]]
let replaces = [for a, b in splits do for c in 'a'..'z' do if b <> "" then yield a + string c + b.[1..]]
let inserts = [for a, b in splits do for c in 'a'..'z' do yield a + string c + b]
deletes @ transposes @ replaces @ inserts |> Set.ofList
@palladin
palladin / gist:1084511
Created July 15, 2011 11:21
Functional style Regex engine
let char c (s : string) = seq { if s.Length > 0 && s.[0] = c then yield s.Substring(1) }
let (=>) l r s = seq { for sl in l s do for sr in r sl -> sr }
let (<|>) l r s = seq { yield! l s; yield! r s }
let rec (<*>) e s = seq { yield s; yield! (e => (<*>) e) s }
let (<+>) e = e => (<*>) e
@palladin
palladin / gist:1084515
Created July 15, 2011 11:24
Actors acting as Lambdas
// Useful type aliases
type Actor = MailboxProcessor<obj>
type Ident = string
type Cond = Actor
type Env = Actor
let (<!>) (actor : Actor) (msg : 'T) = actor.Post msg
// run forever - template
@palladin
palladin / gist:1084722
Created July 15, 2011 13:46
Functional Unparsing SQL
// Functional Unparsing http://www.brics.dk/RS/98/12/BRICS-RS-98-12.pdf
open System
open System.Data
open System.Data.SqlClient
// Type Decls
type SqlText = string
type Counter = int
@palladin
palladin / gist:1085027
Created July 15, 2011 16:32
Clojure's Atoms
open System.Threading
type Atom<'T when 'T : not struct>(value : 'T) =
let refCell = ref value
let rec swap f =
let currentValue = !refCell
let result = Interlocked.CompareExchange<'T>(refCell, f currentValue, currentValue)
if obj.ReferenceEquals(result, currentValue) then ()
else Thread.SpinWait 20; swap f