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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@chrisdone
chrisdone / Bits.hs
Created February 3, 2016 16:50
Pattern matching bits
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE PatternSynonyms #-}
-- | Demonstration of pattern matching on bits in a byte.
module X where
import Data.Bits
pattern Byte a b c d <- (byte -> (ByteBits a b c d))
(defun org-clock-timesheet ()
"Make a timesheet that can be copy/pasted into a spreadsheet of
DAY OF MONTH | CONTRACTOR NAME | DESCRIPTION OF WORK | HOURS
"
(interactive)
(let ((items (org-clock-collect-items))
(requested-month (read-from-minibuffer "Month: " (format-time-string "%Y/%m"))))
(with-output-to-temp-buffer "timesheet"
(let ((hash (make-hash-table :test 'equal)))
@chrisdone
chrisdone / gist:cca98745c2ab5d84e35a
Created February 17, 2016 12:29
org-clock-timesheet.el
(defun org-clock-timesheet ()
"Make a timesheet that can be copy/pasted into a spreadsheet of
DAY OF MONTH | CONTRACTOR NAME | DESCRIPTION OF WORK | HOURS
"
(interactive)
(let ((items (org-clock-collect-items))
(requested-month (read-from-minibuffer "Month: " (format-time-string "%Y/%m"))))
(with-output-to-temp-buffer "timesheet"
(let ((hash (make-hash-table :test 'equal)))
@chrisdone
chrisdone / org-clock-timesheet.el
Created February 17, 2016 12:30
Generate a timesheet tab-separated-list from all TODO items in the current buffer
(defun org-clock-timesheet ()
"Make a timesheet that can be copy/pasted into a spreadsheet of
DAY OF MONTH | CONTRACTOR NAME | DESCRIPTION OF WORK | HOURS
"
(interactive)
(let ((items (org-clock-collect-items))
(requested-month (read-from-minibuffer "Month: " (format-time-string "%Y/%m"))))
(with-output-to-temp-buffer "timesheet"
(let ((hash (make-hash-table :test 'equal)))
{-# LANGUAGE OverloadedStrings #-}
-- |
module Data.Attoparsec.Text.Helpful
(parseHelpfully)
where
import Data.Attoparsec.Text (Parser)
import qualified Data.Attoparsec.Text as P
import Data.List
@chrisdone
chrisdone / Dev.hs
Last active March 15, 2016 11:00
Criterion.Dev
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
-- | Enable --dev flag for Criterion.
module Criterion.Dev where
import Control.Exception
import Data.Function
@chrisdone
chrisdone / TH.hs
Created March 18, 2016 13:29
Foreign.Storable.TH
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
-- |
module Foreign.Storable.TH where
import Foreign.Storable
import Foreign.Ptr
import Language.Haskell.TH
@chrisdone
chrisdone / Apple.md
Last active March 1, 2025 02:14
Apple

Sample types:

isDigit :: Monad f => Char -> f Bool
any :: Monad f => (a -> f Bool) -> [a] -> f Bool
reverse :: Monad f => [a] -> f [a]
map :: Monad f => (a -> f b) -> [a] -> f [b]
"hello" :: Monad f => f String
putStrLn :: (MonadIO f) => String -> f ()
show :: (Show a,Monad f) => a -> f String
{-# LANGUAGE FlexibleContexts #-}
-- | A section: Parser and printer.
-- See <https://en.wikipedia.org/wiki/Section_(category_theory)>
--
-- It's like an isomorphism, except one side is not a complete mapping
-- i.e. the parsing side, but the printing side is complete (anything
-- that is printed can be parsed).
module Yesod.Form.FieldSection where