View async.clj
(def work 10)
(def workers 2)
(defn make-work []
(let [c (chan work)]
(dotimes [i work]
(>!! c i))
(close! c)
c))
View js-beautify.el
;;; js-beautify.el -- beautify some js code
(defgroup js-beautify nil
"Use jsbeautify to beautify some js"
:group 'editing)
(defcustom js-beautify-args "--jslint-happy --brace-style=end-expand --keep-array-indentation"
"Arguments to pass to jsbeautify script"
:type '(string)
:group 'js-beautify)
View BootEditFor.cs
public static class HtmlHelperExtensions
{
public static MvcHtmlString BootEditFor<TModel, TValue>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TValue>> expression, Func<Expression<Func<TModel, TValue>>, MvcHtmlString> editHelper)
{
var sb = new StringBuilder("<div class='clearfix'>");
sb.Append(htmlHelper.LabelFor(expression).ToHtmlString());
sb.Append("<div class='input'>");
sb.Append(editHelper(expression).ToHtmlString());
sb.Append("<span class='help-inline'>");
sb.Append(htmlHelper.ValidationMessageFor(expression).ToHtmlString());
View new1.clj
(declare *indent-level* *inline?*)
(defn- indent-level-str [level]
"Returns the proper indent string for a level"
(apply str (repeat (* 2 level) " ")))
(defn indent [out]
"Writes an indent string for a given level"
(if (false? *inline?*)
(.write out "\n"))
View bubble.clj
(defn bubble-sort [xs]
"Sort a collection using the bubble sort algo. Todo: Accept Java Comparator..."
{:algorithm "Bubble Sort"
:complexity
{:best "O(n)"
:average "O(n^2)"
:worst "O(n^2)"}}
(letfn [(bubble [acc x]
(if (seq acc)
(if (> 0 (compare x (peek acc)))
View Schedule.clj
(def schedule
[{:day "Sunday, September 18, 2011",
:sessions
[{:time "11:30" :title "Learn Scala interactively with the Scala Koans" :speaker "Dianne Marsh"}
{:time "15:00" :title "Getting Cozy with Emacs" :speaker "Phil Hagelberg"}]}
{:day "Monday, September 19, 2011",
:sessions
[{:time "08:30" :title "TBD" :speaker "Erik Meijer"}
{:time "09:30" :title "Functional Thinking" :speaker "Neal Ford"}
{:time "10:30" :title "Extreme Cleverness: Functional Data Structures in Scala" :speaker "Daniel Spiewak"}
View gist:1016089
(defn do-something [lol fields]
(apply map (fn [& args]
(into {} args))
(map (fn [l k]
(map #(vector %1 %2) l (repeat k)))
lol fields)))
(do-something [[1 2 3] [4 5 6]] [:a :b]) ;; ({1 :a, 4 :b} {2 :a, 5 :b} {3 :a, 6 :b})
View gist:1016084
(defn do-something [lol]
(let [keys (map #(-> % meta :key) lol)]
(apply map (fn [& xs]
(apply hash-map (interleave keys xs)))
lol)))
(do-something [^{:key :a} [1 2 3] ^{:key :b} [4 5 6]]) ;; ({:a 1, :b 4} {:a 2, :b 5} {:a 3, :b 6})
View Generalized.clj
;;pass in a list of lists. Lists could contains N number of sub lists. Need an expression for each in each part of this function,
(defn do-something [lol]
(let [la (first lol)
lb (second lol)]
(map #(hash-map :a %1 :b %2)
la, lb))
View dddd.clj
(ns pynch.core
(:require [net.cgrand.enlive-html :as html])
(:require [clj-time.core :as tm]))
(def *hn-url* "http://news.ycombinator.com/")
(def *crawl-delay* 30000)
(defn to-int [s]
(Integer/parseInt s))