How do you undef / unintern a symbol in Clojure? (ns-unmap 'namespace 'symbol). Continue Reading »
Popularity: 22% [?]
How do you undef / unintern a symbol in Clojure? (ns-unmap 'namespace 'symbol). Continue Reading »
Popularity: 22% [?]
The date and time classes built into Java are a horrible mess. What are Clojure programmers to do? Use Joda Time instead. Joda Time is coherently designed and easy to use.
JDBC (at least, the PostgreSQL driver) can’t use Joda Time directly (without explicit type mapping). One way to convert a Joda LocalDate into something JDBC can use:
(defn to-sql-date [date] "Convert any Joda-readable date object (including a string) to a java.sql.Date" (java.sql.Date. (.. (LocalDate. date) toDateMidnight toInstant getMillis)))
It’s not pretty, but it works. You can follow a similar procedure for any of the Joda classes.
Popularity: 30% [?]
Clojure.contrib.logging doesn’t have any way to set the log level. This is obviously a problem if you want to make use of various log levels (debug, warn, etc.) to separate different logging depths. Here’s a function to set the logging level on my default clojure.contrib.logging setup:
;;; This version works when (impl-get-log "") returns an org.apache.commons.logging.impl.Jdk14Logger
(use 'clojure.contrib.logging)
(defn set-log-level! [level]
"Sets the root logger's level, and the level of all of its Handlers, to level.
Level should be one of the constants defined in java.util.logging.Level."
(let [logger (.getLogger (impl-get-log ""))]
(.setLevel logger level)
(doseq [handler (.getHandlers logger)]
(. handler setLevel level))))
;;; This version works when (impl-get-log "") returns a java.util.logging.LogManager$RootLogger
(use 'clojure.contrib.logging)
(defn set-log-level! [level]
"Sets the root logger's level, and the level of all of its Handlers, to level.
Level should be one of the constants defined in java.util.logging.Level."
(let [logger (impl-get-log "")]
(.setLevel logger level)
(doseq [handler (.getHandlers logger)]
(. handler setLevel level))))
This log level setting function works with a standard out-of-the-box clojure.contrib.logger on my system — depending on what logging libraries it finds on your classpath, as per the docs, it may not work for you. In particular, you need to be using clojure.contrib.logger to wrap an Apache Commons Logging instance, which in turn wraps a java.util.logging instance. This is the way my system works without any configuration; YMMV. Hopefully, something like this will be assimilated into a universal wrapper in the next clojure.contrib.logging.
For the gory details of how this was constructed… Continue Reading »
Popularity: 45% [?]
Libcurl’s Java bindings now compile on Macintosh, with a few minor modifications to the Makefile. Get the code from my Github account.
Update: More recent Java bindings, which do not seem to be linked anywhere on the libcurl site, are available at http://www.gknw.net/viewvc/trunk/?root=curl-java. Still no multi support, though.
Popularity: 5% [?]
A Clojure version of my Yahoo Finance Ruby gem seemed like an interesting challenge and a good way to learn Clojure better. This version uses Apache HttpClient, which is significantly slower than libcurl. A libcurl version is on the way. Continue Reading »
Popularity: 45% [?]
Debuggers like JSwat and Eclipse can be remotely attached to live Clojure processes via TCP, but you have to tell the JVM to enable remote debugging when you start it. Leiningen does not presently have an (obvious) way to set java command line flags in project.clj, but it does pass the JAVA_OPTS environment variable to the JVM, so you can do:
JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n" lein swank # or "lein repl", etc.
to enable remote debugging. Watch the output for the port it allocates, and put that into JSwat/Eclipse/etc. Continue Reading »
Popularity: 12% [?]
Pizzoccheri is a northern Italian dish of buckwheat noodles, potatoes, and greens, typically chard or cabbage. I found out about it as I had some chard on hand and was bored with my usual “blanch it and then fry in olive oil with garlic” recipe. I made some modifications to Mark Bittman’s version based on what I had available — no buckwheat or fontina, so I substituted fettuccine and mozzarella, to good effect. The result was pretty good, somewhat resembling an Italian version of rösti. Here’s my take on it: Continue Reading »
Popularity: 6% [?]
Rincanter allows one to access the R statistical programming language from Clojure. Rincanter also integrates R with Incanter for charting and more stats. Rincanter is based on rJava‘s JRI R-from-Java bridge. Getting this working required making a JNI library available to Clojure via an as-yet-undocumented Leiningen setting, :native-path. Continue Reading »
Popularity: 17% [?]
Stella Mare in Santa Barbara is one of the best restaurants I’ve ever been to. No exaggeration; this is not something I write lightly. Every aspect of the restaurant itself and every dish is well thought out and perfectly executed. It’s a bit pricey, but you get what you’re paying for. Continue Reading »
Popularity: 3% [?]