Skip to content

Instantly share code, notes, and snippets.

View mroth23's full-sized avatar

Moritz Roth mroth23

  • Aschaffenburg, Germany
View GitHub Profile
//Linear interpolation of a 2D double array
private double[,] Interpolate(double[,] matrix, int dim)
{
double[,] result = new double[dim, dim];
double sf = (double)(matrix.GetLength(0) - 1) / (double)(dim - 1d);
for (int x = 0; x < dim; x++)
{
for (int y = 0; y < dim; y++)
{
def computeDifference(in: BufferedImage, compare: BufferedImage): BufferedImage = {
val w = in.getWidth
val h = in.getHeight
var result = new BufferedImage(w,h, BufferedImage.TYPE_INT_ARGB)
val graphics = result.getGraphics
graphics.setColor(java.awt.Color.BLACK)
graphics.clearRect(0,0,w,h)
for{
x : Int <- 0 until w
y : Int <- 0 until h
@mroth23
mroth23 / sql_conflicts.hs
Last active December 27, 2015 18:49
Analyses (SQL) transaction histories for possible conflicts.
import Control.Monad.State
import Prelude hiding (reads)
-- A list of dirty records, along with the transactions that wrote to them
-- Also contains a list of read records
data TransactionState = TransactionState
{ dirtyRecs :: [(Reg, Int)]
, reads :: [(Reg, Int)]
, dirtyCommits :: [Int]
, dirtyReads :: [Int]
@mroth23
mroth23 / relaxation_labelling.hs
Created November 23, 2013 16:54
Relaxation labelling script for a simple case with two labels {Edge, NonEdge}. Compatibility function is provided as a Haskell function (nice!), as well as the initial matrix. Uses [[Double]], so this is slow. Using something like traverse and Repa (or any other fast array library) would make this code a lot faster. So just avoid excessive (500+…
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
import Control.Monad
{-
USAGE:
use the functions directly (if you know what you're doing),
or simply use the provided showStep function to get the matrix
after a certain number of relaxation iterations.
@mroth23
mroth23 / enigma.hs
Last active December 30, 2015 15:19
(Re-upload of a private Gist) An enigma machine written in Haskell. Uses some weird IO code because of file dependencies (for the rotors and machine specification).
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Char
import Data.List
import Data.Maybe
import Data.IORef
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Generic.Mutable as MV
import Control.Monad
import System.Exit
import System.IO
@mroth23
mroth23 / dataAnalyser.hs
Last active August 29, 2015 13:56
ACA data analyser
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
-- Needs bytestring-lexing installed to work!
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lex.Double as B
import qualified Data.ByteString.Lex.Integral as B
import Data.Maybe
import Data.List
@mroth23
mroth23 / gitstat.hs
Last active August 29, 2015 14:15
gitstat.hs
{-
Updated to latest version - fixing a bug I didn't notice before with merge commit or binary file lines.
This tool parses a git history into a Haskell data type.
The history can then be further analysed using the ghci command line (all important
metrics are known / saved: commit hash, author, files it modifies and size of contributions).
I also added an example that prints a graphviz representation of the commit / file graph.
-}
import Text.Parsec
import Text.Parsec.Combinator
export WORKON_HOME=~/Envs
source /usr/local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3