Skip to content

Instantly share code, notes, and snippets.

View singpolyma's full-sized avatar

Stephen Paul Weber singpolyma

View GitHub Profile
@singpolyma
singpolyma / TDD.hs
Created April 8, 2015 18:40
TDD add exercise (complete)
module TDD (add, ArgumentError(..)) where
import Data.Either
import Data.Monoid
import qualified Data.Text as T
newtype ArgumentError = ArgumentError [Integer] deriving (Show, Eq)
instance Monoid ArgumentError where
mempty = ArgumentError []
@singpolyma
singpolyma / TDD.hs
Last active August 29, 2015 14:18
TDD add exercise (advanced)
module TDD (add, ArgumentError(..)) where
import Data.Foldable
import Data.Monoid
import Data.Semigroup (Semigroup(..))
import Data.Validation (AccValidation(..))
import Data.Semigroup.Applicative (Ap(..), getApp)
import qualified Data.Text as T
newtype ArgumentError = ArgumentError [Integer] deriving (Show, Eq)
@singpolyma
singpolyma / unsplash.sh
Created March 3, 2015 05:07
Set wallpaper to random recent unsplash image
#!/bin/sh
IDX=$(( ( $(od -N1 -An -t dI /dev/urandom) % 10 ) + 1 ))
feh --bg-fill "$(curl -q https://unsplash.com/rss | grep -o '<url>[^<]*' | sed -ne "${IDX}p" | cut -d'>' -f2- | sed -e 's/&amp;/\&/g')"
@singpolyma
singpolyma / .ngrok
Last active August 29, 2015 14:07
ngrok setup for pairing in rails
tunnels:
rails:
subdomain: yourname
proto:
http: 3000
ssh:
remote_port: 51690
proto:
tcp: 22
@singpolyma
singpolyma / whyfalsy.rb
Created September 18, 2014 15:49
WhyFalsy
class WhyFalsy
attr_reader :msg, :backtrace
def initialize(msg=nil)
@msg = msg
# Hack to get a backtrace
begin
raise
rescue Exception
@singpolyma
singpolyma / UnexceptionalIO.hs
Created September 2, 2014 20:46
Control.Error.UnexceptionalIO
module Control.Error.UnexceptionalIO (
UIO.UnexceptionalIO,
UIO.UIO,
fromIO,
runUnexceptionalIO,
runEitherIO,
fromIO',
UIO.unsafeFromIO,
syncIO
) where
@singpolyma
singpolyma / ajax-form.js
Last active August 29, 2015 14:05
Submit any form with AJAX and jQuery
$('#thing form').submit(function(e) {
var $this = $(this);
e.preventDefault();
$.ajax({
type: this.method,
dataType: "JSON",
url: this.action,
data: $this.serialize(),
success: function() {
@singpolyma
singpolyma / 1model_example.rb
Last active August 29, 2015 14:05
JSON Template
@model = OpenStruct.new(name: 'steve', age: 12, contacts: [{name: 'steve', sekret: 6}], other: 'stuff', moar: 'things')
json @model,
:name,
:age,
oldness: :age,
friends: [nested(:name), from: :contacts],
contacts: nested('contact_partial', :model)
other: ->(c) { c + 'hai' },
stuff: [->(c) { c + 'you' }, from: :moar]
@singpolyma
singpolyma / keybase.md
Created April 12, 2014 21:37
keybase.md

Keybase proof

I hereby claim:

  • I am singpolyma on github.
  • I am singpolyma (https://keybase.io/singpolyma) on keybase.
  • I have a public key whose fingerprint is 59E6 82C3 EAF3 9A21 0CA7 3534 D11C 2911 CE51 9CDE

To claim this, I am signing this object:

module SMSRelayCommon
extend Blather::DSL
def self.log(msg)
t = Time.now
puts "LOG %d.%09d: %s" % [t.to_i, t.nsec, msg]
end
def self.log_raw(msg)
puts msg