Skip to content

Instantly share code, notes, and snippets.

View laurencer's full-sized avatar

Laurence Rouesnel laurencer

  • Meta AI
  • New York, New York
View GitHub Profile
@laurencer
laurencer / GenericLuaParsing.hs
Last active September 23, 2015 22:43
Generic Lua Table Parsing Example
#!/usr/bin/env stack
-- stack --resolver lts-3.4 --install-ghc runghc --package hslua --package bytestring --package monad-loops --package shakespeare --package heredoc --package interpolatedstring-perl6
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
import qualified Scripting.Lua as Lua
@laurencer
laurencer / merge.sh
Created April 17, 2015 07:40
Merging Git Repositories togther
export prefix="ssh://git@???:7999/???/" # prefix for the repo
export suffix=".git" # suffix for the repo address
function merge() {
repo=$1
git remote add -f $repo ${prefix}${repo}${suffix}
git merge -s ours --no-commit ${repo}/master
git read-tree --prefix=${repo}/ -u ${repo}/master
git commit -m "Merged ${repo} subtree"
}
@laurencer
laurencer / ThriftEncoding.scala
Created January 15, 2015 22:27
Thrift Encoding Comparison
===============================================================================
|FeatureValue.thrift |
===============================================================================
namespace java com.rouesnel.features
union Value {
1: bool boolValue;
2: i32 intValue;
@laurencer
laurencer / ObjectsWithApplyMethods.md
Created August 1, 2014 06:04
When to use an Object with a Apply Method

When to use an Object with a Apply Method

If its a pure function and thus doesn't require a class instance we can put it on an object. Additionally if its sufficiently complicated and decomposable that its functionality is implemented in several helper functions.

By naming it apply, we indicate its the main function in the group of functions - and now we can invoke the object directly.

For example, a ComputeOptimalBinPacking object/function was named after its main purpose. Thus using apply has the nice effect that you can use it directly ComputeOptimalBinPacking(...) whilst still being able to see the helper functions ComputeOptimalBinPacking.rotateBin(...).

It didn't really make sense to have ComputeOptimalBinPacking.actuallyComputeTheBinPacking(...) exposed to callers (it makes it difficult to see which one they should use).

@laurencer
laurencer / ScalazStreamResourceErrorHandling.scala
Created June 25, 2014 04:14
Demonstrates how errors affect `scalaz-stream` when using `io.resource`.
import scala.util._
import scalaz._, Scalaz._, concurrent._, stream._
// Testing error handling with scalaz-stream `io.resource`
// Specifically how it works when a Sink/Channel produces
// a function.
def testErrorInOpen = {
@laurencer
laurencer / ScalazStreamDeterminism.scala
Created June 25, 2014 04:02
Sample to test `scalaz-stream`'s execution determinism.
import java.lang.Thread
import java.util.concurrent.{Executors, ExecutorService}
import scalaz._, Scalaz._, concurrent._, stream._
// Testing determinism vs threading.
def testTwoThreads() = {
val first = Executors.newSingleThreadExecutor()
@laurencer
laurencer / Ramp.scala
Created June 15, 2014 01:07
Sketch of implementing RAMP-Fast Transactions in a somewhat generic/abstract manner.
package com.rouesnel.ramp
import scalaz._, Scalaz._, Free._, effect._
object RampFast {
type Result[T] = IO[Exception \/ T]
type Key = String
type Value = Array[Byte]
type Version = Int
@laurencer
laurencer / backbone-nested-mutators.coffee
Created January 25, 2013 12:37
Enables mutator support (ala Backbone.Mutators) for Backbone-NestedModel.
# Written by Laurence Rouesnel (laurencer)
# Based on https://github.com/asciidisco/Backbone.Mutators
class Backbone.NestedModelWithMutators extends Backbone.NestedModel
constructor: ->
if _.isFunction(@mutators) then @mutators = @mutators()
super(arguments...)
get: (attr) =>