Skip to content

Instantly share code, notes, and snippets.

@LeifW
LeifW / 2logback.pxsl
Created May 15, 2012 20:58
log4j to logback converter
#!/usr/local/bin/#pxsl
stylesheet -version=1.0 -xmlns:xsl=http://www.w3.org/1999/XSL/Transform -xmlns:log4j=http://jakarta.apache.org/log4j/ -exclude-result-prefixes=log4j
output -indent=yes
template log4j:configuration
configuration
apply-templates
template logger
logger -name={@name} -level={level/@value}
@LeifW
LeifW / opensaml.PKGBUILD
Created May 18, 2012 05:50
xmltooling pkgbuild
pkgname='opensaml'
pkgver='2.4.3'
pkgrel='1'
pkgdesc='Security Assertion Markup Language (SAML)'
arch=('i686' 'x86_64')
url='http://shibboleth.net/downloads/c++-opensaml/'
license=('APACHE')
depends=('openssl' 'curl' 'log4shib'
'xmltooling' 'xerces-c' 'xml-security-c')
/bin/sh ../../libtool --tag=CC --mode=link gcc -std=gnu99 -fno-strict-aliasing -Wall -g -O2 -I./ -I../ -DGIT_REV="\"v1.1.4-231-g27f1ed5\"" -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/raptor2 -I/usr/include/rasqal -I/usr/include/raptor2 -I/usr/include/libxml2 `pcre-config --cflags` -march=native -mtune=native -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -Wl,-O1,--sort-common,-z,relro -o 4s-query 4s-query.o query.o results.o query-data.o query-datatypes.o query-cache.o filter.o filter-datatypes.o order.o group.o optimiser.o decimal.o ../common/lib4sintl.a ../common/libsort.a ../libs/mt19937-64/libmt64.a -lm -lraptor2 -lrasqal -lraptor2 -lavahi-glib -lglib-2.0 -lavahi-common -lavahi-client -lncurses -lreadline -lglib-2.0 `pcre-config --libs`
libtool: link: gcc -std=gnu99 -fno-strict-aliasing -Wall -g -O2 -I./ -I../ -DGIT_REV=\"v1.1.4-231-g27f1ed5\" -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/raptor2 -I/usr/include/
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by 4store configure v1.1.4-236-g340aa14, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ ./configure --prefix=/usr
## --------- ##
## Platform. ##
@LeifW
LeifW / Foo.scala
Created August 13, 2012 10:31
overloaded method WTF
object Foo {
def f(numbers: Int*)(n1:String) = numbers.sum
def f(numbers: Int*)(n1:String, n2: String) = numbers.sum
def f(numbers: Int*)(n1:String, n2: String, n3:String) = numbers.sum
}
scala> Foo.f(1,2,3)("n")
<console>:8: error: ambiguous reference to overloaded definition,
both method f in object Foo of type (numbers: Int*)(name: String, n2: String, n3: String)Int
@LeifW
LeifW / amazon_sheikh_time.hs
Created October 17, 2012 19:09
Add up all the track times on the list.
time ("MP3" : _ : _ : t : _) = t
time ("Only" : _ : t : _) = t
toSeconds s = case span (≠ ':') s of
(h, m) → 60 * read h + (read (tail m))
main = do
f ← fmap lines $ readFile "foo.txt"
let total = sum $ map (toSeconds ∘ time ∘ reverse ∘ words) $ filter (=~ "[[:digit:]]") $ map snd $ filter (odd ∘ fst) $ zip [1..] f
print total
@LeifW
LeifW / gist:4315293
Created December 17, 2012 02:07
by-name vs by-value
module Main
import Debug.Trace
foo : (x: Int) -> String
foo x = show (x + 10) ++ show x
five : Int
five = trace "evaling" 5
@LeifW
LeifW / schemaScaffold.hs
Created December 20, 2012 22:47
html generation
individual ∷ Subject → [Element]
individual (Subject name dataProps objectProps) =
[
unode "div" [
unode "p" [
unode "b" (l ⧺ ":"),
unode "span" [property p, datatype t]
]
| (p, l, t) ← dataProps ],
unode "div" [
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (readFile, writeFile)
import qualified Data.Text as T
import Data.Text (Text)
import Data.Text.Lazy.IO (readFile, writeFile)
import qualified Data.Text.Lazy as LT
import Data.Map (Map)
import qualified Data.Map as Map
import Data.List (sortBy, groupBy, foldl', foldl1')
import Data.Maybe (catMaybes)
@LeifW
LeifW / VN.scala
Created February 11, 2013 22:05
homogeneous tuples
def makeInstances(size: Int) = 1 to size map (n=>
s"""
implicit def V${n}Functor: Functor[V$n] = new Functor[V$n] {
def map[A, B](r: V$n[A])(f: A => B) = V$n(${1 to n map ("f(r.a"+_+")") mkString ", "})
}
""") mkString
def makeClasses(size: Int) = 1 to size map (n=>
s"""
case class V$n[A](${1 to n map ("a"+_+": A") mkString ", "}) {