Skip to content

Instantly share code, notes, and snippets.

@lazyval
lazyval / fail.sml
Last active December 12, 2015 09:28
SML code that leads to type inference fail.
fun all_answers func [] = SOME []
fun all_answers func xs = let
fun loop [] = []
| loop (h::tail) = case (func h) of
SOME x => x :: loop tail
| NONE => loop tail
in case loop xs of
[] => NONE
| lst => SOME lst
end
@lazyval
lazyval / possibly_bug.scala
Last active December 12, 2015 09:29
Possible bug during object init (or perhaps scala just throws away code that produces only side effects)
object Foo {
val bar = { println("bar"); 42 }
}
object Foo2 {
val bar = { println("bar") }
}
// scala> Foo.bar
// bar
val tens = Map (
'2' -> "Twenty",
'3' -> "Thirty",
'4' -> "Fourty",
'5' -> "Fifty",
'6' -> "Sixty",
'7' -> "Seventy",
'8' -> "Eighty",
'9' -> "Ninety"
) withDefaultValue("")
@lazyval
lazyval / ant.rb
Last active December 14, 2015 20:29
Homebrew formula for ant 1.9.0
require 'formula'
class Ant < Formula
homepage 'http://ant.apache.org/'
url 'http://www.apache.org/dyn/closer.cgi?path=ant/binaries/apache-ant-1.9.0-bin.tar.gz'
sha1 '791418e7e80e3f28d6347528e8992a14f09058e7'
def install
rm Dir['bin/*.{bat,cmd,dll,exe}']
libexec.install Dir['*']
@lazyval
lazyval / README.md
Last active December 15, 2015 01:39
UK postcodes to geo coordinates
@lazyval
lazyval / gist:5203258
Created March 20, 2013 08:57
JVM types are ZBSCIJFDL
JVM types are ZBSCIJFDL
// it's good style to mark such objects/classes with sealed to guide complier
// so it will check if match is exhaustive (all possible cases covered)
sealed abstract class Response
sealed abstract class Reason
abstract class TokenType
case class Token(t: TokenType) extends Response
case class Problem(reason: Reason) extends Response
case object InvalidResponse extends Reason
@lazyval
lazyval / rotating_file.py
Created June 28, 2013 11:47
Rotating file implementation for python. I'm ignoring any error handling and proper closing here
import os
import os.path
buffer_in_bytes = 10 * 100 * 100
class RotatingFile:
def __init__(self, filename, max_files, lines_per_file):
self.file = open(filename, mode='w', buffering=buffer_in_bytes)
self.filename = filename
self.max_files = max_files
val l1 = LinkedList(1)
l1.append(LinkedList(7))
l1
// res14: scala.collection.mutable.LinkedList[Int] = LinkedList(1, 7)
val l0 = LinkedList[Int]()
l0.append(LinkedList(7))
l0
// res16: scala.collection.mutable.LinkedList[Int] = LinkedList()
@lazyval
lazyval / assignment.txt
Created November 21, 2013 18:08
epidemy
Epidemy Simulation
In this part, you are going to write an epidemy simulator based on the simulation framework seen in lecture and used in the circuit simulation.
The scenario is as follows: the world (“Scalia”) consists of regular grid of 64 rooms (8x8) where each room is connected to four neighbouring rooms. Each room may contain an arbitrary number of persons. Scaliosis – a vicious killer virus – rages with a prevalence rate of 1% among the peaceful population of Scalia. It spreads with a transmissibility rate of 40%. By prevalence rate, we mean that a certain portion of the population is infected to begin with. The transmissibility rate refers to the probability of one person to be infected.
In the beginning, 300 people are equally distributed among the rooms. Each step of the simulation corresponds to one simulated day. The disease and behaviour of people is simulated according to the following rules.
Rules
After each move (and also after the beginning of the simulation), a person moves to one of thei