Skip to content

Instantly share code, notes, and snippets.

View wilkes's full-sized avatar

Wilkes Joiner wilkes

View GitHub Profile
(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))))
(regexp-opt '("defn" "defn-"
"defmulti" "defmethod"
"defmacro" "defmacro-"
"deftest"
"defstruct" "defstruct-"
"def"
"defonce" "defonce-"
"defnk"
"defvar" "defvar-"
"defunbound" "defunbound-"
(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)))
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
{-# 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) =
{-
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);
}
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
;; 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
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
(defun clj-repl (dir)
(interactive (list (read-directory-name "Clojure REPL dir: ")))
(setq default-directory dir)
(slime))