Skip to content

Instantly share code, notes, and snippets.

@jchia
jchia / gist:40ee37ed760cca87babed902950051ed
Last active May 30, 2018 01:28
Copy from UArray to ByteString
import import Data.Array.Base
import Data.ByteString
import GHC.Prim
type Chunk = UArray Int Word8
-- Is there anything preventing byteArray from being relocated by the garbage collector after it's read but before it's used packCStringLen, so that packCStringLen uses an old, invalid, address?
chunkToBs :: Chunk -> ByteString
chunkToBs (UArray _ _ n byteArray) = unsafePerformIO $
data Foo = Foo { alpha :: Int, beta :: Int, gamma :: Int
, delta :: Int, eta :: Int } deriving (Eq, Ord, Show)
plusOn :: Num a => (Foo -> a) -> Foo -> Foo -> a
plusOn = on (+)
maxOn :: Ord a => (Foo -> a) -> Foo -> Foo -> a
maxOn = on max
newtype AddFoo = AddFoo { getAddFoo :: Foo }
instance Semigroup AddFoo where
#!/usr/bin/env python3
import numpy as np
import keras.layers as kl
import tensorflow as tf
class_count = 5
width, height = 100, 100
# Placeholders
179,646,281,792 bytes allocated in the heap
15,445,250,464 bytes copied during GC
2,808,589,128 bytes maximum residency (24 sample(s))
87,755,112 bytes maximum slop
7666 MB total memory in use (0 MB lost due to fragmentation)
Tot time (elapsed) Avg pause Max pause
Gen 0 170754 colls, 0 par 13.690s 16.086s 0.0001s 1.9563s
Gen 1 24 colls, 0 par 0.002s 0.003s 0.0001s 0.0016s
@jchia
jchia / gist:89910ccc922c57e43026532ff9758116
Last active January 31, 2019 02:42
Why is not a single input line processed? None of the traceM's got executed.
{-# LANGUAGE RecordWildCards, DuplicateRecordFields #-}
import ClassyPrelude hiding (try)
import Control.Monad.Except (MonadError, throwError)
import Control.Monad.State.Strict
import Control.Monad.Trans.Resource (ResourceT, runResourceT)
import Data.Conduit (ConduitM, runConduit, (.|))
import Data.Conduit.Combinators (sourceFile)
import qualified Data.Conduit.List as CL
import Data.Conduit.Lzma (decompress)
import qualified Data.Map as M
import XMonad
import XMonad.Config.Desktop (desktopConfig)
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import qualified XMonad.StackSet as W
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO
import System.Exit (exitSuccess)
import System.Taffybar
import System.Taffybar.Context (TaffybarConfig(..))
import System.Taffybar.Hooks
import System.Taffybar.SimpleConfig
import System.Taffybar.Widget
config :: TaffybarConfig
config =
let myWorkspacesConfig =
defaultWorkspacesConfig
--Works, but verbose:
let lineParser' = do
[email protected]{[email protected]{
[email protected]{sourceLine, sourceColumn}}} <- getParserState
let pstateSourcePos' :: MP.SourcePos
pstateSourcePos' = pstateSourcePos{sourceLine = mkPos lineNo, sourceColumn = mkPos 1}
setParserState parserState{statePosState=statePosState{pstateSourcePos=pstateSourcePos'}}
lineParser
data Config = Config { x :: Int, y :: Int }
defaultConfig :: Config
data Options' a = OptionsA { queue :: Text }
| OptionsB { config :: a, queue :: Text, a :: Text, b :: Maybe Int }
| OptionsC { config :: a, queue :: Text, c :: Int, d :: Word8 }
| OptionsD { config :: a, queue :: Text, c :: [Word8], d :: Bool }
using Options1 = Options' (Maybe Text)
using Options2 = Options' Config
data Session = Session { date :: Date, nightDay :: NightDay } deriving (Bounded, Eq, Generic, Ord)
instance Show Session where
show (Session date Night) = show date `snoc` 'n'
show (Session date Day) = show date
sessionParser :: (Stream a, Token a ~ Char) => Parsec () a Session
sessionParser = do
date <- dateParser
night <- optional (char 'n')