Skip to content

Instantly share code, notes, and snippets.

@jColeChanged
jColeChanged / someone-use-this.clj
Created December 16, 2010 04:36
I hope Clojure is blessed.
(defn find-fn
[inputs outputs]
(doseq [x (ns-publics (the-ns `clojure.core))]
(try
(if (= outputs
(binding [*out* java.io.StringWriter]
(apply
(if (-> (second x) meta :macro)
(macroexpand `(second x))
(second x))
@jColeChanged
jColeChanged / more-clojurey-find.clj
Created December 16, 2010 05:19
God let this be useful.
(defn find-fn
[in out]
(map first (filter
(fn [x]
(try
(= out
(binding [*out* java.io.StringWriter]
(apply
(if (-> (second x) meta :macro)
(macroexpand `(second x))
{:servers ["irc.freenode.net"] ; A list of servers.
:prepends #{"@"} ; The character you want for a prepend. Currently set to @
:bitly-login "" ; Your bit.ly login.
:bitly-key "" ; API key and login above needed for URL shortening.
:wordnik-key "" ; API key needed for dictionary access.
:max-operations 3 ; The maximum number of operations that can be running at any given time.
:pending-ops 0 ; The number of operations running right now
:admin-add? true ; only admins can add help topics
:admin-rm? true ; only admins can remove help topics
:eval-prefixes {:defaults ["->" "." "," ; prefixes in any channel
@jColeChanged
jColeChanged / gist:850531
Created March 2, 2011 05:33
Naive Implementation of rotate left and rotate right.
(defn rotatel
([n col]
(let [n (mod n (count col))]
(concat
(drop n col)
(take n col))))
([col]
(rotatel 1 col)))
(defn rotater
def bayes(a, b_given_a, b_given_not_a):
"""Calculates P(a|b) using bayes theorem.
Bayes theorem states that:
P(b|a) * P(a)
P(a|b) = --------------------------------
P(b|a) * P(a) + P(b|~a) * P(~a)
Intuitively this is saying that the probability of b given a is equivalent
@jColeChanged
jColeChanged / Merge Sort In Javascript
Created March 25, 2011 16:13
You asked for a sorting algorithm or a function which merged two arrays.
function merge(array_one, array_two)
{
var new_array_length = array_one.length + array_two.length;
var array_three = new Array(new_array_length);
var p_one = 0;
var p_two = 0;
for (var p_three = 0; p_three < new_array_length; p_three++)
{
if (array_one.length == p_one)
{
@jColeChanged
jColeChanged / gist:938272
Created April 23, 2011 04:16
A Nifty Clojure Function
(defn fn-and
"Takes a set of functions and returns a fn which returns whether
every item in the juxtaposition of those functions is true."
([& fns]
(let [juxted-fns (apply juxt fns)]
(fn [& args] (every? true? (apply juxted-fns args))))))
@jColeChanged
jColeChanged / gist:939383
Created April 24, 2011 07:03
My attempt at matrix multiplication in Clojure
(defn C_yx [m1 m2 y x num-cols num-rows]
(reduce +
(map *
(map #(nth (nth m1 y) %1) (range num-cols))
(map #(nth (nth m2 %1) x) (range num-rows)))))
(defn multiply [m1 m2]
(let [num-rows (count m1) num-cols (count (first m1))]
(for [y (range num-rows)]
(for [x (range num-cols)]
(use 'clojure.contrib.math)
(def factorial
(fn [n]
(loop [cnt n acc 1]
(if (zero? cnt)
acc
(recur (dec cnt) (* acc cnt))))))
(defn perm
@jColeChanged
jColeChanged / 20 Questions in Common Lisp
Created August 6, 2011 00:30
Just Wrote the Game Twenty Questions in Common Lisp
(defun input-question ()
(print "Please enter a question which has a yes answer for your word. This question should result in a no for the incorrect word given earlier:")
(read-line))
(defun input-chosen-word ()
(print "Please enter the word that you chose at the start of the game:")
(read-line))
(defun input-question-answer (question)
(print question)