Skip to content

Instantly share code, notes, and snippets.

;; "Clojure transactions should be easy to understand if you've ever used database
;; transactions - they ensure that all actions on Refs are atomic, consistent, and
;; isolated." (http://clojure.org/refs)
(def large-future-data-structure (ref {}))
(def big-text (read-lines (File. "/path/to/my/file")))
;; #"" is how you define a regex
;; dosync is required for transactions with a ref
;; CLOJURE ;;
;; use an up-to-date version of clojure mode (technomancy's version)
(add-to-list 'load-path "~/src/clojure-mode")
(add-to-list 'load-path "~/.emacs.d/elpa/slime-20100404/contrib")
;; initialize clojure-mode
(require 'clojure-mode)
;; setup autoloads for .clj documents
(defn serialize [ds]
(dorun (with-out-writer
(java.io.File. "serialized.db")
(binding [*print-dup* true] (prn ds))))
true)
(defn deserialize [f]
(with-open [r (PushbackReader. (FileReader. f))]
(let [rec (read r)]
rec)))
(ns jobmux.core
(:require [clojure.xml :as xml]
[clojure.zip :as zip]
[clojure.contrib.zip-filter.xml :as zf]))
(def craigslist (xml/parse "http://madison.craigslist.org/sof/index.rss"))
(def ruby-jobs (xml/parse "http://feeds.feedburner.com/jobsrubynow?format=xml"))
require "./lib/slugalizer/slugalizer.rb"
desc "Create a new blog post"
task :new_post, [:title] do |t, args|
created_at = Time.now.strftime("%Y-%m-%d")
slugged_title = Slugalizer.slugalize(args.title)
yaml_head = "---\nlayout: post\ntitle: #{args.title}\ndate: #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}\n---\n\n"
Dir.chdir("_posts")
File.open("#{created_at}-#{slugged_title}.markdown", 'w') { |f| f.write(yaml_head) }
user> (read-string (str {:hai "there" "hello" 3 5 "5"}))
{:hai "there", "hello" 3, 5 "5"}
@devn
devn / Destructuring Examples.clj
Created June 15, 2010 09:27
Destructuring Examples
;;; All Kinds of Destructuring ;;;
(let [foo 1] foo)
; => 1
(let [[foo bar] [1 2 3]] [foo bar])
; => [1 2]
(let [[foo bar & baz] [1 2 3]] [foo bar baz])
; => [1 2 (3)]
(defn markov-chain [index key]
"Lazily creates a markov chain"
(let [completion (markov-next index key)
next-key (nthrest (concat key completion) (count completion))]
(if (nil? completion)
'()
(lazy-cons (first completion) (markov-chain index next-key)))))
(def tutorial-defn-1
(html
[:p.bottom "So, you wanna learn Clojure... Perhaps you're in it for the Lisp, or the JVM goodness. Perhaps you'd like to get your I/O on without a monad after a brief bout with Haskell. Perhaps you're a language nerd, the kind of guy who just finished up investigating Scala or Erlang. I regret to inform you that none of the above will be considered in the following tutorial. This tutorial has been systematically decoupled from theory, and is instead filled with garbage. Delicious, fragrant garbage. The kind of garbage that makes you stop and take a few more whiffs. It's like maple syrup...only more pungent. The trouble with this kind of garbage is that you never get to do anything with it. The garbage *you* need is the kind of garbage you can sink your feet into and wiggle your toes around. So, without further ado I present to you: The Most Garbage Tutorial Ever Conceived By A Dolphin."]
[:p.bottom "I know what you're thinking: \"This is ridiculous! Cloj
(def file-info-extractors
{:filename #(.getName #^java.io.File %)
:path #(str (.toURI #^java.io.File %))
:modified #(.lastModified #^java.io.File %)})
(map #(reduce (fn [m [k e]]
(assoc m k (e %)))
{}
file-info-extractors)
(.listFiles (java.io.File. ".")))