Skip to content

Instantly share code, notes, and snippets.

@ownclo
ownclo / packHuffmanTree.hs
Created December 4, 2013 13:41
Reproducing a bug in 'packHuffmanTree'
import qualified Data.ByteString as B
import Control.Monad.ST( runST )
import Codec.Picture.Jpg.DefaultTable
import Codec.Picture.BitWriter
import Data.Word(Word8)
import Control.Monad(forM_)
goodTree :: HuffmanTree
goodTree = Branch (Leaf 1) (Branch (Leaf 2) (Leaf 3))
diff --git a/Codec/Picture/Jpg/DefaultTable.hs b/Codec/Picture/Jpg/DefaultTable.hs
index d1ff914..4582ecd 100644
--- a/Codec/Picture/Jpg/DefaultTable.hs
+++ b/Codec/Picture/Jpg/DefaultTable.hs
@@ -75,7 +75,7 @@ packHuffmanTree tree = runST $ do
aux (Branch i1 i2@(Leaf _)) idx = do
ix1 <- aux i1 (idx + 2)
_ <- aux i2 (idx + 1)
- (table `M.unsafeWrite` idx) (fromIntegral ix1)
+ (table `M.unsafeWrite` idx) (fromIntegral $ idx + 2)
{-# LANGUAGE ExistentialQuantification #-}
import Control.Applicative
import qualified Data.Vector as V
data Tree a = Node (V.Vector (Tree a))
| Leaf a
deriving Show
class Switchable c where
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- import Data.Monoid
-- The associativity order does not matter,
-- emphasizing it by omitting parantheses.
infixr 5 :&
type a :& b = (a,b)
@ownclo
ownclo / a_little_better_sort.hs
Created February 2, 2014 22:44
slightly better (?) sort?
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Int
import Data.Maybe
import qualified Data.ByteString.Lazy.Char8 as BS
-- ------------------------------------------------
data TEventType = Start | Finish -- XXX: Start < Finish
@ownclo
ownclo / arqs.py
Created May 21, 2014 21:58
GBN and Selective Repeat ARQs simulations.
import random
from collections import deque
class GBNSender:
def __init__(self):
self.to_send_idx = 0
self.transmitted = 0
def get_msg(self):
msg = {'idx': self.to_send_idx}
@ownclo
ownclo / IterNW.hs
Last active August 29, 2015 14:06 — forked from anonymous/IterNW.hs
{-# LANGUAGE
GADTs
, FlexibleContexts
, RankNTypes
, ScopedTypeVariables #-}
import Data.Word
import Data.List( find, sortBy )
import Data.Maybe( fromJust )

General estimates

(assuming that you already have a residence permit card)

TIME

(from the day when you have your residence permit)

  • ~2-3 weeks to get a Chalmers student union card
  • ~2-3 weeks to receive personnummer