Skip to content

Instantly share code, notes, and snippets.

val tens = Map (
'2' -> "Twenty",
'3' -> "Thirty",
'4' -> "Fourty",
'5' -> "Fifty",
'6' -> "Sixty",
'7' -> "Seventy",
'8' -> "Eighty",
'9' -> "Ninety"
) withDefaultValue("")
@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
@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 / if_statement_without_space.py
Last active December 12, 2015 03:49
Git hook written in python. I had a habit of leaving 'if' statement without following space which really annoyed my collegues. So I've written git hook which checks if there is some nasty ifs, and if so, it will reject commit until I fix an issues.
#!/usr/bin/python
import os
import sys
import re
import subprocess
devnull = open(os.devnull, 'w')
@lazyval
lazyval / .gitignore
Last active December 12, 2015 03:38
SML sandbox. I place here most of the stuff, I've done during coursera course. If you don't like **SPOILERS**, please, move along, don't look inside.
.DS_STORE
@lazyval
lazyval / example.java
Created January 29, 2013 20:24
An example, I've written to show some **very** basic swing constructs to my classmate
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionEvent;
public class Foo {
static final JFrame MainWindow = new JFrame();
static final JPanel content = new JPanel(new BorderLayout());
static final JLabel resultFromDialog = new JLabel("SomeText");
@lazyval
lazyval / assignment.scala
Created November 24, 2012 18:06
Remove the words where last character is a capital letter from a given sentence and then reverse the characters of each word
"FooO bar baZ bow".split(" ").filter(word => word.last >= 'a').map(_.reverse)
@lazyval
lazyval / gist:4082827
Created November 16, 2012 00:40 — forked from saetia/gist:1623487
Clean Install – Mountain Lion OS X 10.8
@lazyval
lazyval / list.scala
Created October 19, 2012 16:35
Compile time list
trait Base {
protected def contribute : List[String] = List("Beginning")
val list = contribute.reverse
}
trait TrA extends Base {
override protected def contribute = "A" :: super.contribute
}
trait TrB extends TrA {
@lazyval
lazyval / brackets.scala
Created October 3, 2012 17:53
bracket balanicing
object Main extends App {
println(isBalanced("(.)(.)".toList))
def isBalanced(list: List[Char]) = {
@annotation.tailrec
def countBracets(string: List[Char], count: Int = 0): Int = {
string match {
case '('::tail => countBracets(tail, count+1)
case ')'::tail => countBracets(tail, count-1)