Skip to content

Instantly share code, notes, and snippets.

@kohyama
Created December 11, 2012 05:56
Show Gist options
  • Save kohyama/4256213 to your computer and use it in GitHub Desktop.
Save kohyama/4256213 to your computer and use it in GitHub Desktop.
Clojure tips infrequently used

Clojure tips infrequently used

To get names of methods of a class

(map #(.getName %) (.getMethods java.io.File))
; -> ("equals" "toString" "hashCode" "compareTo" "compareTo" "getName" "length" "getParent" "isAbsolute" "getCanonicalPath" "setReadOnly" "list" "list" "delete" "getParentFile" "getPath" "getAbsolutePath" "getAbsoluteFile" "getCanonicalFile" "toURL" "toURI" "canRead" "canWrite" "exists" "isDirectory" "isFile" "isHidden" "lastModified" "createNewFile" "deleteOnExit" "listFiles" "listFiles" "listFiles" "mkdir" "mkdirs" "renameTo" "setLastModified" "setWritable" "setWritable" "setReadable" "setReadable" "setExecutable" "setExecutable" "canExecute" "listRoots" "getTotalSpace" "getFreeSpace" "getUsableSpace" "createTempFile" "createTempFile" "wait" "wait" "wait" "getClass" "notify" "notifyAll")
(map (memfn getName) (.getMethods java.io.File))

do the same.

The date when you did lein uberjar

(let [sdf (java.text.SimpleDateFormat. "yyyyMMddHHmmss")]
  (->>
    (clojure.java.io/resource "project-name/core__init.class")
    (.openConnection)
    (.getLastModified)
    (.format sdf)))

Hexadecimals

  • literal: 0xff ; -> 255
  • value -> string in hexadecimal representation: (Integer/toString 255 16) ; -> "ff"
  • string in hexadecimal representation -> value: (Integer/parseInt "ff" 16) ; -> 255
  • string -> array of ascii bytes: (.getBytes "0000") ; -> #<byte[] ...>
  • array of bytes -> list of values: (apply list (.getBytes "0000")) ; -> (48 48 48 48)

To supply a REPL

(use '[clojure.main :only (repl)])
(repl)

To exit from REPL

(. System exit 0)

To treat Japanese characters properly

Set the environment variable _JAVA_OPTIONS to -Dfile.encoding=UTF-8.

To do things at runtime

@tnoda
Copy link

tnoda commented Dec 11, 2012

πŸ‘

@kohyama
Copy link
Author

kohyama commented Dec 11, 2012

γ‚γ‚ŠγŒγ¨γ†γ”γ–γ„γΎγ™. η΅΅ζ–‡ε­—γŒδ½Ώγˆγ‚‹γ¨γ―ηŸ₯らγͺγ‹γ£γŸ πŸ˜…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment