Skip to content

Instantly share code, notes, and snippets.

@imalsogreg
imalsogreg / gist:8332cf1ee11d69568b25
Created June 4, 2014 13:38
Heist.SpliceAPI - try to break duplicate detection (in this case, duplicate IS detected)
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Heist.SpliceAPI
main :: IO ()
main = print $ runSplices baz
foo = do
@imalsogreg
imalsogreg / Try 2
Created June 4, 2014 14:20
SpliceAPI
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Heist.SpliceAPI
main :: IO ()
main = print $ runSplices baz
foo = do
@imalsogreg
imalsogreg / mapK amnesia
Created June 4, 2014 19:15
map-syntax testing
module Main where
import qualified Data.Map as M
import Data.Map.Syntax
-- prints: Right (fromList [("blobz",10),("smootz",12)])
main = print . runMapSyntax M.lookup M.insert $ do
foo
mapK (++ "a") bar
@imalsogreg
imalsogreg / ReddisSession.hs
Created July 10, 2014 15:19
Control.Error reduce nested cases
instance ISessionManager RedisSessionManager where
--------------------------------------------------------------------------
--load grabs the session from redis.
load mgr@(RedisSessionManager (Just _) _ _ _ _ _ ) = return mgr
load mgr@(RedisSessionManager _ _ _ _ rng con) = do
res <- runMaybeT $ do
(Payload x) <- MaybeT $ getPayload mgr
cs <- hoistMaybe . hush $ S.decode x
liftIO $ runRedis con $ do
------------------------------------------------------------------------------
readRequestBodyHangIssue :: Test
readRequestBodyHangIssue =
testCase "readRequestBody doesn't hang" assertReadRqBody
where
assertReadRqBody =
do let hdl = readRequestBody 5000 >>= writeLBS
res <- race
(threadDelay 1000000)
(runHandler Nothing (ST.get "" Map.empty) hdl appInit)
cabal sandbox add-source ../io-streams
cabal sandbox add-source ../io-streams-haproxy
cabal sandbox add-source ../map-syntax
cabal sandbox add-source ../snap-server
cabal sandbox add-source ../snap-core
cabal sandbox add-source ../xmlhtml
cabal sandbox add-source ../snap-loader-static
cabal sandbox add-source ../snap-loader-dynamic
cabal sandbox add-source ../heist
@imalsogreg
imalsogreg / Main.hs
Last active August 29, 2015 14:04
Tape winding
module Main where
import Data.List
import Codec.Picture
import qualified Data.Vector as V
r0 = 50 -- Core thickness
rEnd = 200 -- Tape role end thickness (no effect?)
thick = 1 -- Thickness of one sheet of tape
@imalsogreg
imalsogreg / Test.hs
Created September 4, 2014 18:20
Simple demo UDP server and client
module Main where
import Control.Applicative
import Control.Concurrent
import Control.Error
import Control.Monad
import Control.Monad.Trans (lift)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL
import qualified Data.Binary.Get as B
@imalsogreg
imalsogreg / changelogs.md
Last active August 29, 2015 14:14
Survey of changelogs on hackage

Authoritative sources

Source Notes
Wikipedia entry
  • Custom format from GNU
  • Date (YYYY-MM-DD), name, email per entry
Keep a changelog
  • Use markdown
  • Emphasis on human readability
  • Attempt at modern standard
  • Never dump git logs there
  • Subsections tagged by [VERSION]
  • Top version always [UNRELEASED]
  • Many more tips at their site

Examples from hackage

| Package | Notes |

@imalsogreg
imalsogreg / pointers.md
Last active August 29, 2015 14:14
Pointers for mom

Pointers

Some background things to keep in mind:

  • A variable is the combination of a name and a location in memory.
  • Initializing a variable tells C what the variable's type is, and sets aside some space for the variable's value
  • Then, using the variable causes C to look into that variable's memory address.
  • Assigning value to a variable means looking up the address and copying bites there
  • Reading a variable means looking up the memory address, reading the bytes, and using the variable's types to interpret the bytes (without the type, there'd be no way to know how to interpret the bytes)
  • Types give values meaning. The meaning of a char is "a single character". This meaning isn't necessarily part of the language. Instead it's for you to have a mental model of what the program does.