Skip to content

Instantly share code, notes, and snippets.

@tce
tce / README.md
Created November 14, 2013 22:32 — forked from anonymous/options.json
created by http://livecoding.io
fruits=(apple orange kiwi "dried mango")
for fruit in "${fruits[@]}"; do
echo "${fruit}"
done
@tce
tce / _.md
Created January 22, 2013 22:31
First Test
@tce
tce / cli
Created February 6, 2012 19:31
Using CLI in clojure
;; from http://twitch.nervestaple.com/2012/01/12/clojure-hbase/?utm_source=NoSQL%20Weekly%20Newsletter
(defn tool-run
"Provides the main function needed to bootstrap the Hadoop application."
[^Tool this args-in]
;; define our command line flags and parse out the provided
;; arguments
(let [[options args banner]
(cli args-in
["-h" "--help"
@tce
tce / Freq
Created February 2, 2012 17:01
Clojure frequencies
;; from http://twoguysarguing.wordpress.com/2010/07/26/7-rules-for-writing-clojure-programs/
(reduce #(assoc %1 %2 (inc (get %1 %2 0))) {} “aabcdcdcd”)
=> {\d 3, \c 3, \b 1, \a 2}
@tce
tce / printNoQuotes
Created February 2, 2012 16:35
Simple macro example
;; allows you to say (hello jenny) instead of (hello "jenny")
(defmacro hello [s] `(println "Hello" ~(name s)))
@tce
tce / renamefiles.sh
Created January 19, 2012 19:47
Rename files in bash
# rename from *.JPG to *.jpg
for x in *.JPG; do mv "$x" "${x/.JPG}".jpg; done
rename 's/\.JPG/\.jpg/' *.JPG
#strip spaces
rename 's/ //' *.JPG
# upper to lower case
rename 'y/A-Z/a-z/' *.JPG
@tce
tce / clojureDirectoryList
Created January 18, 2012 21:52
clojure directory listings
(comment "wildcardfilter from http://corfield.org/blog/post.cfm/real-world-clojure-powermta-log-files")
(defn- wildcard-filter
"Given a regex, return a FilenameFilter that matches."
[re]
(reify java.io.FilenameFilter
(accept [_ dir name] (not (nil? (re-find re name))))))
(defn- nonhidden-filter
"return a FilenameFilter that ignores files that begin with dot or end with ~."