Javascript – Is an Object Empty?

To check if an object is empty in Javascript:

Object.getOwnPropertyNames(obj).length === 0;

Where obj is the object you’re testing e.g.:

var obj = {};
Object.getOwnPropertyNames(obj).length === 0; //true

obj = {'not' : 'empty'};
Object.getOwnPropertyNames(obj).length === 0; //false

Or to wrap it in a function:

function isEmpty(obj){
    return (Object.getOwnPropertyNames(obj).length === 0);
}

This only works in ECMAScript 5 compatible browsers, so is useful when developing mobile / desktop web apps.

Katamari Hack


The winner of the 2011 Yahoo HackU contest at University of Washington, this is so cool.

Click here to activate the Katamari Damacy effect.

You can also install it as a bookmarklet by dragging: Katamari to your bookmarks bar.

It uses CSS3 transforms and html5 canvas to do this awesome effect.

Hats off to the developers, this works seamlessly. Checkout the javascript source code to see how they’re doing it or find out more on kathack.com

Site Seeing – Week Four

Google Font Directory

https://fonts.google.com/

Bit late to the party with this one, but the Google Font Directory has some great open source fonts that can be included in your webpages incredibly easily. They host the whole solution and it’s a few basic lines of CSS to get some fancy fonts on your site. My personal favourites include Inconsolata and Lobster.

Experimental Gummy Bear Surgery

http://www.likecool.com/Experimental_Gummy_Bear_Surgeries–Other–Gear.html

Some great gummy bear transpants!

Experimental Gummy Bear Surgeries

Experimental Gummy Bear Surgeries

For Zebras

http://spudcomics.com

Think the photo says it all, check out Spud Comics for more.

For zebras it's not a party until someone brings the barcode scanner cartoon

by Lonnie Easterling

Fullscreen HTML5 Video in Safari via JavaScript

In Safari 5 HTML5 videos played in the <video> tag can now be made fullscreen, if you’re using the default controls then a button is available, but if you’re overriding them with a custom control you can use:

webkitEnterFullScreen();

This needs to be called on the video tag element, for example, to fullscreen the first video tag on the page use:

document.getElementsByTagName('video')[0].webkitEnterFullscreen();