Skip to content

Instantly share code, notes, and snippets.

object ExistentialTest {
case class Box[T]()
case class Pair[T](a: Box[T], b: Box[T])
val pair: Pair[_] = ???
val pair2 = Pair(pair.a, pair.b)
}
@jimmydivvy
jimmydivvy / EvilPromise.hs
Created June 14, 2015 05:24
Evil Promises
module Main where
{-
Warning: This is not an example of something you should ever do.
This is an academic excercise to scratch an itch.
Every single line of this file is morally wrong and violates all that
is good and holy in the world.
-}
@jimmydivvy
jimmydivvy / JavascriptIOMonadExample.js
Last active May 26, 2024 18:47
Simple IO Monad example in Javascript
class IO {
// We construct the IO type with a thunk/callback that returns the value when called
constructor( fn ){
this.fn = fn;
}
// IO doesn't do anything until we explicitly call it.
run(){
return this.fn();
@jimmydivvy
jimmydivvy / PoorMansPromise.js
Last active August 29, 2015 14:23
Basic promise implementation
/* Very basic promise implementation */
class Promise {
observers: [];
value: T;
resolved: Boolean;
constructor(){
this.observers = [];
@jimmydivvy
jimmydivvy / gist:2bd8bceae5ee0b5fa229
Created March 19, 2015 04:13
Softlayer routing issues
Routing from east coast Australia to Softlayer... via Perth? (Wrong side of the country!)
traceroute to softlayer.com (66.228.119.72), 30 hops max, 60 byte packets
1 192.168.1.1 (192.168.1.1) 0.316 ms 0.300 ms 1.897 ms
2 gw101.cha24.brisbane.telstra.net (203.45.253.1) 3.279 ms 3.462 ms 3.583 ms
3 tengige0-8-0-2.woo-core1.brisbane.telstra.net (203.50.51.129) 12.150 ms 12.159 ms 12.197 ms
4 bundle-ether11.chw-core10.sydney.telstra.net (203.50.11.70) 17.636 ms 18.027 ms 18.152 ms
5 bundle-ether8.exi-core10.melbourne.telstra.net (203.50.11.125) 36.428 ms 36.436 ms 36.434 ms
6 bundle-ether5.way-core4.adelaide.telstra.net (203.50.11.92) 45.297 ms 58.743 ms 59.433 ms
7 bundle-ether5.pie-core1.perth.telstra.net (203.50.11.17) 86.472 ms 86.906 ms 86.907 ms
import scalaz._, Scalaz._
sealed trait Action
case class Insert(ids:Seq[Int]) extends Action
case class Update(ids:Seq[Int]) extends Action
case class Delete(ids:Seq[Int]) extends Action
object Test extends App {
import scalaz._, Scalaz._
def bench[T](fn: => T):(T,Long) = {
val start = System.currentTimeMillis()
val result = fn
val end = System.currentTimeMillis()
(result, end - start)
}
@jimmydivvy
jimmydivvy / Bug.js
Created February 23, 2014 08:58
Bacon.Model bug?
var bob = Bacon.Model({
name: "Bob",
age: 30
});
console.log( bob.lens("name").get() ); // "Bob" as expected
Bacon.constant(1).onValue(function(){
console.log( bob.lens("name").get() ); // Undefined
});
moment.parseInTz = function () {
var args = [], i, len = arguments.length - 1;
for (i = 0; i < len; i++) {
args[i] = arguments[i];
}
var m = moment.apply(null, args);
var preTzOffset = m.zone();
m.tz(arguments[len]);
return m.add('minutes', m.zone() - preTzOffset);
};
@jimmydivvy
jimmydivvy / Fib.scala
Created March 4, 2013 06:31
Recursive Fibonacci using tail recursion
def fib( n: Long ):Long = {
def fib_tailrec( n:Long, a:Long, b:Long ):Long = {
n match {
case 0 => a
case _ => fib_tailrec( n - 1, b, a + b )
}
}
fib_tailrec(n, 0, 1)
}