Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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]
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 / 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
### 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 / 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
@pbrisbin
pbrisbin / watchme.rb
Last active December 31, 2015 18:59
Show repos which you own but are not yourself watching.
#!/usr/bin/env ruby
#
# $ curl -o watchme.rb 'https://gist.github.com/pbrisbin/8030960/raw/watchme.rb'
# $ ruby ./watchme.rb
#
###
require 'json'
class GitHub
def initialize(username, password)
@pbrisbin
pbrisbin / spot.rb
Last active December 30, 2015 23:39
Spot some common mistakes in multi-language rails translations files.
require 'yaml'
# {a,{b,{c}} => [a, a.b, a.b.c]
def parse_keys(hash, keys = [], prefix = nil)
hash.each do |k, v|
key = [prefix, k].compact.join('.')
if v.is_a?(Hash)
parse_keys(v, keys, key)
else