This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn parse-qs [qs] | |
(let [split (fn [s v] (seq (.split s v))) | |
pairs (split qs "&") | |
parse-pair (fn [p] (map url-decode (split p "=")))] | |
(apply hash-map (mapcat parse-pair pairs)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(regexp-opt '("defn" "defn-" | |
"defmulti" "defmethod" | |
"defmacro" "defmacro-" | |
"deftest" | |
"defstruct" "defstruct-" | |
"def" | |
"defonce" "defonce-" | |
"defnk" | |
"defvar" "defvar-" | |
"defunbound" "defunbound-" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn render-template | |
"Loads a StringTemplate off the classpath and binds the params" | |
[template-name & params] | |
(doto (. (StringTemplateGroup. "tmpls") getInstanceOf template-name) | |
(set-attrs! (partition 2 params)))) | |
(defn set-attrs! [t attr-pairs] | |
(doseq [[k v] attr-pairs] | |
(. t setAttribute (name k) v))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
orderedForkIO :: [IO a] -> IO [a] | |
orderedForkIO actions = do | |
-- create a blocking container to hold the results for each IO action | |
mvars <- replicateM (length actions) newEmptyMVar | |
-- fork and run the action then put the result in the container | |
let run mvar action = forkIO $ action >>= putMVar mvar | |
-- fork and run each action with a container in the local run function | |
forkIO $ zipWithM_ run mvars actions | |
-- collect all the results, blocking until they are finished | |
mapM takeMVar mvars |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE FlexibleInstances #-} | |
module PivotalTeam.Html where | |
import Happstack.Server | |
import Text.XHtml.Strict | |
import PivotalTeam.State | |
instance HTML (TeamMember, Bool) where | |
toHtml (TeamMember n _, b) = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
public void take(int v) { | |
if (currentMode == Mode.accumulating) { | |
int digits = (int)Math.pow(10, (int)Math.log10(v) + 1); | |
int x = stack.pop(); | |
x *= digits; | |
x += v; | |
stack.push(x); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Network.Curl | |
--import Network.URI | |
import Data.Char(isAlphaNum, toLower) | |
import Data.List(transpose,sort,foldl') | |
import Data.Maybe(fromMaybe) | |
import Control.Monad --(foldM) | |
import System.Environment(getArgs) | |
import qualified System.Random as Random | |
import qualified Data.Map as Map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; reduce is the key here | |
(def s [{:pk 1 :data "a"} {:pk 2 :data "b"} {:pk 3 :data "c"}]) | |
(def h (reduce (fn [result item] (merge result {(:pk item) item})) {} s)) | |
;; anonymous function version | |
(def h2 (reduce #(merge %1 {(:pk %2) %2}) {} s)) | |
;; h is {3 {:pk 3, :data "c"}, 2 {:pk 2, :data "b"}, 1 {:pk 1, :data "a"}} | |
;; general form | |
(defn m-of-ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import System.Environment(getArgs) | |
import qualified Data.ByteString as L | |
import qualified Data.ByteString.Char8 as L8 | |
import Text.CSV.ByteString | |
import Control.Monad | |
import Control.Applicative | |
import Data.List | |
import Data.Char |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun clj-repl (dir) | |
(interactive (list (read-directory-name "Clojure REPL dir: "))) | |
(setq default-directory dir) | |
(slime)) |