Rough Book

random musings of just another computer nerd

Month: September, 2010

Zen Magnets vs. Buckyballs or Buckyballs, meet the Streisand Effect

Buckyballs and Zen Magnets make nearly identical magnetic toys. Zen Magnets started a campaign where they sold both sets on eBay and asked customers to compare. Buckyballs CEO responded with a legal threat, and Zen Magnets posted a video on YouTube responding to their threat, showing how to compare the quality of both the toys. Buckyballs sent a DMCA takedown notice (a completely frivolous one) to YouTube and YouTube removed the video. Zen Magnets sent a counter take-down notice, but the video still hasn’t come back up.

But no need to fear. Buckyballs is quickly going to be educated on the Streisand Effect. Here is a mirrored video:

Also, here is an mp4 for download.

Anonymous self-invoked recursive-function in Javascript

I needed to do an n-ary tree traversal recently with some Javascript code that I’m working on and I initially wrote an iterative n-ary tree-traversal algorithm (using a node stack with a while loop). I wanted to keep track of some extra (depth-dependent) data during the traversal and I didn’t like the way I was forced to do it with the iterative algorithm. I also didn’t feel like adding a new function to the namespace. Then I realized that you can create function-literals in Javascript and self-invoke them. So I ended up with the an anonymous self-invoked recursive function. Here’s the basic skeleton for an n-ary tree traversal (this one is pre-order):

(function(node){
for(var i = 0; i < node.children.length; i++) { console.log(node.data); arguments.callee(node.children[i]); } }(root)); [/sourcecode] You can also do a binary tree traversal (this one is also pre-order): [sourcecode="javascript"] (function(node){ if(node != null) { console.log(node.data); arguments.callee(node.left); arguments.callee(node.right); } }(root)); [/sourcecode] Seems very elegant and also very Lisp-like to me (must be the parentheses!)

All original content on these pages is fingerprinted and certified by Digiprove
%d bloggers like this: