Posts

Showing posts from August, 2011

OS X Lion Automator And Mobile NOKIA Maps

When I have read this article about Making Desktop Webapps in Lion my first thought was " cool! " instantly followed by " what about an experiment with Mobile NOKIA Maps WebApp? " ... and here I come :) m.maps.nokia.com is the beta project I am working on right now together with a bounce of HTML5 geeks :P in order to bring the mature NOKIA Maps experience on Android 2.2+, iOS4+, and others already supported or " coming soon " devices. Optimized for mobile but still usable with Desktop Chrome or Safari browser, the web app is quite " cute " seen in iPhone or other medium and small screens and this experiment was about bringing same " cuteness " on my Mac Mini as well: partially successful! Lion Automator And WebPopup Limits Unfortunately it is not possible to customize that much the popup browser user agent and I am not even sure what kind of engine is used there ... With iPhone UserAgent the version exposed is 3 and Webkit 430+ . W...

Simulate Script Injection Via Data URI

Well, not only downloads on the fly , the data uri works for almost everything ( only iOS 5 beta does not want to work with inline data uri AUDIO sources .... but this is another story ... ) ... so ... How To Simulate Script injection Let's say you want a test but you don't want to bother a server. However, you want to be sure the test is asynchronous and it simulates the server. var head = document.getElementsByTagName("head")[0], script = document.createElement("script") ; head.insertBefore(script, head.lastChild); script.src = "data:text/javascript;base64," + btoa( "alert('Hello World')" ); How To Simulate JSONP Same trick, isn't it? ... except: script.src = "data:text/javascript;base64," + btoa( "callback(" + JSON.stringify(dummyData) + ")" ); How To Drop Server Requests well, this is the tricky one ... Surely there is some job to do in the createResponse() function but ... he...

wru, unit tests have ever been that easy

Do you remember my good old wru project ? It has been refactored , readapted for both client and server side environment such node.js and Rhino and, most important, it landed in github ;) Please spend few minutes to read the documentation and you'll realize why I chose this title for this post. Have fun with JavaScript Unit Tests!

Overloading the in operator

In all its " sillyness ", the CoffeeShit project gave me a hint about the possibilities of an overloaded in operator . The Cross Language Ambiguity In JavaScript, the in operator checks if a property is present where the property is the name rather than its value . "name" in {name:"WebReflection"}; // true However, I bet at least once in our JS programming life we have done something like this, expecting a true rather than false . 4 in [3, 4, 5]; // false // Array [3, 4, 5] has no *index* 4 The Python Way In Python, as example, last operation is perfectly valid! "b" in ("a", "b", "c") #True 4 in [3, 4, 5] # True The behavior of Python in operator is indeed more friendly in certain situations. value in VS value.in() What if we pollute the Object.prototype with an in method that is not enumerable and sealed? No for/in loops problems, neither cross browsers issues since if it's possible in our target ...

CoffeeShit, The CoffeeScript Parody

Image
... because script happens! This silly project does not want to offend the CoffeeScript creator neither any CoffeeScript user, hoping both have sense of humor :D About Every cult movie has one or more parodies ... well, every cult technology as well (or at least it should)! This idiotic project is on github with a better explanation, a suite of unit tests, and both source code and the partially manually minified one ( manually because I have discovered a nice bug with closure compiler and eval there ... ) About The Name You can check the library by yourself and realize I have used all worst possible practices in order to simulate a different syntax within the one allowed by JavaScript. Such pile of shit I wrote to mimic an excellent project as CoffeeScript is could not have a better name, imo. If you feel insulted by this idiotic experiment please let me know and I'll do my best to let people try it under a different name. Example // CoffeeScript square = (x) -> x * x ...

HTML5: How To Create Downloads On The Fly

this is a quick one I have implemented already in fuckn.es in the create angry memory button logic ... The New Download Attribute Hopefully soon, most updated browser will implement the download attribute in hypertext links (aka: <a> tag) The quick summary is this one: The download attribute, if present, indicates that the author intends the hyperlink to be used for downloading a resource. The attribute may have a value; the value, if any, specifies the default filename that the author recommends for use in labeling the resource in a local file system. And this is a basic example: click here to <a href="resource234.txt" download="license.txt" > download the license </a> What Is Download For Well, I am pretty sure you have read at least once in your life this kind of extra info beside a link: right click to download the content and "Save As ..." Moreover, I am pretty sure you have created at least once in your server a page ...

JSONH And Hybrid JS Objects

Image
I have already described JSONH and now I also have the proof that it's as safe as native JSON is but on average 2X faster than native JSON operations with both small (10 objects), medium (100 objects), and massive (5000 objects and not a real world case, just a stress test to see how much JSONH scales) homogenous collections. Wherever it's not faster it's just " as fast " but the best part is that it seems to be always faster on slower machines ( mobile ). Moreover, the 5000 objects stress example shows that JSONH.stringify() produces a string with 54% of original JSON.stringify() size so here the summary: JSONH is faster on both compression and decompression plus it produces smaller output yeah but ... what About Hybrid Objects To start with, if you don't recognize/understand what is an homogenous collection and ask me: " what about nested objects? ", all I can do is to point you out that Peter Michaux explained this years before me. Have a ...

Last Version Of JSON Hpack

Update created github repository with (currently) JavaScript, PHP5 and Python versions. Update after quick chat on twitter with @devongovett who pointed out there is a similar standard called JSONDB I have created a JSONH(Flat) version . It looks slightly faster on mobile so I may opt for this one rather than Array of keys at index 0. The whole array is flat and it changes from [{a:"A"},{a:"B"}] to [1,"a","A","B"] where the empty collection would be [0] rather than [[]] . Also more details here on how to JSONH Hybrid JS Objects . A while ago I proposed a homogeneous collections optimizer nick named JSON.hpack . What I wasn't expecting is that actually different projects and developers adopted this technique to shrink down JSON size. Basic Advantage Of JSON.hpack Gzip and deflate work really good with repeated chunks of strings and this is why homogeneous collections have really good compression ratio there. However, gzip...

Once Again On Script Loaders

It's a long story I would like to summarize in few concrete points ... Three Ways To Include A Script In Your Page First of all, you may not need loaders at all. Most likely you may need an easy to go and cross platform build process, and JSBuilder is only one of them. The Most Common Practice This way lets users download and visualize content first but it lets developers start the JS logic ASAP as well without mandatory need to set DOMContentLoaded or onload event. <!doctype html> <head> <!-- head content here --> </head> <body> <!-- body content here --> <script src="app.minzipped.js">/* app here */</script> </body> </html> The "May Be Better" Practice I keep saying that a web application that does not work without JavaScript should never be accessed by a user. As example, if a form won't submit without JavaScript what's the point to show it befor...

How To JSONP A Static File

Update I have discussed this object a part and I agree that the url could be used as unique id as well. In this case the server should use the static url as unique id: StaticJSONP.notify("http://cdn.com/static/article/id.js",{..data..}); So that on client side we can use the simplified signature: StaticJSONP.request( "http://cdn.com/static/article/id.js", function (uid, data) { } ); The callback will receive the uid in any case so that we can create a single callback and handle behaviors accordingly. The script has been updated in order to accept 2 arguments but, if necessary, the explicit unique id is still supported. Under the list of " incomplete and never posted stuff " I found this article which has been eventually reviewed. I know it's " not that compact " but I really would like you to follow the reason I thought about a solution to a not so common, but quite nasty, problem. Back in 2001, my early attempts to include cal...

Please Stop Reassigning For No Reason!

Image
I swear it is was a short one but a must write and yes, once again, since I keep seeing this kind of mistake everywhere! This is not about JavaScript, this is about programming whatever language you want ... if you do this, you are doing it wrong! The Problem JS Engines developers are desperate ! They are even posting how to help JIT compilers to go faster and developers seem to be so lazy that even most basic good practices are avoided. Performances a part, this pattern can be also dangerous , specially in this ES5 era where getters and setters are extremely common, specially on mobile browsers where nobody cares about IE gap. I am looking at you only if you are still writing something like this in your code: window.whatever = window.whatever || { /* the whatever it is, object, function, anything */ }; where window is just the generic object example. OMG, What Can Be Wrong ... Everything! Any object property could be a native or user defined setter. In this case above techni...

Neu!

Image
Some new photos up for those interested. More to come in the future. Big thanks to Nikki Sneakers , Maxim Ryazansky , Eric Phipps , Brock Fetch , and Kevin Faulkner for always shooting great photos. Tour starts on Thursday night in Brooklyn @ 538 Johnson Ave with Nomos, Brain F, Only The Messenger, and Face The Rail. We will have 2 new shirt designs as well as more Immaculada shirts, the Leave Home LP on Sacred Bones Records, and the repress of the Immaculada LP on Deranged Records. Almost all tour dates are finalized and you can check those out to your left. Also, updated/fixed the discography section. Smell ya later, New York City...

bit.ly bookmarklet

bit.ly offers a proper sidebar bookmarklet but you need to sign in so, if you are really lazy and you want an easy way to shorten whatever page you are visiting, drag and drop next link into bookmarks and click it once whenever you want. bit.ly shortener enjoy :)