Flashing the BIOS without a floppy drive can be done with an Ultimate Boot CD (free!) and a USB memory stick. BIOS upgrades usually come in the form of an MS-DOS executable meant to be run from a bootable floppy, but modern computers don’t usually have floppy drives anymore, and who has a copy of DOS lying around anyway?
- Download a copy of the free Ultimate Boot CD and burn it to disk. FreeDOS (and a lot of other useful stuff) is preinstalled on the CD. As the name implies, FreeDOS is a free, open source, binary-compatible replacement for MS-DOS.
- Download the replacement BIOS from your motherboard’s manufacturer. Unpack it onto a USB flash drive.
- Plug your flash drive into the target computer and boot it with your Ultimate Boot CD. Select FreeDOS from the menu.
- FreeDOS asks a number of configuration questions while booting. You can usually leave all at their default except for the ASPIUSB driver. ASPIUSB is not enabled by default (at the time of this writing), but is necessary for the use of a USB flash drive under DOS, so enable it when prompted.
- If you miss the prompt for the USB driver, don’t worry. Type “
menu” at a command prompt and enable USB devices from the popup menu.
- Change to your flash drive by typing e.g.
R: and execute the BIOS flash utility as per the manufacturer’s instructions. (If you don’t know which drive letter to use, type “menu” and select the option to display active drive letters.)
Popularity: 17% [?]
Posted in Tech |
No Comments » | May 8th, 2010
I wanted to parse some externally-generated and malformed HTML, so naturally I went to the short and sweet clojure.xml/parse function. I got a nasty error:
error: java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
It seems that the W3C blocked access to the DTDs two years ago, but Java still tries to load them by default anyway. The following allows clojure.xml to run without checking external DTDs:
(defn startparse-sax-non-validating [s ch]
(.. (doto (. javax.xml.parsers.SAXParserFactory (newInstance))
(.setValidating false)
(.setFeature "http://apache.org/xml/features/nonvalidating/load-dtd-grammar" false)
(.setFeature "http://apache.org/xml/features/nonvalidating/load-external-dtd" false)
(.setFeature "http://xml.org/sax/features/validation" false)
(.setFeature "http://xml.org/sax/features/external-general-entities" false)
(.setFeature "http://xml.org/sax/features/external-parameter-entities" false))
(newSAXParser) (parse s ch))))
Then you can simply (xml/parse "sourcefile.xml" startparse-sax-non-validating). This is not the ideal solution — ideally, we want to use a locally cached DTD — but it works well enough for one-off code. Read on for further information. Continue Reading »
Popularity: 36% [?]
Posted in Tech |
4 Comments » | April 28th, 2010
Psyleron sells a hardware random number generator and associated software package for experimentation on the interaction of consciousness and randomness. No, don’t laugh. Princeton Engineering Anomalies Research conducted decades of methodologically rigorous research into the nature of randomness. They concluded that deliberate conscious intention can produce a small but statistically significant and reproducible effect on the outcome of stochastic processes. Psyleron is a commercial offshoot of PEAR.
The Psyleron system, unfortunately, costs hundreds of dollars and only runs on Windows, so I wrote some quick Clojure to do experimentation with randomness, using /dev/random as the source. (It appears that /dev/random on Mac OS X does not provide the same quality guarantees as it does on Linux, but it’s fine for a prototype and the implementation allows easy substitution of another randomness source later.) Continue Reading »
Popularity: 24% [?]
Posted in Tech |
1 Comment » | April 22nd, 2010
SQL WHERE and HAVING clause strings can be rendered from neat, structured S-expressions with this simple Clojure macro:
(defmacro sql-expand
"Transforms nested s-expressions into SQL, for use in WHERE or HAVING clauses.
e.g.: (sql-expand (and (> foo 3)
(< bar 4)))
-> '(foo > 3 AND bar < 4)'
Nested clauses:
(sql-expand (or (and (> foo 3) (< bar 4))
(> baz 6)))
-> '((foo > 3 AND bar < 4) OR baz > 6)'
Embedded arbitrary SQL:
(sql-expand (and (> foo 3)
(< bar \"(SELECT max(foo) + 10 FROM bar)\")))
-> '(foo > 3 AND bar < (SELECT max(foo) + 10 FROM bar))'
"
[form]
(let [head (first form)]
(if (includes? '(and or) head)
`(str "(" (sql-expand ~(second form)) " "
~(.toUpperCase (str head)) " "
(sql-expand ~(last form)) ")")
(str (second form) " " head " " (last form)))))
Continue Reading »
Popularity: 30% [?]
Posted in Tech |
2 Comments » | April 5th, 2010
How do you undef / unintern a symbol in Clojure? (ns-unmap 'namespace 'symbol). Continue Reading »
Popularity: 22% [?]
Posted in Tech |
2 Comments » | March 24th, 2010
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% [?]
Posted in Tech |
2 Comments » | March 24th, 2010
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% [?]
Posted in Tech |
7 Comments » | March 14th, 2010
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% [?]
Posted in Tech |
No Comments » | March 13th, 2010
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% [?]
Posted in Tech |
5 Comments » | March 13th, 2010
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% [?]
Posted in Tech |
No Comments » | March 12th, 2010