Skip to content

Instantly share code, notes, and snippets.

View b-studios's full-sized avatar

Jonathan Immanuel Brachthäuser b-studios

View GitHub Profile
@b-studios
b-studios / proceedable.rb
Created May 21, 2013 22:59
proceedable exceptions in ruby
require "continuation"
module Proceedable
class ProceedableException < Exception
def initialize(msg, cont)
super(msg)
@cont = cont
end
@b-studios
b-studios / loopcompiler.js
Created June 13, 2013 13:08
Simple loop compilation
function iterator(f, bindings) {
bindings = bindings || {};
var matches = f.toString().match(/function[^(]*\(\s*(\w+)\s*\)[^{]*(.*)/);
if (!matches) {
console.log("iterator function has wrong format, please use only one argument");
}
@b-studios
b-studios / Debugger.scala
Created June 20, 2013 17:50
An attempt to visualize kiama's rewriting process, the html output can be seen at http://b-studios.de/demos/kiama_debug/.
trait DebugRewriter extends org.kiama.rewriting.CallbackRewriter {
import org.bitbucket.inkytonik.dsprofile.Events.{Event, Start}
import org.bitbucket.inkytonik.dsprofile.Events
Events.profiling = true
// ... some outputbuffering and pretty printing here
override def rewriting[T] (oldTerm : T, newTerm : T) : T = {
@b-studios
b-studios / options.js
Last active December 26, 2015 14:59
Encoding Haskells `Maybe` or Scala's `Option` type in JavaScript using the new generators (es6)
function Option(value) {
this.value = value;
this.some = arguments.length == 1
}
Option.none = new Option()
Option.some = v => new Option(v)
Option.prototype.iterator = function () {
if (this.some) yield this.value
}
@b-studios
b-studios / nat.scala
Created November 16, 2013 18:22
Dependent Types and Generalized Type Constraints
sealed trait Nat
sealed trait Zero extends Nat
sealed trait Succ[N <: Nat] extends Nat
@b-studios
b-studios / ui.scala
Last active December 31, 2015 23:08
Example code to illustrate a different approach for Vaadin's scala wrapper classes using the "pimp my library" pattern.
package scalavaadin
import com.vaadin.{ ui => orig }
import scala.language.implicitConversions
import scala.collection.mutable
import scala.collection.JavaConversions
package object ui {
// Adding new Methods
@b-studios
b-studios / Sizeable.scala
Created December 30, 2013 17:15
Strongly Typed Version of Sizeable
package vaadin.scala
package server
import com.vaadin.{ server => orig }
import scala.language.implicitConversions
import scala.PartialFunction.condOpt
import apigen.annotations.accessors
@b-studios
b-studios / IdentityHashMap.scala
Created January 12, 2014 17:32
`IdentityHashMap` as adopted from `scala.collection.mutable.WeakHashMap`
package de.bstudios.collection.mutable
import scala.collection.mutable._
import scala.collection.generic._
import scala.collection.convert.Wrappers._
class IdentityHashMap[A, B] extends JMapWrapper[A, B](new java.util.IdentityHashMap)
with JMapWrapperLike[A, B, IdentityHashMap[A, B]] {
override def empty = new IdentityHashMap[A, B]
}
@b-studios
b-studios / object-encodings.scala
Created June 3, 2016 14:50
Comparing Object Encodings
/**
* This file contains some notes taken while reading:
*
* Comparing Object Encodings
* Kim B. Bruce, Luca Cardelli and Benjamin C. Pierce
*/
package object encodings {
// Library Stuff
trait Fix[F[_]] {
@b-studios
b-studios / monadic-oa.scala
Created June 8, 2016 13:19
Some experiments with monadic object algebras
object monadicOA {
type ??? = Any
trait Monad[M[+_]] {
def unit[A]: A => M[A]
def bind[A, B]: M[A] => (A => M[B]) => M[B]
def map[A, B]: M[A] => (A => B) => M[B]
}
object Monad {