Skip to content

Instantly share code, notes, and snippets.

View nh2's full-sized avatar

Niklas Hambüchen nh2

View GitHub Profile
@nh2
nh2 / sharing-code-between-node-and-browser.txt
Created June 13, 2012 14:16
Sharing code between node and browser
Sharing code between node and browser
=====================================
This is incredibly messy.
Using require.js + r.js + amdefine
----------------------------------
* Cannot use cs.js for "cs!module" coffee imports
@nh2
nh2 / StaticPipeline.java
Created July 28, 2012 23:32
StaticPipeline in Java (not working)
package staticpipeline;
class Image implements ProvidesOriginalImage {
@Override
public Image getOriginalImage() {
return null;
}
}
class FaceLocation implements ProvidesFaceLocation {
@nh2
nh2 / staticpipeline.hs
Created July 28, 2012 23:46
StaticPipeline in Haskell (one type class per in/out predicate)
{-# LANGUAGE NoMonomorphismRestriction #-}
module StaticPipeline where
data Image = Image
data OriginalImage = OriginalImage Image
data ProcessedImage = ProcessedImage Image
data FaceLocation = FaceLocation
data EyeLocation = EyeLocation
@nh2
nh2 / hspec-processes.hs
Created August 3, 2012 04:30
Hspec processes workaround
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleInstances #-}
module Main where
import Test.Hspec
import qualified Test.Hspec.Core as Core
import qualified Test.Hspec.Internal as Internal
@nh2
nh2 / Hopfield-mini.hs
Created October 16, 2012 05:36
Hopfield networks - minimal Haskell implementation
import Data.Vector ((!))
import qualified Data.Vector as V
import Data.Vector.Generic.Mutable (write)
step ws state = case updatable of [] -> state
(i,_):_ -> V.modify (\v -> write v i (o i)) state
where
n = V.length state
w i j = ws ! i ! j
@nh2
nh2 / imps-emulator.c
Created November 23, 2012 02:20
Bytecode virtual machine + JIT compiler
/* COMPILATION NOTE
* This has to be compiled with `gcc -z execstack` to allow jumping
* into the stack (which is where the JIT generated code is stored
* in `jit_area`).
*/
// TODO "i" is a bad variable name
#include <stdio.h>
#include <stdlib.h>
@nh2
nh2 / haskell-pcap-writing.hs
Created November 25, 2012 22:56
Haskell PCAP writing / dump (instance Storable PktHdr)
module PktHdrStorableInstance where
import Foreign.Marshal.Utils (with)
import Foreign.Ptr (plusPtr)
import Foreign.Storable
import Network.Pcap
import Network.Pcap.Base (toPktHdr)
#include <pcap.h>
@nh2
nh2 / ghc-7.4-wrong-qualified-as-name.hs
Created February 23, 2013 01:58
GHC 7.4 wrong "qualified as" name
import qualified Data.Vector as V
import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Unboxed as U
main = do
_k <- VS.convert (undefined :: U.Vector) :: VS.Vector
return ()
@nh2
nh2 / scrollDirective.coffee
Last active December 16, 2015 21:39
Angular scroll directive
# Updates a variable when the window scrollTop position is changed.
# Usage:
# <set-window-scroll set-variable="windowScroll"></set-window-scroll>
app.directive "setWindowScroll", ->
restrict: "E"
scope:
setVariable: "="
link: (scope) ->
$(window).scroll ->
@nh2
nh2 / Past.hs
Last active December 17, 2015 00:39
Working with all past data types that ever existed using typed versions + type classes (Example)
{-# LANGUAGE MultiParamTypeClasses #-}
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
-- | past: Compile-time checked backwards compatibility
-- Dealing with data types from the past, forever.
--
module Main where