Skip to content

Instantly share code, notes, and snippets.

View kvanbere's full-sized avatar
:octocat:
We write and test real time control software. @cuedo

Kyle Van Berendonck kvanbere

:octocat:
We write and test real time control software. @cuedo
View GitHub Profile
data NXFile = NXFile
{ getNodeCount :: Int
, getNodeBlock :: Ptr ()
, getStringCount :: Int
, getStringBlock :: Ptr ()
, getBitmapCount :: Int
, getBitmapBlock :: Ptr ()
, getAudioCount :: Int
, getAudioBlock :: Ptr ()
}
@kvanbere
kvanbere / HsNx.hs
Created July 8, 2013 07:39
NX file format loader
{-# LANGUAGE OverloadedStrings, BangPatterns #-}
module Main (main) where
import Control.Applicative
import Control.Monad
import qualified Data.ByteString as BS
import qualified Data.Vector as V
import Data.Word
import Data.Maybe
@kvanbere
kvanbere / HsNx.hs
Last active December 19, 2015 11:19
The same program as earlier, except using hash tables rather than tries.
{-# LANGUAGE OverloadedStrings, BangPatterns #-}
module Main (main) where
import Control.Applicative
import Control.Monad
import Control.Monad.Loops
import qualified Data.ByteString as BS
import Data.Word
import System.IO.MMap
searchBench :: NXFile -> BS.ByteString -> NXNode -> IO ()
searchBench han str nod = do
(Just node) <- nxLookup han str
let name1 = getName node
info = getFileInfo han
fch = getFirstChildID node
cch = getChildrenCount node
cond = (>= fch + cch)
act x = do
node2 <- nxNodeFromID info x
@kvanbere
kvanbere / History.hs
Created July 15, 2013 01:21
WIP time/extended-tardis monad.
-- Todo: Improve laziness
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Monad.State
import Control.Monad.Identity
@kvanbere
kvanbere / Chrono.hs
Last active December 19, 2015 18:18
Chrono monad (Time via Keystone(s))
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE BangPatterns #-}
-----------------------------------------------------------------------------
-- |
-- Module : Control.Monad.Chrono
Kyle@kyle-laptop /c/Users/Kyle/Desktop$ ghc -fllvm -fforce-recomp test.hs
[1 of 1] Compiling Main ( test.hs, test.o )
C:\Users\Kyle\AppData\Local\Temp\ghc6708_0\ghc6708_0.s: Assembler messages:
C:\Users\Kyle\AppData\Local\Temp\ghc6708_0\ghc6708_0.s:2: Error: junk at end of line, first unrecognized character is `,'
C:\Users\Kyle\AppData\Local\Temp\ghc6708_0\ghc6708_0.s:3: Warning: .type pseudo-op used outside of .def/.endef ignored.
C:\Users\Kyle\AppData\Local\Temp\ghc6708_0\ghc6708_0.s:3: Error: junk at end of line, first unrecognized character is `s'
C:\Users\Kyle\AppData\Local\Temp\ghc6708_0\ghc6708_0.s:7: Warning: .size pseudo-op used outside of .def/.endef ignored.
C:\Users\Kyle\AppData\Local\Temp\ghc6708_0\ghc6708_0.s:7: Error: junk at end of line, first unrecognized character is `s'
C:\Users\Kyle\AppData\Local\Temp\ghc6708_0\ghc6708_0.s:10: Warning: .type pseudo-op used outside of .def/.endef ignored.
C:\Users\Kyle\AppData\Local\Temp\ghc6708_0\ghc6708_0.s:10: Error: junk at end of line, firs
@kvanbere
kvanbere / Serialize.hs
Last active December 21, 2015 18:48
Stream encoders/decoders
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE ScopedTypeVariables #-}
--------------------------------------------------------------------------------
-- |
-- Module : Burrito.Serialize
-- Copyright : (C) Burrito Development Team, 2013. All rights reserved.
-- License : MIT
--
-- Maintainer : Kyle Van Berendonck <[email protected]>
case x8 of {
True#
-> singleton [r1] [Nat r2] n;
False#
-> let x9 : Nat r2 = N# [r2] 1# in
let x10 : Nat r2 = addNat [r2] [r2] [r2] n x9 in
let x11 : List r1 (Nat r2) = enumFromTo [r1] [r2] x10 max in
Cons [r1] [Nat r2] n x11
};
@kvanbere
kvanbere / gist:6377808
Created August 29, 2013 13:04
The Haskell highlighting which comes with sublime text for Haskell is broken. This one works much better.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>hs</string>
</array>
<key>keyEquivalent</key>
<string>^~H</string>