Posts

Showing posts from October, 2011

On User Agent Sniffing

Oh well, who was following me on twitter today is already bored about this topic (I guess) but probably other developers would like to read this too so ... What Is UA Sniffing UserAgent sniffing means that a generic software is relying into a generic string representation of the underlying system. The User Agent is basically considered a unique identifier of " the current software or hardware that is running the app ". In native applications world UA could be simply the platform name ... where if it's " Darwin " it means we are in a Mac platform, while if it's Win32 or any other " /^Win.*$/ " environment, the app reacts, compile, execute, as if it is in a Windows machine ... and so on with Linux and relative distributions. The "Native" Software Behavior If you have an hybrid solution, example those solutions not allowed anymore but called Hachintosh not long time ago, your machine has most likely Windows Starter capable Hardware but it

JS getCSSPropertyName Function

I was re-checking @LeaVerou talk at jsconf.eu looking forward to see mine there too to understand how to improve and specially what the hell I have said for 45 minutes :D Lea made many valid points in her presentation but as is for supports.property case, you never want to go too deep into a single point of your talk so ... here I come. getCSSPropertyName Function This function aim is to understand if the current browser supports a generic CSS property. If property is supported, the whole name included prefix will be returned. var getCSSPropertyName = (function () { var prefixes = ["", "-webkit-", "-moz-", "-ms-", "-o-", "-khtml-"], dummy = document.createElement("_"), style = dummy.style, cache = {}, length = prefixes.length, i = 0, pre ; function testThat(name) { for (i = 0; i < length; ++i) { pre = prefixes[i] + name;

News

So we just got back from a little Canadian weekend with Thee Oh Sees. We had a blast. There is a lot going on in our world at the moment so we've been a bit busy - sorry for the lack of updates here. We have a whole bunch of upcoming shows, check out the shows section to your right - these include shows with SEX CHURCH, a mini-tour with PYGMY SHREWS, a couple of shows with RUSSIAN CIRCLES, and a little European tour in December. If any of you euros cant make it to see us in December, we will be back in January for a little over a month, and we are very excited. We have a new LP done, it will be out in March on Sacred Bones Records and much touring in support of it shall follow. We have also been informed that Karmic Swamp Records is repressing the "Think" 7" that came out last year. There were only a handful of those pressed so hopefully people that missed out on getting them can grab one now. We will post here when it is available. Also, thanks to everyone who has o

My BerlinJS Slides

It was a great event today at @co_up in @berlinjs meet-up and here are my sides about wru which accordingly with today meeting means where are you , directly out of SMS syntax. Enjoy ;)

Playing With DOM And ES5

Image
A quick fun post about " how would you solve this real world problem ". The Problem Given a generic array of strings, create an unordered list of items where each item contains the text of the relative array index without creating a singe leak or reference during the whole procedure. As plus, make each item in the list clickable so that an alert with current text content occur once clicked. The assumption is that we are in a standard W3C environment with ES5+ support. The Reason I think is one of the most common tasks in Ajax world. We receive an array with some info, we want to display this info to the user and we want to react once the user interact with the list. If we manage to avoid references we are safer about leaks. If we manage to optimize the procedure, we are also safe about memory consumption over a simplified DOM logic ... How would you solve this ? Give it a try, then come back for my solution. The Solution Here mine: document.body.appendChild( /* input */[&q

Do You Really Know Object.defineProperty ?

I am talking about enumerable , configurable , and writable properties of a generic property descriptor. enumerable most likely the only one we all expect: if false, a classic for/in loop will not expose the property, otherwise it will. enumerable is false by default. writable just a bit more tricky than we think. Nowadays, if a property is defined as non writable, no error will occur the moment we'll try to change this property: var o = {}; Object.defineProperty(o, "test", { writable: false, value: 123 }); o.test; // 123 o.test = 456; // no error at all o.test; // 123 So the property is not writable but nothing happens unless we try to redefine that property. Object.defineProperty(o, "test", { writable: false, value: 456 }); // throws // Attempting to change value of a readonly property. Got it ? Every time we would like to set a property of an unknown object, or one shared in an environment we don't trust, either we use a try/catch plus double

The Men are going to Europe In December

Here are the dates: 12/7/2011:  Paris, France , Espace 12/9/2011:  Dijon, France , Consortium- Generiq Fest (w/Cults) 12/10/2011:  Belfort, France , Poudiere (w/Black Lips) 12/11/2011:  Strousbourg, France @ TBA 12/12/2011:  Rotterdam, Netherlands , Exit 12/13/2011:  London, UK , Madame Jojo’s White Heat 12/14/2011:  London, UK , Shacklewell Arms

The Missing Tool In Scripting World

Few days ago I was having beers with @aadsm and @sleistner and we were talking about languages and, of course, JavaScript too. That night I have realized there is a missing process, or better tool, that could open new doors for JavaScript world. The Runtime Nightmare The main difference between scripting languages and statically typed one is the inability to pre optimize or pre compile the code before it's actually executed. Engineers from different companies are trying on daily basis to perform this optimization at runtime, or better Just In Time, but believe me that's not easy task, specially with such highly dynamic language as JavaScript is. Even worst task is the tracing option: at runtime each reference is tracked and if its type does not change during its lifecycle, the code could be compiled as native one. The moment a type, an object structure, or a property changes, the tracer has to compile twice or split the optimizations up to N exponential changed performed in a

Object.prototype.define Proposal

Somebody may think that defineProperties is boring and I kinda agree on that. The good news is that JavaScript is flexible enough to let you decide how to do that ... and here I am with a simple proposal that does not hurt, but can make life easier and more intuitive in modern JS environments. Unobtrusive Object.prototype.define How To Well, the handy way you expect. The method returns the object itself, so it is possible to define one or more property runtime and chain different kind of definitions, as example splitting properties from method and protected properties from protected methods. var o = {}.define("test", "OK"); o.test; // OK Multiple properties can share same defaults: var o = {}.define(["name", "_name"], "unknown"); o.a; // unknown o._a; // unknown Methods are immutable by default and properties or methods prefixed with an underscore are by default not enumerable. function Person() {} Person.protoype.define( ["getN

about JS VS VBScript VS Dart

You can take it as a joke since this is not a proper comparison of these web programming languages. JS Dart VBScript types √ √ sort of getters and setters √ √ √ immutable objects √ √ √ prototypal inheritance √ simulated classes √ "real" classes √ √ closures √ √ weakly bound to JS √ √ obtrusive for JS (global) may be √ √ obtrusive for JS (prototypes) may be √ operator overload √ cross browser √ real benefits for the Web √ ? ? If you are wondering about JS types, we have both weak type and strong type, e.g. Float32Array. When StructType and ArrayType will be in place then JS will support any sort of type.

about that post

I have been blamed and insulted enough so I removed the possibility to comment and I also invite you again to do not stop reading the title of a generic post here or anywhere around the net. I would like to summarize few parts of that post: on real world we should use the proper flag in order to generate files where only necessary parts of the library is included ... I agree that at this stage can be premature to judge the quality of Dart code, once translated for JavaSript world ... Google is a great company loads of ultra skilled Engineers ... n.d. I have proposed a fix for Dart code ... you may realize how much overhead exists in Dart once this is used in non Dart capable browsers ... Was operator overload the reason the web sucks as it is? ... everything 2 up to 10 times slower for devices, specially older one, that will never see a native Dart engine in core ... Not Really What We Need Today ... What are the performances boost that V8 or WebCL will never achieve ? ... What is the

What Is Wrong About 17259 Lines Of Code

Is the most popular, somehow pointless, and often funny gist of these days. It's about Dart , the JavaScript alternative proposed by Google. Why So Many Lines Of Code The reason a simple "Hello World" contains such amount of code is because: the whole library core is included and not minified/optimized but on real world we should use the proper flag in order to generate files where only necessary parts of the library is included whoever created such core library did not think about optimizing his code What am I saying, is that common techniques as code reusability do not seem to be in place at all: // first 15 lines of Dart core function native_ArrayFactory__new(typeToken, length) { return RTT.setTypeInfo( new Array(length), Array.$lookupRTT(RTT.getTypeInfo(typeToken).typeArgs)); } function native_ListFactory__new(typeToken, length) { return RTT.setTypeInfo( new Array(length), Array.$lookupRTT(RTT.getTypeInfo(typeToken).typeArgs)); } ListFact

Taking The Bat-Formula To The Next Level

When you wake up on Sunday morning with upside-down stomach and batcode in mind, you may realize it's time to rest a bit. with (/*Bat*/Math) Array(16).join( pow(/*JOK*/E/*R*/, cos, E/*vil*/) ) + "batman"; The output is the same produced by the original bat-formula : 'NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNbatman' Have a nice Sunday.

A Better is_a Function for JS

In 2007 I have posted about get_class and is_a functions in JavaScript in order to simulate original PHP functions. Well ... that was crap, since a much simpler and meaningful version of the is_a function can be easily summarized like this: var is_a = function () { function verify(what) { // implicit objet representation // the way to test primitives too return this instanceof what; } return function is_a(who, what) { // only undefined and null // return always false return who == null ? false : verify.call(who, what) ; }; }(); ... or even smaller with explicit cast ... function is_a(who, what) { // only undefined and null // return always false return who == null ? false : Object(who) instanceof what ; } An " even smaller " alternative via @kentaromiura function is_a(who, what) { return who != null && Object(who) instanceof what; } Here a usage example: alert([ is_a(false, Boolean), // true is_

implicit require in node.js

playing with Harmony Proxy I came out with a simple snippet: The aim of above snippet is to forget the usage of require ... here some example: module.sys.puts("Hello implicit require"); var fs = module.fs; fs.stat( ... ); It's compatible with nested namespaces too and if there are non JS chars in the middle ... well: var Proxy = module["node-proxy"];

bind, apply, and call trap

quick one out of ECMAScript ml var // used to trap function calls via bind invoke = Function.call, // normal use cases bind = invoke.bind(invoke.bind), apply = bind(invoke, invoke.apply), call = bind(invoke, invoke) ; What Is It This is a way to trap native functions method in a handy way. Used in a private scope, it can address these methods once so that we can rely nobody can possibly change them out there for some script injection and only if we are sure the script has been loaded at the very beginning. How To Use Them Here few examples: // secure hasOwnProperty var hasOwnProperty = bind(invoke, {}.hasOwnProperty); // later on hasOwnProperty({key:1}, "key"); // true hasOwnProperty({}, "key"); // false // direct slice var slice = bind(invoke, [].slice); slice([1,2,3], 1); // 2,3 slice(arguments); // array // direct call call([].slice, [1,2,3], 1); // 2,3 // direct apply apply([].slice, [1,2,3], [1]); // 2,3 // bound method var o = {name:&q

SUMMER IS GONE/REWIND/GIVE IT BACK

Our good friend Chris Berntsen used "Stranger Song" in his short film. It's great, check it out. SUMMER IS GONE/REWIND/GIVE IT BACK from Chris Berntsen on Vimeo .

Dear Brendan, Here Was My Question

I had the honor to personally shake the hand of the man that created my favorite programming language: Brendan Eich ! I also dared to ask him a question about ES6 and I would like to better explain the reason of that question. I have 99 problems in JS, syntax ain't one I don't know who said that but I completely agree with him. Here the thing: one of the main ES6 aim is to bring new, non breaking, shimmable, native constructors such StructType , ArrayType , and ParallelsArray . We have all seen a demo during Brendan presentation and this demo was stunning : an improvement from 3~7 to 40~60 Frames Per Second over a medium complex particles animation based, I believe, on WebGL. These new native constructors are indeed able to simplify the JS engine job being well defined, known, and "compilable" runtime in order to reach similar C/C++ performances. These new constructors can also deal directly behind the scene, without repeated and redundant "boxing/unboxing"

Me At JSConf.EU 2011

About my JSConf.EU Talk . Here my JSConf EU 2011 Slides , and here again the speaker rate (only if you have seen the talk, pls). update I forgot to mention lazy features detection oject proposal! Thanks everybody, it has been a great week end :)