Shonzilla, a pattern-seeking animal

Life is a game of patterns and chance, and those who play well will win.


Twitter

See also (via Entrecard)

programming coupons powered by RetailMeNot.com

Sun Oct 31

Command-line JavaScript beautifier implemented in JavaScript

Intro

In the the world of web programming where more things gets done in JavaScript, most of this JavaScript is directly available online. An exception is the server-side JavaScript like the one used in node.js or, less commonly known, in a OpenSocial container like Apache Shindig. Unless the license says otherwise, all this JavaScript code is free for anyone to download, fiddle with and fork/hack/improve/refactor.

For different reasons, the code is frequently post-processed in a way making it impossible to read. Enter JavaScript beautifiers. There’s plenty of them. However, they’re all on the web. Have you asked yourself “is there’s no command-line JavaScript beautifier?” so that you can most of the work from hacker’s favorite development environment. If you were looking for CLI JavaScript beautifier and haven’t found one, you came to the right page.

Ingredients

Here’s the DIY guide on how to create your own CLI JavaScript beautifier.

First, you’ll need a command-line JavaScript interpreter. Say Mozilla Rhino, JavaScript interpreter implemented in Java. I’ll assume you already have a working Java installation on your machine. Since Rhino works with any JDK 1.4 or higher, if you have any Java on your machine - you’re surely fine already.

Secondly, JavaScript beautifying itself is implemented in JavaScript just as most of the online JavaScript beautifiers rely on client-side process implemented JavaScipt. This JavaScript piece of the puzzle fits perfectly in the previous one - the JavaScript interpreter. I recommend jsbeautifier.org - JavaScript unpacker and beautifier since it’s the only I’ll use here as an example.

The last piece of the puzzle is a shell script to tie it all together.

DIY guide

Follow this steps to DIY:

  1. Download the latest stable Rhino and unpack it somewhere, e.g. ~/dev/javascript/rhino
  2. Download beautify.js which is referenced from aforementioned jsbeautifier.org then copy it somewhere, e.g. ~/dev/javascript/bin/cli-beautifier.js
  3. Add this at the end of beautify.js (using some additional top-level properties to JavaScript):
    // Run the beautifier on the file passed as the first argument. print( j23s_beautify( readFile( arguments[0] )));
  4. Copy-paste the following code in an executable file, e.g. ~/dev/javascript/bin/jsbeautifier.sh:

    #!/bin/sh

    java -cp ~/dev/javascript/rhino/js.jar org.mozilla.javascript.tools.shell.Main ~/dev/web/javascript/bin/cli-beautifier.js $*

  5. (optional)  add the folder with jsbeautifier.js to PATH or moving to some folder already there.

Usage

If you have the above script (jsbeautifier.sh) in PATH like I do, you can run it from any folder to format a JavaScript or JSON file by adding the file as the first argument: 

jsbeautifier.sh some-minified.js

where you replace some-minified.js with some JavaScript or JSON file that no normal web developer wants to read.

Outro

I see no reason why wouldn’t the same technique repurposed for other JavaScript-based services currently only found online. Some ideas come to mind: JavaScript comressing/uglifying… maybe even running YQL from the command-line.

Note that I haven’t actually tried those nor checked if there are stronger dependencies on the client-side requiring more work to repurpose the JavaScript code from the web browser into Rhino runtime.

Tue Jun 30

Hilarious internet musical… well worth the watch!

Pop quiz: Does it remind you of some people you know? ;-)

[via CollegeHumor]

Sat Apr 25
Fri Mar 20

Great stuff that your Google Chrome browser can do… most experiements won’t look as good or as fat in other web browsers. 



Have in mind that everything is implemented in HTML, JavaScript and CSS. :-)



Verdict: this is one great viral marketing campaign!



Thanks to Raša for letting me know about this and bashing Tetris within a web browser as a bleak achievement. ;-)

Great stuff that your Google Chrome browser can do… most experiements won’t look as good or as fat in other web browsers.

Have in mind that everything is implemented in HTML, JavaScript and CSS. :-)

Verdict: this is one great viral marketing campaign!

Thanks to Raša for letting me know about this and bashing Tetris within a web browser as a bleak achievement. ;-)

Fri Sep 5
Watch this comic explaining in detail features Google Chrome web browser.

Watch this comic explaining in detail features Google Chrome web browser.

Fri Mar 28

Design Coding by Poetic Prophet

Listen to the man rhyme! Yo!

Thu Feb 21

The new web browser Opera Mobile 9.5 looks (and works) great!

On a sidenote, sometimes project managers are not the best people to present their product (at least not to the general public). That guy might be considered cool by geek standards (for what he does) but certainly is not to your neighbour Joe or Jane who’d like to surf the web on their mobiles as well. :-)

What’s particularly interesting is the concept of Opera Widgets among which there are some that will surely keep any Facebook addict relaxed and happy.

In my view, mobile widgets are a very viable solution for small-screened mobile devices. What’s a mobile widget? Well, isn’t that a regular application that can be downloaded from a widget library that can be browsed from your desktop web browser as well.

[via DailyMotion]

Fri Feb 15
Every Web2.0 afficionado should have a look at this: Web Trend Map 2008.The brilliant people at Information Architects selected nearly 300 of the most influential and successful websites and layered them over the greater Tokyo-area train map. Looks great and it’s a great reference too.All of you Web2.0 addicts may use this as your del.icio.us 2.0. ;-) You can download a PDF (A3 format) or check out the clickable online version. Within a week, you will be able to obtain a huge poster (A0 format!) version of it. You can preview its prominent features in detail too.  [via informationarchitects.jp]

Every Web2.0 afficionado should have a look at this: Web Trend Map 2008.

The brilliant people at Information Architects selected nearly 300 of the most influential and successful websites and layered them over the greater Tokyo-area train map. Looks great and it’s a great reference too.

All of you Web2.0 addicts may use this as your del.icio.us 2.0. ;-)

You can download a PDF (A3 format) or check out the clickable online version. Within a week, you will be able to obtain a huge poster (A0 format!) version of it. You can preview its prominent features in detail too.

[via informationarchitects.jp]