Skip to content

Instantly share code, notes, and snippets.

View trygvea's full-sized avatar

Trygve Matland Amundsen trygvea

View GitHub Profile
(defn normalize
"Transforms a tabular form to a normalised hierarchical form."
([kw values-kw coll]
(normalize kw values-kw [] coll))
([kw values-kw promoted-keys coll]
(normalize kw values-kw promoted-keys identity coll))
([kw values-kw promoted-keys f coll]
(map
(fn [[k v]]
(merge {kw k
def Y = { le -> ({ f -> f(f) })({ f -> le { x -> f(f)(x) } }) }
def factorial = Y { fac ->
{ n -> n <= 2 ? n : n * fac(n - 1) }
}
assert 2432902008176640000 == factorial(20G)
@trygvea
trygvea / stringsWithIdenticalHashcode.groovy
Last active December 14, 2015 19:29
Simple strings with identical hashcode
def alphabet = ('A'..'Z')+ ['Æ','Ø','Å']
def combinations = [:]
alphabet.each { first ->
alphabet.each { second ->
alphabet.each { third ->
def str = "" + first + second + third
def hash = str.hashCode()
if (combinations[hash]) {
println combinations[hash]+" has same hashcode as "+str+"!!!!!! ("+hash+")"
}
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<link rel="stylesheet" href="ullami.css" type="text/css">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="ullami.js"></script>
</head>
<body>
(function ($) {
jQuery.noConflict();
var sheepImage = new google.maps.MarkerImage('sau.png',
new google.maps.Size(37, 25), // marker size
new google.maps.Point(0,0), // origin
new google.maps.Point(18, 12)); // anchor is the middle of the image
var shape = {
coord: [1, 1, 1, 37, 25, 37, 25 , 1],
type: 'poly'
// Konverter tekst: Tirsdag, ukenr 49, år 2006
// til dato
Date gjettSlakteDato(String tekst, Date compareToDate) {
def ukedag = ["Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag", "Søndag"]
def split = tekst.split(",")
String d = ukedag.findIndexOf {it == split[0]} + 1
String ww = split[1][-2..-1]
String y = split[2][-1]
return convertDateFormat(y+ww+d, compareToDate)
}