Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Dec 11, 2012

👍

@kohyama

This comment has been minimized.

Copy link
Owner Author

commented Dec 11, 2012

ありがとうございます. 絵文字が使えるとは知らなかった 😅

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.