Skip to content

Instantly share code, notes, and snippets.

View qnikst's full-sized avatar
🐧
penguin?

Alexander Vershilov qnikst

🐧
penguin?
View GitHub Profile
@qnikst
qnikst / DeriveADT.hs
Created June 8, 2012 15:19 — forked from pxqr/gist:2893200
Question: Deriving boilerplate matching function.
{-# LANGUAGE TemplateHaskell #-}
module DeriveADT
( deriveExtract
, deriveIs
) where
import Data.Maybe
import Data.Char
import Language.Haskell.TH
--
-- xmonad example config file.
--
-- A template showing all available configuration hooks,
-- and how to override the defaults in your own xmonad.hs conf file.
--
-- Normally, you'd only override those defaults you care about.
--
import System.Exit
import System.IO
@qnikst
qnikst / gist:3397193
Created August 19, 2012 19:33
how to make a function that is based on it's return type
-- | how to make a function that is based on its return type?
class (Storable a) => P a where
data Ps a
pStorageType :: [a] -> StorageType
wP :: [a] -> (Ptr a -> IO b) -> IO b
wP xs f = V.unsafeWith (V.fromList xs) f
export:: (MonadIO m, Pixel a) => PMagickWand -> Int -> m [a]
exportImagePixels len = exportArray len ffiFunction undefined
@qnikst
qnikst / magick.hs
Created August 28, 2012 17:47 — forked from Shimuuar/gist:3501111
Do magik
import Data.Default
import Debug.Trace
class Magick a where
magickStorage :: [a] -> String
instance Magick Int where
magickStorage = const "Int"
instance Magick Char where
{-# LANGUAGE OverloadedStrings, FlexibleContexts, RankNTypes, KindSignatures #-}
module Main
where
import Prelude hiding (FilePath)
import Data.ByteString as S
import Data.ByteString.Lazy as SL
import Data.ByteString.Lazy.Char8 as SL8
@qnikst
qnikst / gist:4213380
Created December 5, 2012 07:20
Zeromq template?
I have a distributed network that consists of a equal nodes.
I have 2 types of messages:
Events:
Each node can send a stream of events corresponding to concrete "structure"
All nodes can subscribe to events for list of "structures"
Commands:
Each node can send a commands to concrete node.
Responses to commands should be asynchronous.
@qnikst
qnikst / mouse.hs
Last active December 12, 2015 08:29
http://haskell98.blogspot.ru/2013/02/2013.html nub можно убрать использовав Data.Set, но на малых размерах N^2 не проблема. solN можно тоже переписать так, чтобы не проводилить двойные вычисления, но мне лень :)
import Data.Function
import Data.List
import Control.Monad
import Debug.Trace
import Data.Set (Set)
import qualified Data.Set as S
type History = [Int]
type Mouse = Int
type Size = Int
@qnikst
qnikst / test.hs
Last active December 15, 2015 10:09
./124 -o out.html -g картинка тут: http://postimg.org/image/wyxmmdo5v/
-- картинка http://postimg.org/image/wyxmmdo5v/
import Data.List
import Data.DList (singleton, fromList, snoc, empty, toList)
import Control.Monad.Trans.Writer.Lazy
import Criterion.Main
import Data.Maybe
zipMore :: [a] -> [b] -> ([(a,b)],[a],[b])
zipMore [] xs = ([],[],xs)
zipMore xs [] = ([],xs,[])
@qnikst
qnikst / gist:5285242
Last active December 15, 2015 15:58 — forked from voidlizard/gist:5285196
{-# LANGUAGE BangPatterns #-}
module Main where
import qualified Data.ByteString as BS
import System.IO
import Control.Monad
import Data.Bits
import Data.Word
import Data.Monoid
import Network.Openflow.StrictPut
@qnikst
qnikst / vector.hs
Created April 20, 2013 06:16
not fully correct crc16 implementation
-- Vector:
icsum16 :: Word32 -> V.Vector Word16 -> Word32
icsum16 !i bv = V.foldl' (\a -> (+a).fromIntegral) i bv
{-# INLINE icsum16 #-}
icsum16 :: Word32 -> Vector Word16 -> Word32
icsum16 =
\ (eta :: Word32) (eta1 :: Vector Word16) ->
let { Vector ipv ipv1 ipv2 ~ _ <- eta1 } in