Skip to content

Instantly share code, notes, and snippets.

View knutwalker's full-sized avatar
🦀

Paul Horn knutwalker

🦀
View GitHub Profile
@knutwalker
knutwalker / README.md
Last active April 19, 2023 16:17
Git commit graph to Neo4j

Installation

  • requires python 2.7 (maybe python 3.3+ will work too, didn't tested it)

Put git2neo.py somewhere in your $PATH and chmod +x it.

Usage

@knutwalker
knutwalker / FSM.scala
Last active April 3, 2022 13:51
Simple Encoding of a purely functional Finite State Machine using Scala and scalaz
package example.statemachine
import scalaz.{State, Scalaz}, Scalaz._
object FSM {
def apply[I, S](f: PartialFunction[(I, S), S]): FSM[I, S] =
new FSM((i, s) => f.applyOrElse((i, s), (_: (I, S)) => s))
private def states[S, O](xs: List[State[S, O]]): State[S, List[O]] =
xs.sequence[({type λ[α]=State[S, α]})#λ, O]
@knutwalker
knutwalker / imdb_to_trakt.py
Created October 14, 2012 03:29
Migrate movies from a public watchlist from IMDb into your private watchlist on trakt.
#!/usr/bin/env python
import csv
import collections
import re
import json
import requests
@knutwalker
knutwalker / FromMap.scala
Last active April 12, 2020 15:21
Converting Map[String,Any] to a case class using Shapeless - http://stackoverflow.com/q/31640565/2996265
/*
* Based on http://stackoverflow.com/a/31641779/2996265
*
* Changed:
* - use https://github.com/knutwalker/validation to accumulate errors
* - support lists as well (polymorphic on higher kinds would be better, though)
* - use -Xexperimental for java8 style SAM support
*/
@knutwalker
knutwalker / Main.hs
Created May 9, 2017 11:21
Play around with Haskell
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative ((<$>), (<*>))
import Control.Monad (mzero)
import Data.Aeson
import Data.Aeson.Types (emptyObject)
import qualified Data.ByteString.Lazy.Char8 as BL
@knutwalker
knutwalker / AbstractResource.java
Last active November 8, 2016 21:06
Jersey2 + Swagger with Resource inheritance
package com.example;
import com.wordnik.swagger.annotations.ApiParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@knutwalker
knutwalker / ga.js
Last active May 11, 2016 02:47
Variation of the Universal Analytics tracking Code (Google Analytics). It can only be safely included once since it overwrites itself. The original script does check against that. Also, document.scripts is not available in Firefox < 9
(function(G,O,o,g,l,e){G.GoogleAnalyticsObject=O;G[O]=function(){G[O].q.push(arguments)},G[O].q=[],G[O].l=+new Date;e=o.createElement('script'),l=o.scripts[0];e.src=g;l.parentNode.insertBefore(e,l)}(this,'ga',document,'//www.google-analytics.com/analytics.js'));
// ===>
ga('create', 'UA-XXXXXXX-Y');
ga('send', 'pageview');
λ> enumFromThenTo 3 9 50
[3,9,15,21,27,33,39,45]
it :: (Enum a, Num a) => [a]
λ> enumFromThenTo 'A' 'C' 'I'
"ACEGI"
it :: [Char]
λ> data Foo = A | B | C | D | E | F | G | H | I deriving (Enum,Show)
λ> enumFromThenTo A C I
sealed trait Thingy[+A] {
def bla(x: String): String
val bla2: String ⇒ String = bla
}
case class Good[A](x: A) extends Thingy[A] { def bla(x: String) = x }
case class Bad(t: String) extends Thingy[Nothing] { def bla(x: String) = t }
object Thingy {
def good1[A](x: A): Thingy[A] = Good(x)
package stackoverflow;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.*;
import org.apache.lucene.search.*;