Skip to content

Instantly share code, notes, and snippets.

View trygvea's full-sized avatar

Trygve Matland Amundsen trygvea

View GitHub Profile
// 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)
}
(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'
<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>
@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+")"
}
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)
(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
UTF-8: æøåÆØÅ
ISO-8859-1: ʯÂ∆ÿ≈
MacRoman: æøåÆØÅ
I korthet:
* non-UTF-8 aapnet i UTF8 gir svarte spoersmaalstegn
* non-ISO aaapnet i ISO: UTF8: diverse A-tegn, MacRoman: 3/4 (R) E etc
* non-Mac aapnet i Mac: UTF-8: Kvadratrot, ISO: E, delta Y mattesymboler
// Tested in groovy 2.4.3
import groovy.transform.TypeChecked
@TypeChecked
interface F1<A, B> { // Function1
abstract B f(A a);
}
@TypeChecked
interface Functor<T, A> { // Egentlig Functor<T<A>> men det går ikke i java/groovy
abstract <A,B> T<B> map(F1<A, B> f)
package shapeless.examples
import shapeless._
import poly._
import labelled._
sealed trait Message
case class Ping(id: Long, sender: String) extends Message
case class Pong(id: Long, receiver: String) extends Message
@trygvea
trygvea / gist:a35999de8ee0ee14bcc5
Created December 15, 2015 08:44
Some groovy/java utilities for HBase shell. Note that IntelliJ has groovy console built-in!
import java.nio.ByteBuffer
public static byte[] bytes(long l) {
ByteBuffer.allocate(Long.BYTES).putLong(l).array();
}
def pretty(byte[] b) {
def sb = new StringBuilder()
for(i=0;i<b.length;i++){
sb.append(String.format("\\x%02X", b[i]))