Skip to content

Instantly share code, notes, and snippets.

@mucaho
mucaho / SortedMultiMap.scala
Created April 15, 2014 17:28
Immutable, sorted multi map in Scala
import scala.collection._
import scala.collection.generic.CanBuildFrom
import scala.Iterator
/**
* Factory singleton for creating a [[ .SortedMultiMap SortedMultiMap]].
*/
object SortedMultiMap {
/**
* Construct an empty [[ .SortedMultiMap SortedMultiMap]].
@mucaho
mucaho / ClosureTrap.js
Last active August 29, 2015 13:57
JavaScript - Fix loop variable closure trap
// See http://stackoverflow.com/q/750486 for details
var callbacksIncorrectValue = [];
var callbacksCorrectValue = [];
var callbacksReference = [];
var array = ["A", "B", "C"];
for (var i = 0; i < array.length; ++i) {
var element = array[i];
callbacksReference.push(function() { return array[i] });
callbacksIncorrectValue.push(function() { return element });
@mucaho
mucaho / DatabaseTest.java
Last active August 29, 2015 13:56
TestNG + JMockit - @dataProvider parameters + local @mocked abstract classes / interfaces
/**
* see Boeffi's tutorial: http://boeffi.net/tutorials/local-mock-variables-ein-dritter-weg-in-jmockit/
*
* useful for abstract classes / interfaces (shorter than implementing all methods for a "dummy" instance which is dynamically partially mocked afterwards; cleaner than static partial mocking)
* take a look at dynamic partial mocking for mocking concrete classes:
* http ://jmockit.googlecode.com/svn/trunk/www/tutorial/BehaviorBasedTesting.html#dynamicPartial
*/
public final class DatabaseTest {
public interface IUser {}
public interface IPassword {}
@mucaho
mucaho / src.YOUR_CODE.scala
Created February 13, 2014 10:42
Akka Actors to be executed in Swing / JavaFX thread - based on Victor Klang's [Swing Actors](https://gist.github.com/viktorklang/2422443)
// After that we just create the GUI Actors with a Props with the correct dispatcher set:
val javaFxActor = context.actorOf(Props[JavaFxActor].withDispatcher("javafx-dispatcher"), "javaFxActor")
val swingActor = context.actorOf(Props[SwingActor].withDispatcher("swing-dispatcher"), "swingActor")
// Done! Now all messages processed by the new actor will be executed by the Swing/JavaFX Event Dispatch Thread, enjoy!
@mucaho
mucaho / ClassPrototype.js
Last active August 29, 2015 13:56
JavaScript prototype template
var Person = (function() {
// private statics
var greetHeader = "Welcome,";
var greetFooter = "! Have a nice day!";
// constructor -- define instance specific stuff
function Person(isMale, firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;