HD Timelapse from Our Apartment Window
My roommate Charlie recorded this with his new MinoHD.
I think he should do another timelapse for Bay to Breakers, which runs right through that intersection. (why that might be interesting)
Trader Joe’s Song
Austinites, other Texans: This is where I get my snack foods. If this company were public I’d buy stock.
The Onion vs. W
I might share The Onion’s harsh feelings towards our outgoing commander-in-chief, but this series of articles is strange:
- Spider Eggs Hatch In Bush’s Brain
- Single-Engine Cessna Crashes Into Bush
- Bush’s Eyelid Accidentally Nailed To Wall
- Bush Dragged Behind Presidential Motorcade For 26 Blocks
I guess it’s funny, but it’s schadenfreude without a punchline, and that feels more like a satirical voodoo doll than a joke.
Not that there’s anything wrong with that.
MapReduce with JavaScript, and My New Blog: dashdashverbose
I’ve started a new blog, dashdashverbose, where I will be putting my geekier code-related entries from now on.
I’m splitting the CS geekery off because I get one consistent piece of feedback from people who actually offer feedback on this blog: “It’s interesting except for the technical posts- I don’t get those so I just scroll past ‘em.”
The name “dashdashverbose” comes from a command line option used by unix-like applications: “- -verbose” usually tells the app to spit out as much information about what it’s doing as it can. The output is typically a firehose of technical details that only a few people care about.
Kinda like my geekier posts :)
The inaugural –verbose entry is about how to run MapReduce with JavaScript.
SmorgasBorges: The Improbable Impostor Tom Castro
[Second in a series]
Summary
An idiot who goes by the adopted name Tom Castro is befriended by a black man in Australia named Ebenezer Bogle. Bogle is some kind of genius, but he is haunted by the fear of being hit by a car so he has trouble crossing streets.
Castro ad Bogle read in the paper about this english guy Roger Charles Tichborne who disappeared with a sinking ship. The article says Tichborne’s mother is convinced that her son was not on the ship and is still alive.
Bogle devises a plan to have Castro pose as the lost Tichborne. They travel to the London to present themselves to Tichborne’s mother. Castro looks nothing like Tichborne, and doesn’t even speak French, as Tichborne did fluently. The mother believes Castro to be her son regardless, but the rest of the family objects.
Creditors who are owed money insist that Castro is Tichborne, helping to build Bogle’s case.
Bogle gets hit by a car.
Without Bogle masterminding the charade, Castro is caught and convicted.
Commentary
When I see a “Lost Dog” sign I want to do this:
- Write the phone number down and wait a year.
- Call to verify that they still haven’t found the dog.
- Go to the animal shelter and find a dog that closely resembles the one in the photo.
- Train it to go by the name of the lost dog.
- “Return” it.
How to Play Guitar (or Customize Your Profile Page)
If you’ve ever worked on or with an application that lets users customize the look and feel (or any sufficiently user-customizable application for that matter): this might uh, strike a chord with you.
How to Play Guitar by David Fair:
Tuning the guitar is kind of a ridiculous notion. If you have to wind the tuning pegs to just a certain place, that implies that every other place would be wrong. But that’s absurd. How could it be wrong? It’s your guitar and you’re the one playing it. It’s completely up to you to decide how it should sound. In fact I don’t tune by the sound at all. I wind the strings until they’re all about the same tightness.
[Thanks Shawn]
js.Processing with Rhino
Processing.js: Processing in JavaScript
A few months ago JavaScript Ninja John Resig unleashed processing.js. Like many others I was shocked and amazed. I love to tinker with Processing, and I also do a fair amount of JavaScript work, so I was keenly interested.
There are some limitations to using the browser for the type of work people want to do with Processing though. Processing.js is even slower than Processing applets, and it’s not even a full implementation.
However, I am intrigued by the use of JavaScript to do Processing-like stuff.
js.Processing: JavaScript in Processing
The Processing language inherits some unfortunate (and personally annoying) features of Java since that’s what it compiles down to.
I actually prefer JavaScript to the Processing language because it’s loosely typed and has some other nifty features.
I’d like to be able to use all of Processing’s capabilities (not the crippled applet variety), AND program with JavaScript instead of Processing’s language.
cake.have().eat();
So today I created a .pde that loads Rhino, creates a JavaScript execution context, stuffs itself into that context, loads an external javascript file and runs it.
And js.Processing is born.
I added some functions to proxy the built-in Processing callbacks so you can write “draw(){}” and “mouseDragged(){}” in javascript and they do what you’d expect.
Here’s the main shell Processing sketch that runs the Javascript (listing below):
/**
* Experiment to drive Processing with JavaScript.
* Uses Rhino: https://developer.mozilla.org/en/Rhino_Overview
* This does not currently work in an applet due to some Rhino issues
* with class loading and optimization.
*
* This class itself isn't where you put the javascript. .js files
* should go in your processing project's code/ folder. Load your .js
* script explicitly in setup() below. This example is hard-coded to
* laod "guilloches.js", an example I ported from regular Processing
* but you can set it to whatever file name you want.
*
* This class just forwards calls from Processing into your javascript code.
*
* To access Processing methods in javascript, prefix them with "p5." -
* I'm looking at how to make those functions global, if that's possible.
*
* author: Sean McCullough banksean@gmail.com
*/
import org.mozilla.javascript.*;
Context cx;
Scriptable scope;
Function jsInit;
Function jsDraw;
Function jsMouseDragged;
Function jsMousePressed;
Function jsMouseReleased;
Function jsKeyPressed;
Function jsKeyReleased;
void setup() {
cx = Context.enter();
// TODO: make this work so it can run in an applet. Because optimization levels 0 and higher do classLoader voodoo,
// the browser seems to object. Setting it to -1, however, makes JavaAdapter no workie and that makes this exercise
// even more useless.
// cx.setOptimizationLevel(-1);
scope = cx.initStandardObjects();
size(400, 400);
// String[] globalNames = {"log"};
// TODO: make this work so global functions don't need to be prefixed with p5.whatever.
// scope.defineFunctionProperties(globalNames, Class.forName("jstest.JSProcessing"), ScriptableObject.DONTENUM);
Object wrappedThis = Context.javaToJS(this, scope);
// p5 is the global "Processing" object available to your scripts. Prefix any processing api calls with "p5." or they
// won't work.
ScriptableObject.putProperty(scope, "p5", wrappedThis);
String srcStrings[] = loadStrings("guilloches.js");
String src = "";
for (int i=0; i<srcStrings.length; i++) {
src += srcStrings[i] + "\n";
}
cx.evaluateString(scope, src, "<cmd>", 1, null);
jsInit = getFunction("init");
jsDraw = getFunction("draw");
jsMouseDragged = getFunction("mouseDragged");
jsMousePressed = getFunction("mousePressed");
jsMouseReleased = getFunction("mouseReleased");
jsKeyPressed = getFunction("keyPressed");
jsKeyReleased = getFunction("keyReleased");
jsInit.call(cx, scope, scope, null);
}
Function getFunction(String name) {
Object o = scope.get(name, scope);
if (o instanceof Function) { return (Function) o; }
return null;
}
void draw() {
callIfNotNull(jsDraw);
}
void mouseDragged() {
callIfNotNull(jsMouseDragged);
}
void mousePressed() {
callIfNotNull(jsMousePressed);
}
void mouseReleased() {
callIfNotNull(jsMouseReleased);
}
void keyPressed() {
callIfNotNull(jsKeyPressed);
}
void keyReleased() {
callIfNotNull(jsKeyReleased);
}
void callIfNotNull(Function f) {
if (f != null) {
f.call(cx, scope, scope, null);
}
}
public void log(String str) {
System.out.println(str);
}
//////////////////// Begin overloaded global functions //////////////////////
public void stroke(String cr) {
stroke((Integer)colors.get(cr));
}
public void fill(String s) {
fill((Integer)colors.get(s));
}
HashMap colors = new HashMap();
/**
* Rhino/Javascript don't support long types. In processing, a color object is
* represented by a long, so we have a problem. This method proxies color() to
* return a JS-safe reference to a processing color value.
* See:
* http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/FunctionObject.html
* Also, it's called getColor() instead of color() because processing won't let
* me override that method name. Probably has something to do with it being a
* reserved word as well as a method/class. Should probably just replace this
* with a hex string of the color values.
*/
public String getColor(int r, int g, int b, int a) {
color c = color(r,g,b,a);
colors.put("" + c, c);
return "" + c;
}
Here’s what my Guilloches sketch looks like, re-implemented in js.Processing:
function init() {
p5.smooth();
p5.background(255);
// NOTE: have to use getColor() instead of color()
// because JavaScript is retarded about Longs, which color() returns.
var c = p5.getColor(0, 0, 0, 64);
p5.stroke(c);
p5.frameRate(10);
p5.strokeWeight(0.5);
p5.strokeCap(p5.SQUARE);
}
var lastSet = false;
var lastX = 0;
var lastY = 0;
var dTheta = 0.0004 * p5.PI;
var theta = 0.0;
var R = 50.0;
var r = -0.25;
var p = 25.0;
var m = 1;
var n = 6.00;
var Q = 0;
function mousePressed() {
drawStuff();
}
function mouseDragged() {
drawStuff();
}
function draw() {
if (!lastSet) drawStuff();
}
function drawStuff() {
var mx = 2.0*(p5.width/2.0-p5.mouseX)/p5.width;
var my = 2.0*(p5.height/2.0-p5.mouseY)/p5.height;
if (lastSet)
Q = (50*Math.sqrt(mx*mx + my*my));
var Rr = R + r;
var rp = r + p;
p5.background(255);
var mTheta = m*theta;
var mThetaRrr = m*theta*Rr/r;
var nTheta = n*theta;
var x;
var y;
var plotX;
var plotY;
for (var i=0; i<15000; i++) {
theta += dTheta;
mTheta = m*theta;
mThetaRrr = m*theta*Rr/r;
nTheta = n*theta;
x = (Rr)*Math.cos(mTheta) +
(rp)*Math.cos(mThetaRrr) +
Q*Math.cos(nTheta);
y = (Rr)*Math.sin(mTheta) +
(rp)*Math.sin(mThetaRrr) +
Q*Math.sin(nTheta);
plotX = (p5.width/2 + (x/125)*p5.width/2);
plotY = (p5.height/2 + (y/125)*p5.height/2);
if (!lastSet) {
lastSet = true;
lastX = plotX;
lastY = plotY;
}
p5.line(lastX, lastY, plotX, plotY);
lastX = plotX;
lastY = plotY;
}
}
I’m not really taking advantage of JavaScript language features much here (besides not having to worry about variable types) but it proves the concept.
I haven’t done any formal performance tests, but this seems to run slower than the original.
Download the js.Processing Project .zip Here
The JavaScript source code is in the data/ folder (since it’s loaded as an external resource).
Of course I imagine there’s an easier way to go about this, especially if one were to actually modify the Processing source code itself to accommodate JavaScript/Rhino.
SmorgasBorges: The Cruel Redeemer Lazarus Morell
[I'm attempting to write a quick summary of every Borges story I read from now on. I was introduced to this author only a couple of years ago, and I wasn't a Lit major in college so don't expect anything erudite.
Why I think Borges is a good author: I don't have the attention span to read entire books. I have had a life-long battle with TL;DR. Unfortunately I also like stories that include really big ideas, the kind that usually take a long time to explain.
Borges' big (twisted, maze-like) ideas for stories and extreme economy of words has a solid track record of blowing my mind in twelve pages or less.
I tend to forget things unless I write them down, so I figured I'd share what I remember.
His stories are mostly published in collections. The one I'm starting with is Collected Fictions.
I couldn't think of a good name for this (hopefully) series, so I'm calling it SmorgasBorges instead.]
First up is “The Cruel Redeemer Lazarus Morell”
This story takes place during the days of slavery in the south. Lazarus is a criminal mastermind who has a loyal following of about 1000. Sort of like a mafia boss. Their racket is truly wicked.
Lazarus has “Strikers” whose mission is to offer freedom to slaves who wish to escape. The slave is told that if he runs away from his current master and lets the the Striker sell him to another master, the Striker will help him escape again and then they’ll split the money from his sale. Sounds good right? Get your freedom and some cash.
The deal, of course, is raw.
They don’t offer to just let him go free on the second “escape.” They say they need more money for unanticipated expenses that suddenly came up, so they have to sell him again. The slave would eventually try to escape on his own, only to be recaptured and beaten. Eventually the Strikers would give the slave his final freedom.
Profiting from crushing a slave’s hope for freedom is particularly cruel when you have an active hand in instilling that hope.
But Lazarus’ grade-A douchebaggery doesn’t stop there. By law, when a slave owner posts a reward for a runaway slave, anybody can claim him. So he’d wait until the reward was posted before trying to sell the slave again. That way it wasn’t a crime, just a breach of etiquette for him to sell the slave to another master.
He does a few more incredibly awful things in this story but that’s the one that gets the most description.
Slit-Scan Slinky Bass with Processing
More fun with slit-scan video in Processing.