Skip to content

Instantly share code, notes, and snippets.

@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)]
user> (read-string (str {:hai "there" "hello" 3 5 "5"}))
{:hai "there", "hello" 3, 5 "5"}
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) }
(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"))
(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)))
;; 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
;; "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
@devn
devn / rails_3_scope_options.rb
Created November 4, 2010 19:40
Rails 3 scope options to consider...
scope :latest_by_hashtag, lambda {|hashtag| {
:where => { :hashtags => hashtag },
:order_by => :tweeted_at.desc,
:limit => 20 }
}
# OR #
def self.latest_by_hashtag hashtag
where(:hashtags => hashtag).order_by(:tweeted_at.desc).limit(20)
@devn
devn / gist:671030
Created November 10, 2010 16:00
Emacs Nightly Fails to Build, OSX 10.6.4, Macbook Pro
Loading /Users/defn/src/emacs-nov-2010/lisp/vc/ediff-hook.el (source)...
Loading /Users/defn/src/emacs-nov-2010/lisp/tooltip.el (source)...
Finding pointers to doc strings...
Finding pointers to doc strings...done
Dumping under the name emacs
--- List of All Regions ---
address size prot maxp
--- List of Regions to be Dumped ---
address size prot maxp
--- Header Information ---
@devn
devn / gist:725974
Created December 2, 2010 20:15
tmux build failure
tty.c:392: warning: passing argument 2 of ‘bufferevent_write’ discards qualifiers from pointer target type
cc -DBUILD="\"1.3\"" -std=c99 -D_GNU_SOURCE -D_POSIX_SOURCE -iquote. -c -o tty-keys.o tty-keys.c
cc -DBUILD="\"1.3\"" -std=c99 -D_GNU_SOURCE -D_POSIX_SOURCE -iquote. -c -o tty-term.o tty-term.c
cc -DBUILD="\"1.3\"" -std=c99 -D_GNU_SOURCE -D_POSIX_SOURCE -iquote. -c -o utf8.o utf8.c
cc -DBUILD="\"1.3\"" -std=c99 -D_GNU_SOURCE -D_POSIX_SOURCE -iquote. -c -o window.o window.c
cc -DBUILD="\"1.3\"" -std=c99 -D_GNU_SOURCE -D_POSIX_SOURCE -iquote. -c -o window-choose.o window-choose.c
cc -DBUILD="\"1.3\"" -std=c99 -D_GNU_SOURCE -D_POSIX_SOURCE -iquote. -c -o window-clock.o window-clock.c
cc -DBUILD="\"1.3\"" -std=c99 -D_GNU_SOURCE -D_POSIX_SOURCE -iquote. -c -o window-copy.o window-copy.c
cc -DBUILD="\"1.3\"" -std=c99 -D_GNU_SOURCE -D_POSIX_SOURCE -iquote. -c -o xmalloc.o xmalloc.c
cc -DBUILD="\"1.3\"" -std=c99 -D_GNU_SOURCE -D_POSIX_SOURCE -iquote. -c -o xterm-keys.o xterm-keys.c