In lieu of actual new content... a quick recap of some good posts from several of my favourite sources:
1. Steve Yegge's excellent post on code, code base size, and perhaps a reason to use rhino - http://steve-yegge.blogspot.com/2007/12/codes-worst-enemy.html
2. Reginald Braithwaite's writings on code style and why clarity is king - http://weblog.raganwald.com/2007/12/golf-is-good-program-spoiled.html
3. Hamlet D'Arcy's humorous article on the detriments of new found functional programming knowledge - http://hamletdarcy.blogspot.com/2009/08/how-to-tell-your-co-workers-have.html
There you have it, just in case you missed 'em the first time around.
Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts
Monday, February 21, 2011
Saturday, August 14, 2010
getting reacquainted with javascript
Ok, I'm admittedly a little late to the party here. Lots of people are doing really, really cool things with javascript these days.
So, I've been using rhino to whip together my java experiments lately. Setup is trivial, you just need java and js.jar.
Once you have rhino, all sorts of java-ish things can be whipped up as quick hacks.
A quick http server, for example, goes something like this:
Wait, what about a threaded server you say? Try this on for size.
For more reading about rhino and javascript including how to structure, organize, and manage your code for larger projects, try these great posts.
http://steve-yegge.blogspot.com/2008/06/rhinos-and-tigers.html
http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth
http://peter.michaux.ca/articles/javascript-widgets-without-this
http://www.jspatterns.com/
So, I've been using rhino to whip together my java experiments lately. Setup is trivial, you just need java and js.jar.
- download rhino
- extract js.jar (at least)
- for an interactive shell, run java -jar js.jar
- or run a script using java -jar js.jar some-javascript-file.js
Once you have rhino, all sorts of java-ish things can be whipped up as quick hacks.
A quick http server, for example, goes something like this:
function main() { var s = new java.net.ServerSocket(8080) while (true) { var client = s.accept() var sc = new java.util.Scanner(client.getInputStream()) var method = sc.next() var path = '.' + sc.next() var out = new java.io.PrintWriter( new java.io.OutputStreamWriter(client.getOutputStream())) try { var f = new java.io.FileInputStream(path) out.println("HTTP/1.1 200 Success") out.println("Content-Type: text/html") out.println() for (var c = f.read(); c != -1; c = f.read()) out.write(c) } catch (e if e.javaException instanceof java.io.FileNotFoundException) { out.println("HTTP/1.1 404 File not found") out.println("Content-Type: text/html") out.println() out.println("<html><body>") out.println("<h1>File not found</h1>") out.println("</body></html>") } out.flush() out.close() } } main()
Wait, what about a threaded server you say? Try this on for size.
function main() { var s = new java.net.ServerSocket(8080) while (true) { var client = s.accept() var t = java.lang.Thread(function() { var sc = new java.util.Scanner(client.getInputStream()) var method = sc.next() var path = '.' + sc.next() var out = new java.io.PrintWriter( new java.io.OutputStreamWriter(client.getOutputStream())) try { var f = new java.io.FileInputStream(path) out.println("HTTP/1.1 200 Success") out.println("Content-Type: text/html") out.println() for (var c = f.read(); c != -1; c = f.read()) out.write(c) } catch (e if e.javaException instanceof java.io.FileNotFoundException) { out.println("HTTP/1.1 404 File not found") out.println("Content-Type: text/html") out.println() out.println("<html><body>") out.println("<h1>File not found</h1>") out.println("</body></html>") } out.flush() out.close() } ) t.start() } } main()
For more reading about rhino and javascript including how to structure, organize, and manage your code for larger projects, try these great posts.
http://steve-yegge.blogspot.com/2008/06/rhinos-and-tigers.html
http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth
http://peter.michaux.ca/articles/javascript-widgets-without-this
http://www.jspatterns.com/
Monday, July 12, 2010
a survey of web visualization toolkits
I'm always on the lookout for new tools to create graphs, charts, and other visualizations. It is an obsession that dates back to my days slaving over gnuplot and R scripts (or even *gasp* metapost). Here are some more modern toolkits I've come across which lend themselves to visualizations for the web.
- Processing has to be one of my favorites, probably because I've been using it the longest.
- And if Processing isn't web-2.0-enough for you, there is always the Javascript implementation.
- Protovis - any visualization toolkit that can be used to create an interactive version of Minard’s Napoleon has to get good marks.
- Google has Chart Tools.
- Degrafa has been used to create some beautiful visualizations.
- Or there is the slightly higher-level Axiis if you prefer (which is built on top of Degrafa).
- Should you be religiously opposed to flash, you might like dygraphs
- Prefuse is another Java toolkit with some great graph and chart types
- And Flare (also from the Prefuse guys) you post those interactive visualizations to the web in flash.
Sunday, July 11, 2010
dnode - javascript remote invocation
dnode is just the latest in a serious of cool things people are doing with javascript that I find amazing. processingjs is another (albeit not very new anymore).
Wednesday, July 23, 2008
introducing jsqueeze
Not that I want to get into any js framework debates, but I've been using prototype and scriptaculous for my ajax ui toolkit recently. However, I do have to give a nod to the dojo team for their javascript compressor, shrink safe. It seems to me that any javascript compressor/obfuscator must know about the underlying structure of the language if it wants to save every last byte.
As much as I like the idea of shrink safe, I have to confess that patching the rhino javascript process doesn't seem to most elegant way to harness its power. So, with that in mind, I managed to adapt the shrink safe code to simply use the rhino api to accomplish the same task. I've called by javascript compressor jsqueeze (or jsqz for short).
Anyway, if your interested and want to give it a spin, you can download the source here.
As much as I like the idea of shrink safe, I have to confess that patching the rhino javascript process doesn't seem to most elegant way to harness its power. So, with that in mind, I managed to adapt the shrink safe code to simply use the rhino api to accomplish the same task. I've called by javascript compressor jsqueeze (or jsqz for short).
Anyway, if your interested and want to give it a spin, you can download the source here.
Subscribe to:
Posts (Atom)