Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(comment "
SpeedNotes Clojure script, by Torbjørn Marø.
Version 1.0 - 2010.08.17
Clojure version 1.1 (w/Contrib)
Always have it running in a console window to quickly note down stuff
you you need to remember - thoughts and ideas you don't want to loose,
but don't want to steal focus away from what you are currently doing.
Save notes:
At the prompt type a keyword + the text you want to save.
>todo Buy milk
This will append 'Buy milk' to todays TODO file, prefixed with the
time you entered it. ANy word can be used as a keyword, and each
keyword will get it's own file (one for each day).
List saved items for a keyword:
At the prompt enter 'list' + a keyword
>list todo
This will list everything you have saved in your todo-list today.
List all saved items:
Type 'summary' at the prompt. This will list the content of all your
keyword files for today.
What about notes from yesterday?
Notes are saved to plain text files in the current directory, so you
can easily access and read them using any text viewer. They can not
be accessed however by the current version of SpeedNotes, which is
only concerned with todays notes.
Exit the script:
If you really want to close down SpeedNotes you enter 'quit' at the
(ns marosoft.speednotes
(:import java.util.Date)
(defn split-keyword-text [line]
"Splits a line on keyword and the rest.
Returns it as a vector of the two.
The keyword is made upper case."
(let [space-index (.indexOf line " ")]
(if (neg? space-index)
[(.toUpperCase line) nil]
[(.toUpperCase (.substring line 0 space-index))
(.substring line (inc space-index))])))
(defn pad-zero [s]
(.replace (format "%1$#2s" s) " " "0"))
(defn get-date-string []
(let [now (Date.)]
(str (+ 1900 (.getYear now)) "."
(pad-zero (inc (.getMonth now))) "."
(pad-zero (.getDate now)))))
(defn get-time-string []
(let [now (Date.)]
(str (pad-zero (.getHours now)) ":"
(pad-zero (.getMinutes now)))))
(defn get-file-name [keyword]
"Gets todays filename for a given keyword"
(str keyword "-" (get-date-string) ".log"))
(defn write-to-file [file text]
"Write a log line to a given file"
(append-spit file
(str (get-time-string)
(defn print-keyword-file [keyword]
"Prints the content of todays file for a given keyword"
(println "--------------------------------------")
(try (-> keyword
(catch e
(println "*** No" keyword "file today!"))))
(defn filter-files [pattern files]
"Filters a collection of files on a pattern"
(filter #(-> (.getName %)
(.indexOf pattern)
(defn print-summary []
"Prints the content of all files from today"
(doseq [log-name (->> (File. ".")
(filter-files (get-date-string))
(map #(.getName %)))]
(println "----------------------------------")
(println \tab log-name)
(println "----------------------------------")
(println (slurp log-name)))))
(defn main-loop []
"Takes action on input and continues"
(println) (print ">") (flush)
(let [[keyword text] (split-keyword-text (read-line))]
(condp = keyword
"QUIT" (System/exit 0)
"LIST" (print-keyword-file text)
"SUMMARY" (print-summary)
(-> keyword
(write-to-file text))))

This comment has been minimized.

Copy link

commented Aug 18, 2010

No description provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.