Skip to content

Instantly share code, notes, and snippets.

@nathanic
nathanic / commandlinefu.clj
Created May 23, 2013 14:28
lazybot plugin to show unix tips from commandlinefu.com
(ns lazybot.plugins.commandlinefu
(:use [lazybot registry]
[clojure.data.json :only [read-json]])
(:require [clj-http.client :as client])
(:import org.apache.commons.lang.StringEscapeUtils)
)
; http://www.commandlinefu.com/site/api
(def CLFU-URL "http://www.commandlinefu.com/commands/random/json")
@nathanic
nathanic / MyMaybe.hs
Created March 11, 2013 13:37
Educational Reimplementation of the Maybe Monad
-- | Re-implementing the Maybe monad from memory, to make sure I
-- understand it.
module MyMaybe where
import Prelude hiding (Maybe, Just, Nothing)
data MyMaybe a = MyNothing | MyJust a
deriving (Eq, Show)
instance Monad MyMaybe where
@nathanic
nathanic / h2server.sh
Last active December 12, 2015 07:48
simple script to detect and run the latest h2 server
#!/bin/sh
# find and run the latest version of h2 in the local maven repo
H2VERSION=$(ls ~/.m2/repository/com/h2database/h2/ | grep '^[.0-9]*$' | tail -n 1)
if [[ -z "$H2VERSION" ]]; then
echo "NOPE: I can't find any h2 jars installed in your maven repo."
else
echo detected H2 version is $H2VERSION.
java -cp ~/.m2/repository/com/h2database/h2/${H2VERSION}/h2-${H2VERSION}.jar org.h2.tools.Server $@
@nathanic
nathanic / multimap_thing.clj
Last active December 11, 2015 22:18
Clojure version of something josh was trying in Guava
(def input [["a" "apple"] ["a" "amazon"] ["b" "banana"] ["c" "clown"]])
(->> (group-by first input) ; now we have our keys pointing to lists of every key value pair with that key
(map (fn [[k v]] [k (map second v)])) ; for each key value pair, keep only the second parts of the values
(into {})) ; throw it into a hash map
;=> {"a" ("apple" "amazon"), "b" ("banana"), "c" ("clown")}
@nathanic
nathanic / hackernews.clj
Created January 29, 2013 19:39
Lazybot hacker news plugin
(ns lazybot.plugins.hackernews
(:use [lazybot registry]
[clojure.data.json :only [read-json]])
(:require [clj-http.client :as client])
(:import org.apache.commons.lang.StringEscapeUtils)
)
; we've got a couple choices for hacker news APIs
; both APIs return similar JSON
; but ihackernews seems faster but unreliable (500s a lot)
@nathanic
nathanic / validation-test-example.clj
Created November 29, 2012 19:34
validation test example
(fact "answers get validated"
(let [ctx {:state :composing
:players #{"data" "geordi" "picard"}
:submissions {}
:letters [\S \I \T \M]
;:live? true
}]
(submit-answer ctx "data" "sock it to me")
=> (contains {:submissions {"data" "sock it to me"}})
@nathanic
nathanic / feelings.clj
Created November 29, 2012 16:11
bitsbot feelings plugin
(ns lazybot.plugins.feelings
(:require [clojure.string :as string])
(:use [lazybot registry]
[somnium.congomongo :only [fetch fetch-one insert! destroy!]]))
; feelings.clj: a lazybot plugin to remember and report how people feel about various stuff
; TODO: parameterize prefix instead of literal '@', or don't bother?
(def love-responses
@nathanic
nathanic / apples_to_apples.clj
Created November 14, 2012 16:53
closer match to the style of silly_big_ben_irc_bot
(ns simplebot.core
(:use [clj-time.core :exclude [extend]]
[clj-time.local])
(:require [irclj.core :as ircb]
[overtone.at-at :as at-at]
[clojure.string :as string]))
(def CHANNEL "#silly-bot-test")
(defn -main [& args]
@nathanic
nathanic / big_ben.clj
Created November 14, 2012 16:01
clojure implementation of josh's big ben bot
(ns big-ben.core
(:use [clj-time.core :exclude [extend]]
[clj-time.local])
(:require [irclj.core :as ircb]
[overtone.at-at :as at-at]
[clojure.string :as string]))
(def HOUR-IN-MS (* 60 60 1000))
(def config
@nathanic
nathanic / greetings.clj
Created October 12, 2012 16:28
simple lazybot plugin, detects and replies to greetings
(ns lazybot.plugins.greetings
(:use lazybot.registry)
(:use [lazybot.utilities :only [prefix]])
(:require [clojure.string :as s]))
(def morning-patterns
[#".*good.morning.*"
#".*top.*o.*morning.*"
])