| Books & Tools | Techniques | |
JudeJude is my Java documentation browser. It combines Sun's definitive javadocs with the easy-to-use format of Java in a Nutshell, and tops it off with easy keyboard-based navigation and full-text searching. Jude is available for free evaluation. See the user's guide for more info Java in a NutshellThe 5th edition is now out, with complete coverage of Java 5.0! It includes a fast-paced tutorial on the language, and a compact quick-reference for the core Java API. Java Examples in a NutshellThe 3rd edition, updated for Java 1.4 This edition has all-new coverage of the NIO and JavaSound APIs, completely rewritten Servlets and XML chapters, and coverage of new Java 1.4 features (assertions, logging, preferences, SSL, etc.) added througout. A great book for those who like to learn by example. 193 working examples: 21,900 lines of carefully commented code to learn from. JavaScript: The Definitive GuideThis is my JavaScript bestseller. It has been called the "bible" for JavaScript programmers. Brendan Eich, the creator of JavaScript called it a "must-have reference". Java 1.5 Tiger: A Developer's NotebookAmazon incorrectly credits me as the main author on this book. I'm actually the second author: really more of a consultant. This is a good book about all the language changes in the latest version of Java. Effective JavaI didn't write this excellent book, but I wish I had. Author Josh Bloch is probably best known for the collections classes in the java.util package. His experience and wisdom are apparent in this book. I learned from it and recommend it highly. |
November 04, 2005Amazon Commodifies Human IntelligenceAmazon has a new web service which they call Mechanical Turk, after a fake chess playing robot from the 18th century. Amazon describes it like this:
Most of the task available for completion today involve looking at a set of streetscape photographs and picking the one that is the best picture of a specified business. For completing such a task, you can earn 3 cents. For the more ambitious, you can help Amazon re-catalog the automotive parts they sell, earning 40 cents for re-writing the title and bullet points for a custom license plate holder or a exhaust tube extension. At first I was intrigued by this. Interesting use of technology. (There's even an API for it: hey, I could use Mechanical Turk tasks as a captcha for blog comments, and readers would earn money for me...) Free market goodness. And as Amazon says:
What's not to like? Then I noticed Amazon's subtitle for the Mechanical Turk service: "Artificial Artificial Intelligence". That seems a little creepy. Reducing humans to cheap computing power. But don't think I'm reading too much into this. Here are two paragraphs from the FAQ:
I don't know if I'm more disturbed by the philosophical implications of this Matrix-lite inversion of control, by the commodification of intelligence it represents, or by the implications for workers rights. A system like this will just accelerate the race to the bottom: even offshore worker's jobs won't be safe. Heck, they could probably train pigeons to do some of the image recognition tasks they're currently paying 3 cents for. 3 cents probably buys a lot of pigeon pellets. I'm not qualified to really critique Mechanical Turk the way it needs to be critiqued. Perhaps former O'Reilly editor Steve Talbot will write about it in his wonderful NetFuture newsletter. Mechanical Turk is still a beta service. I hope it fails. October 24, 2005java.io.ConsoleBuild 57 of Java 6 includes a new class java.io.Console. Javadocs are at the link above. And you can also leran more at Alan Bateman's blog . Highlights:
October 13, 2005Client side sparkline imagesSparklines are a new graphical concept championed by Edward Tufte, author of a number of very cool books that you have probably already heard about. Sparklines are an idea from his forthcoming book, and he explains them in a draft chapter from that forthcoming book at sparklines.org. If you're using a browser that understands the data: URL, here's an example of a sparkline:
Note, that this particular sparkline is hard-coded in this blog entry. The demos below show how they are dynamically generated. As part of my newfound obsession with client-side drawing techniques (I really think it could change the web) I've created a way to generate sparkline images using client-side Java and JavaScript. This is proof-of-concept stage, but if you're running Firefox and have the Java plugin installed, click on these links to try out the demos:
You'll need to understand both Java and JavaScript to make use of this stuff. But if it interests you, you can use my code for any purpose as long as you attribute it to me. October 12, 2005Flash for client-side vector graphics!In my previous entry, I asked about the possiblity of using Flash as a vector graphics engine, for scripting by client-side JavaScript code. With help from Geoff Stearns and his blog Deconcept I've figured out how to do it. I've figured out how to do it in Flash 8, at least. Flash 8 has a new ExternalInterface API that transparently makes ActionScript methods callable from JavaScript. (It is possible, though not nearly so simple to do similar things in earlier versions of Flash.) Here is my trivial ActionScript file, which I named Canvas.as:
import flash.external.ExternalInterface;
class Canvas {
static function main() {
Stage.scaleMode = "noScale";
Stage.align = "TL";
ExternalInterface.addCallback("beginFill", _root, _root.beginFill);
ExternalInterface.addCallback("beginGradientFill", _root,
_root.beginGradientFill);
ExternalInterface.addCallback("clear", _root, _root.clear);
ExternalInterface.addCallback("curveTo", _root, _root.curveTo);
ExternalInterface.addCallback("endFill", _root, _root.endFill);
ExternalInterface.addCallback("lineTo", _root, _root.lineTo);
ExternalInterface.addCallback("lineStyle", _root, _root.lineStyle);
ExternalInterface.addCallback("moveTo", _root, _root.moveTo);
}
}
I compiled this code with the open-source mtasc ActionScript compiler like this: mtasc -swf Canvas.swf -main -version 8 Canvas.as This produced the file Canvas.swf which you can download by clicking the link. The ActionScript code doesn't do anything except make the Flash drawing API accesible to JavaScript. If you embed this SWF file in your web page, it is simply blank, until you draw something to it yourself. Here is a demo:
<embed src="Canvas.swf" quality=high bgcolor=#FFFFFF width="400" height="200"
name="canvas" align="" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer">
<p><button onclick="draw()">Draw in the Canvas</button>
<script>
function draw() {
document.canvas.beginFill(0xAAAAFF, 100);
document.canvas.lineStyle(5, 0x0000FF, 100);
document.canvas.moveTo (10, 10);
document.canvas.lineTo (200, 100);
document.canvas.lineTo (10, 190);
document.canvas.lineTo (10, 10);
document.canvas.endFill();
}
</script>
This demo uses the <embed> tag instead of the <object> tag, so it won't run in IE. But I have tested it in Firefox, and it works. But only if you have Flash 8 installed. And Flash 8 is not available for Linux yet. If you've got Flash 8 running in Firefox (or Safari?) give the demo a try! Comments, suggestions, improvements, or whatever are very welcome. I plan to tweak Canvas.as a bit to expose methods for adding text, but I think that will be straightforward. I was disappointed to discover that the Flash drawing API is not nearly as robust as that of the <canvas> tag or of SVG of VML. In particular all curves must be done with quadratic beziers. Cubic beziers, circles, arcs and so on must all be approximated with a single curveTo() function. So it might be worth adding some basic shape-drawing primitives (circles, rounded rectangles, etc) to Canvas.as as well. Feel free to use this code (and the swf file) for any purpose, with attribution. October 11, 2005Flash for client-side vector graphics?I know very little about Flash, but it seems to me that it would make a good substitute for the <canvas> tag as well as SVG and VML. From a basic perusal of the Macromedia web site, it appears that it is possible for client-side JavaScript to communicate with the ActionScript interpreter in the Flash plugin. If so, JavaScript ought to be able to get ActionScript to draw lines, curves, and do other vector-graphics type things. ActionScript has an eval() function. I would think that it would be possible to create a tiny SWF file that does nothing more than define a hidden TextField object and an onChanged event listener for that field. The event listener would take the new value of the TextField and pass it to eval(). Client-side JavaScript would then set the value of the TextField with the TSetProperty method that is exported by the Flash player. And voila! Client-side JavaScript can then make pass arbitrary ActionScript commands to the Flash Player. This gives us scriptable client-side vector graphics that work anywhere Flash is installed. Can anyone tell me why this wouldn't work? Is anyone already doing it? If you make this work and release your code openly, you'll get a link and an attribution in the next edition of my JavaScript book! September 21, 2005account migrationThis website is migrating to a new server. While the new DNS propagates, the site may go down for a bit, and my email may bounce. Just a temporary disruption, however!Update: well, that was harder than it should have been. I think everything is working again, but please let me know if you find any flakiness on my site. August 29, 2005Canvas tag in Java and XBLI think 2D graphics are a lot of fun, and have always loved the Java2D API. How cool is it, then, that Safari includes and Firefox 1.5 will include a new <canvas> tag that exposes a drawing API very, very similar to the Java2D API? The canvas tag has the potential to revolutionize a lot of web applications. But for this to happen, it needs to be ported to browsers other than Safari and Firefox 1.5. I'm sure it can be done for IE, somehow, but I don't want to tackle that right now. Instead, my contribution is to begin implementing the canvas tag for Firefox 1.0 using a Java applet and Mozilla's XBL binding language. This is just at proof-of-concept stage, but it is usable enough to make simple demos work. The java applet and XBL files are here. The canvas.html file in that directory is a simple demo. It doesn't seem to work online, but if you copy the files to a local directory, it should work. (I suspect, but don't know, that XBL bindings have to be installed locally to work for security reasons.) To use this, compile the .java file to a .class file. Then define a simple stylesheet that tells Firefox to use the canvas.xbl file to implement the canvas tag. This is what I use:
<style>
canvas {
-moz-binding: url('canvas.xbl#canvas');
display:block;
}
</style>
Anyone want to take over work on this? You need to know Java and JavaScript, and know more about XBL than I do. And if you know something about whatever IE uses instead of XBL, that would be a big help, too... Drop me a line if you're interested! August 23, 2005XMLHttpRequest with <script> and PHPHere is a very simple XMLHttpRequest utility function:
/**
* Use XMLHttpRequest to fetch the contents of the specified URL using
* an HTTP GET request. When the response arrives, pass it (as plain
* text) to the specified callback function.
*/
HTTP.getText = function(url, callback) {
var request = HTTP.newRequest();
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) callback(request.responseText);
}
}
request.open("GET", url);
request.send(null);
};
This function assumes the presence of a HTTP.newRequest() function to abstract away the differences in creating an XMLHttpRequest object in IE and other browsers. (You've seen a function like this in every Ajax utility library you've looked at...)
Since XMLHttpRequest uses ActiveX in IE, it is unavailable if the user has disabled ActiveX for security reasons. In this situation, we can try to fall back on other means of scripting HTTP. Both <iframe> and <script> tags have src attributes that can generate HTTP GET requests when dynamically set. Let's start there and see if we can use these tags to create an analog to the HTTP.getText() method shown above. (Full compatibility with XMLHttpRequest is not possible with these techniques, however.)
|
Advertising
About
Search
Archives
November 2005
October 2005 September 2005 August 2005 July 2005 June 2005 April 2005 March 2005 February 2005 December 2004 October 2004 September 2004 July 2004 June 2004 May 2004 April 2004 March 2004 February 2004 January 2004 Syndicate
|
