Skip to content

Instantly share code, notes, and snippets.

@pbrisbin
pbrisbin / hdocs
Created March 15, 2014 20:25
Browse local haskell documentation (requires documentation: True in cabal/config)
#!/bin/sh
if [ -z "$1" ]; then
printf "usage: hdocs <identifier>\n"
exit 64
fi
package="$(printf "%s" "$*" | sed 's/[ .]/-/g; s/.*/\L&/g')"
package_glob="*/$package-*/html/index.html"
if [ -e "$PWD/.cabal-sandbox" ]; then
### Keybase proof
I hereby claim:
* I am pbrisbin on github.
* I am pbrisbin (https://keybase.io/pbrisbin) on keybase.
* I have a public key whose fingerprint is 7A4F 38C2 01F4 3F11 1C95 A9E5 7548 1C55 CEC8 925D
To claim this, I am signing this object:
@pbrisbin
pbrisbin / lsrc.hs
Last active August 29, 2015 13:57
Monads!
module Main where
import Control.Monad.State
import Data.List
data Dotfile = Dotfile
{ dfSource :: FilePath
, dfPath :: FilePath
, dfTag :: Maybe String
, dfHost :: Maybe String
instance Aeson.FromJSON User where
parseJSON (Object u) = User
<$> fmap read (u .: "id")
<*> u .: "username"
<*> u .: "full_name"
<*> u .: "bio"
<*> u .: "profile_picture"
@pbrisbin
pbrisbin / dfa.hs
Created April 6, 2014 03:17
Exploring some DFA-based Regex ideas in Haskell
module DFA where
import Control.Monad.State
type DFAState = Int
data Rule = Rule
{ fromState :: DFAState
, inputChars :: [Char]
, nextStates :: [DFAState]
@pbrisbin
pbrisbin / lock.sh
Created April 9, 2014 13:51
Set yourself away in IRC before locking your screen
#!/bin/sh
#
# Uses xdotool and slock.
#
# Note: relies on your client being in a terminal with the title/name "chat", e.g.
#
# $ urxvtc -title chat -n chat -e weechat-curses
#
###
set_away() {
@pbrisbin
pbrisbin / xdg-send.sh
Last active August 29, 2015 14:00
Seamlessly open graphical files locally from a remote server
#!/bin/sh
#
# Usage: xdg-send ./some_file.pdf
#
# Requirements on Local,
#
# - Running sshd on port 2222
# - ssh -R 2222:localhost:2222 remote.com
#
# Requirements on Remote,
@pbrisbin
pbrisbin / a-steps.md
Last active August 29, 2015 14:01
JSON value mismatch in Yesod testing

Steps

% mkdir example && cd example && yesod init --bare
name: Example
type: simple
% curl "https://gist.githubusercontent.com/pbrisbin/448f31288d1ebb4435d6/raw/e49cd961eee825ec35a5332472b210d1b0bbfce1/b-patch.diff" | patch
% yesod test
-- Within an implementation of the TODO app from LYAH, there was something like
-- this...
data Todo = Todo
newtype Add = Add (Either String Todo)
newtype Remove = Remove (Either String ())
newtype Complete = Complete (Either String Todo)
class Respond a where
@pbrisbin
pbrisbin / validations.hs
Last active August 29, 2015 14:02
Generic, model-level validations for Haskell
import Data.Monoid
-- A validated record is either errors or it
type Validated a = Either [String] a
-- A validation is the process of taking a record and returning a validated one
newtype Validation a = Validation { runValidation :: (a -> Validated a) }
-- Validation processes are composable as monoids
instance Monoid (Validation a) where