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
(ns rabscuttle.test-json | |
(:require [rabscuttle.json :as json]) | |
(:use [clojure.contrib.test-is])) | |
(deftest encode-value | |
(let [pairs [["string" "\"string\""] | |
["" "\"\""] | |
["\"" "\"\"\""] | |
[:keyword "\"keyword\""] | |
['symbol "\"symbol\""] |
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
(ns rabscuttle.parser-combinator) | |
(comment | |
"Working through http://www.cs.nott.ac.uk/~gmh//parsing.ps" | |
"parser is a function that takes in input and returns [[v, inp]]") | |
;; Primitive Parsers | |
(defn succeed [v] (fn [inp] [[v inp]])) | |
(defn fail [inp] []) |
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
(require 'magit) | |
(defun my-magit-run (&rest args) | |
(apply #'magit-run (cons "git" args)) | |
(message (mapconcat #'identity args " "))) | |
(defun my-magit-hack () | |
(interactive) | |
(let ((working-branch (magit-get-current-branch))) | |
(my-magit-run "checkout" "master") |
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
;; clojure | |
(require 'clojure-paredit) | |
;; slime | |
(require 'slime) | |
(slime-setup) | |
;; slime fancy repl | |
(require 'slime-repl) |
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
(ns rabscuttle.parser-combinator) | |
(comment | |
"Working through http://www.cs.nott.ac.uk/~gmh//parsing.ps" | |
"A parser is a function that takes in input and returns lazy list of list of parsed value, and remaining input pairs") | |
(def letters (map char (lazy-cat (range (int \a) (inc (int \z))) | |
(range (int \A) (inc (int \Z)))))) | |
(def digits (map char (lazy-cat (range (int \0) (inc (int \9)))))) |
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
(ns rabscuttle.parser-combinator) | |
(comment | |
"Working through http://www.cs.nott.ac.uk/~gmh//parsing.ps" | |
"A parser is a function that takes in input and returns lazy list of list of parsed value, and remaining input pairs") | |
(def letters (map char (lazy-cat (range (int \a) (inc (int \z))) | |
(range (int \A) (inc (int \Z)))))) | |
(def digits (map char (lazy-cat (range (int \0) (inc (int \9)))))) |
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)) |
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
;; 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 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 |