Skip to content

Instantly share code, notes, and snippets.

View bradclawsie's full-sized avatar

Brad Clawsie bradclawsie

View GitHub Profile
@bradclawsie
bradclawsie / uuid.hs
Created February 18, 2012 06:03
generate hashed and random uuids in haskell
{-# LANGUAGE PackageImports #-}
module Main where
import qualified Data.Char as C
import qualified Data.Word as W
-- must qualify this (requiring the ghc pragma above) to disambiguate
-- from the Data.UUID also in system-uuid
import qualified "uuid" Data.UUID as U
import qualified Data.UUID.V5 as U5
@bradclawsie
bradclawsie / rstring.hs
Created March 1, 2012 06:38
random string of uppercase chars
module Main where
import Control.Monad.Random
import Data.Char
rnd :: (RandomGen g) => Rand g Int
rnd = getRandomR (65,90)
main = do
values <- evalRandIO (sequence (replicate 10 rnd))
@bradclawsie
bradclawsie / json_types
Created March 24, 2012 22:16
json of different value types
{"S":"a string"}
{"N":"123456"}
{"SS":["a string","another string"]}
{"NS":["123","456"]}
@bradclawsie
bradclawsie / go_type
Created March 24, 2012 22:25
match Go type to json
#!/usr/bin/env gorun
package main
import (
"encoding/json"
"fmt"
)
type MyJSONType struct {
@bradclawsie
bradclawsie / convert_go
Created March 24, 2012 22:47
convert json to native Go
// take an interface{} string and turn it into a real string
func To_S(i interface{}) (string,error) {
i_str,ok := i.(string)
if !ok {
e := fmt.Sprintf("cannot convert %v to string\n",i)
return "", errors.New(e)
}
return i_str,nil
}
@bradclawsie
bradclawsie / wai-sample.hs
Created April 1, 2012 05:48
complete wai/warp sample server
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Network.Wai
import Network.Wai.Handler.Warp
import Network.HTTP.Types
import qualified Data.Text as T
import Data.Time.Clock
import Data.Time.Format
@bradclawsie
bradclawsie / strpuzzle.hs
Created April 6, 2012 05:48
string puzzle solution
module Main where
import Data.List
import Data.List.Split
-- performs the transformation of adjacent strings
tr :: String -> String
tr s = case s of
"ab" -> "c"
"ba" -> "c"
"ac" -> "b"
{-# LANGUAGE TupleSections #-}
module Main where
-- see https://plus.google.com/u/0/105746006385940131491/posts/9Uev6KVRUgK for
-- context
-- what we essentially have is a non-associative operation (represented by
-- concatenation):
--
-- ab = ba = c
-- bc = cb = a
<?php
$u = 4/0;
if ($u == $t) {
print "do stuff with *your* credit card number here\n";
}
?>
@bradclawsie
bradclawsie / loadredis.hs
Created May 30, 2012 05:48
loadredis.hs
module Main where
import qualified Data.DateTime as DATE
import qualified Control.Monad as C
import qualified Control.Monad.Trans as CT
import qualified Database.Redis as R
import qualified System.Random as SR
import qualified Data.ByteString.UTF8 as U
-- a nice find from the web - picking an elt at random