Skip to content

Instantly share code, notes, and snippets.

Doesn't GitHub render smart quotes?

@pbrisbin
pbrisbin / img2s3.sh
Created December 31, 2014 15:19
Find image links in markdown sources, put to S3 and update the link
#!/bin/sh
#
# pbrisbin 2015 - look for markdown links to local images, move them to S3 then
# update the markdown to link to it.
#
# Things to tweak:
#
# - Processes posts/*.md
# - Looks for "/img/image.ext"
# - Puts img/image.ext to s3://$bucket/$(prefix $post)image.ext
@pbrisbin
pbrisbin / either.hs
Created December 19, 2014 17:11
Alternative Either <*> definition
module Test where
import Control.Applicative
data EitherX a b = LeftX a | RightX b deriving (Eq, Show)
instance Functor (EitherX a) where
fmap f (RightX x) = RightX $ f x
fmap _ (LeftX e) = LeftX e
@pbrisbin
pbrisbin / headache.md
Created October 27, 2014 18:55
ZSH startup file headaches

Default behavior dictates the following order for ZSH startup files:

  • /etc/zshenv
  • ~/.zshenv
  • /etc/zprofile (if login shell)
  • ~/.zprofile (if login shell)
  • /etc/zshrc (if interactive)
  • ~/.zshrc (if interactive)
  • /etc/zlogin (if login shell)
  • ~/.zlogin (if login shell)
@pbrisbin
pbrisbin / redis.sh
Created October 20, 2014 14:34
Redis cheat-sheet (gist mirror of something on pastebin.com)
# Connect to a server
redis-cli server
# Make an insert
set key value
# Make multiple insert
@pbrisbin
pbrisbin / sendgrid-test.hs
Created October 17, 2014 18:37
SendGrid test via Haskell
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Network.Mail.Mime
import Network.Mail.SMTP
import qualified Data.Text.Lazy as TL
-- Get from e.g. `heroku config`
username = ""
@pbrisbin
pbrisbin / steps.md
Created July 20, 2014 17:10
End-to-end development of a Haskell project

Prerequisites: GHC + cabal-install

Setup project skeleton using hi and my template:

% cabal update
% cabal install hi
% hi \
    --module-name "Foo.Bar" \
    --package-name "foo" \

--author 'Your Name' \

@pbrisbin
pbrisbin / log.txt
Last active August 29, 2015 14:04
Follow the types
2014-07-17 15:05:03 darthdeus guys I'm getting No instance for (Text.Julius.ToJavascript …Data.ByteString.Lazy.Internal.ByteString) when using aeson's encode ... how should I convert things to json so that I can interpolate them in julius?
2014-07-17 15:05:38 darthdeus should i unpack the bytestring and pack it into Text? (seems inefficient)
2014-07-17 15:09:25 darthdeus hmm seems lazy Text doesn't work either
2014-07-17 15:16:40 darthdeus aaargh, string doesn't work either
2014-07-17 15:16:55 brisbin String and Text should both be interpolatable
2014-07-17 15:17:10 darthdeus No instance for (Text.Julius.ToJavascript String) … arising from a use of ‘Text.Julius.toJavascript’
2014-07-17 15:17:18 darthdeus after doing this
2014-07-17 15:17:25 darthdeus let json = TL.unpack $ decodeUtf8 $ encode reports :: String
2014-07-17 15:17:32 darthdeus inside the .julius file just #{json}
2014-07-17 15:21:52 brisbin
@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
-- 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