Skip to content

Instantly share code, notes, and snippets.

Niklas Hambüchen nh2

Block or report user

Report or block nh2

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nh2
nh2 / sharing-code-between-node-and-browser.txt
Created Jun 13, 2012
Sharing code between node and browser
View sharing-code-between-node-and-browser.txt
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 Jul 28, 2012
StaticPipeline in Java (not working)
View StaticPipeline.java
package staticpipeline;
class Image implements ProvidesOriginalImage {
@Override
public Image getOriginalImage() {
return null;
}
}
class FaceLocation implements ProvidesFaceLocation {
@nh2
nh2 / staticpipeline.hs
Created Jul 28, 2012
StaticPipeline in Haskell (one type class per in/out predicate)
View staticpipeline.hs
{-# 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 Aug 3, 2012
Hspec processes workaround
View hspec-processes.hs
{-# 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 Oct 16, 2012
Hopfield networks - minimal Haskell implementation
View Hopfield-mini.hs
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 Nov 23, 2012
Bytecode virtual machine + JIT compiler
View imps-emulator.c
/* 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 Nov 25, 2012
Haskell PCAP writing / dump (instance Storable PktHdr)
View haskell-pcap-writing.hs
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 Feb 23, 2013
GHC 7.4 wrong "qualified as" name
View ghc-7.4-wrong-qualified-as-name.hs
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 Dec 16, 2015
Angular scroll directive
View scrollDirective.coffee
# 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 Dec 17, 2015
Working with all past data types that ever existed using typed versions + type classes (Example)
View Past.hs
{-# LANGUAGE MultiParamTypeClasses #-}
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
-- | past: Compile-time checked backwards compatibility
-- Dealing with data types from the past, forever.
--
module Main where
You can’t perform that action at this time.