Skip to content

Instantly share code, notes, and snippets.

m0smith / fizzbuzz.clj
Created Sep 22, 2012
fizzbuzz in Clojure
View fizzbuzz.clj
(take 100 (map #(let [s (str %2 %3) ] (if (seq s) s (inc %)) )
(cycle [ "" "" "Fizz" ])
(cycle [ "" "" "" "" "Buzz" ])))
m0smith / pipe.cljs
Created Dec 19, 2012
A ClojureScript usable version of pipe that will return a seq and a function to add elements to the end of the pipe. I found it here: and just wanted to have a copy I could find
View pipe.cljs
(defn pipe
"Returns a pair: a seq (the read end) and a function (the write end).
The function can takes either no arguments to close the pipe
or one argument which is appended to the seq. Read is blocking."
(let [promises (atom (repeatedly promise))
p (second @promises)]
[(lazy-seq @p)
([] ;close the pipe
m0smith / featurec.clj
Created Jan 4, 2013
An example of Clojure core.logic that finds map that match a certain structure. Both functions are equilivent but one uses list comprehension and the other uses core.logic
View featurec.clj
(ns logicfun.core
;(:refer-clojure :exclude [==])
(:use [clojure.core.logic :rename {== ?==}]))
(def data [
{:id 1 :type :t1 :name "one" :other1 :o2}
{:id 2 :type :t2 :name "two" :other2 :o1 :another :ao2}
{:id 3 :type :t3 :name "three" :other2 :o1 :another :ao1}
m0smith / blackjack.clj
Last active Dec 14, 2015
Basic Black Jack engine in Clojure
View blackjack.clj
(def suites [:heart :club :diamond :spade])
(def ranks
:ace [1 11]
:two [2]
:three [3]
:four [4]
:five [5]
:six [6]
:seven [7]
m0smith / iterate-while.clj
Last active Dec 14, 2015
Same as the core iterate function except the lazy sequence ends when the value is nil.
View iterate-while.clj
(defn iterate-while-1
[f x]
(when x
(cons x (lazy-seq (iterate-while f (f x))))))
(defn iterate-while
[f x]
(take-while identity (iterate f x)))
m0smith / ip.clj
Last active Dec 16, 2015
Get a list of active IP addresses for this host
View ip.clj
(import ( NetworkInterface Inet4Address))
(defn ip-filter [inet]
(and (.isUp inet)
(not (.isVirtual inet))
(not (.isLoopback inet))))
(defn ip-extract [netinf]
(let [inets (enumeration-seq (.getInetAddresses netinf))]
(map #(vector (.getHostAddress %1) %2) (filter #(instance? Inet4Address %) inets ) (repeat (.getName netinf)))))
View broken-refer.clj
(:require [clj-time.core :refer [epoch]]))
View rps.clj
(require 'clojure.core.async :refer :all)
(def MOVES [:rock :paper :scissors])
(def BEATS {:rock :scissors, :paper :rock, :scissors :paper})
(defn rand-player
"Create a named player and return a channel to report moves."
(let [out (chan)]
(go (while true (>! out [name (rand-nth MOVES)])))
m0smith / gist:6083731
Created Jul 25, 2013
Stack Trace from Archiva
View gist:6083731
javax.servlet.ServletException: javax.jdo.JDODataStoreException: Insert request failed: INSERT INTO JDOAUTHENTICATIONKEY (DATE_CREATED,PURPOSE,MODEL_ENCODING,DATE_EXPIRES,FOR_PRINCIPAL,AUTHKEY) VALUES (?,?,?,?,?,?)
SQL Exception: An SQL data change is not permitted for a read-only connection, user or database.
m0smith / wkp_Delicious.php
Last active Dec 20, 2015
A Lionwiki plugin that will pull data from Delicious. The usage is {delicious}user/tag{/delicious}. See
View wkp_Delicious.php
* Written by Matthew O. Smith <>
* With {delicious}user/tag{/delicious} insert links from the user and tags
* With {delicious}user/tag?count=50{/delicious} you can spcifiy the number of items returned
class Delicious
var $desc = array(
You can’t perform that action at this time.