Posts

Showing posts with the label Python

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 ...

Google Code Jam: Mousetrap in 4 languages - GAME OVER

First of all, I would like to thank the Google team for Code Jam opportunity, and its organization: AMAZING! Yesterday I have lost my Round without a single commit. This time I have not excuses, it was simply my fault. I did not understand properly first two problems, or better, expected results, but I was sure the reason was my poor English knowledge, and I wouldn't be silly, asking silly questions (some question was silly enough, so, next time, I'll be less shy than this time). Accordingly, since Code Jam is a challenge, I chose to solve the most difficult problem, the Mousetrap. First of all, because the problem, and the expected result, was so simple to understand, secondly, because it was the best one for points :geek: Problem Analysis Ok, we had 2 hours to analyse the problem, to find the best solution, and to commit results, and this time I did not even download the test, because I would like to be sure that my solution was good enough to solve the problem. Count positio...

packed.it screencast ... (maybe) Yesss!!!

I didn't find a way to create a clean video, probably 450 pixels are not enought to show how does packed.it work? However, I'll try to explain these two screencast. First one - Ext JS Home Page - from 223Kb to 52Kb This video shows a saved version of Ext JS Home Page . This site uses a lot of external CSS, one imported and one in page but not every one is used by JavaScript disabled browsers. Total CSS size is about 93,2Kb while 4 used JavaScript files size is about 130Kb. With packed.it You can create a project using both CSS and JavaScript and the result will be a single file with total size of 52Kb, including both CSS and JavaScript. I didn't add to project Google Analytics unrich.js file but this should be included without problems too saving other 15Kb. As You can see (I hope), the result is even smaller on page, just three tags, using IE5 compatibility one, instead of 8 inside page ... these are few bytes less than original and layout is even more clean than ever. CS...

new packed.it automatic content generator

packed.it service now creates archives with 3 types of automatic content generator: ASP.NET (C#) , PHP (4 or 5) and Python (mod_python and psp or WSGI version). These generators complete packed.it service and are usable with MyMin produced code too if You choose to manage your own projects by yourself. Probably there will be future implementations (Java, Perl, Ruby), however today You can use packed.it to create optimized CSS and JavaScript for more than 80% of hosting solutions. A special thanks to Cristian Carlesso for C# porting, He doesn't like my revision style so much ... but it works perfectly and it's more simple to mantain too (at least for me :D) Have fun with packed.it :-)

MyMin project 1.0.1 available

I've just uploaded last version of MyMin project fixing only JSmin problems with regular expressions when it's not inside a closure, not after '{' or ';' allowing them to parse entire jQuery UI, for example, without problems. This fix has been successfully tested on Python 2.5, PHP 5.2, C# 2 and JavaScript 1.3 You can find MyMin project description in this page while You can optimize CSS and JavaScript in a single file simply using my on-line packed.it service . Have fun with optimizations and please feel free to post a comment if You find some bug using MyMin project, Thank You!

A "little bastard" BUG using JSmin parsers

Update It seems I found a valid fix for "strange" regular expressions. I suppose MyMin will be available tomorrow while packed.it has been just updated with last client version. Have fun with packed.it and please tell me if some source cannot be parsed. -------------------------------------- While I was testing every kind of source and CSS with my last creation, packed.it , I found a bug on JSmin logic, partially recoded inside MyMin project as JavaScript minifier (MyMinCSS and MyMinCompressor seem to work perfectly). This bug seems to be present on every version linked in JSmin page . I found this bug parsing jQuery UI + every CSS with my new service but one JavaScript file has one single, simple problem: function(){return /reg exp with this ' char/;} Bye bye JSmin, regexp will be parsed as string and an error will be raised. The problem is reproducible just with a string that contains only this (so a source that begins and end with these 3 chars): /'/ that's a...

Are You Ready To Pack ?

I'm pleased to announce my last revolutionary project called packed.it ! Just another minifier packer alternative ??? No guys! packed.it goals is to reduce using best practices both CSS and JavaScript sources in a single file . You can write directly on JS area or in CSS one or upload one or more file, choosing which one should be executed before others. Based on MyMin project , a personal revisit of JSmin plus a dedicated compressor and a CSS minifier for C# , JavaScript , PHP or Python languages, packed.it creates a project archive, in zip format, that will contain everything You need to server your files gzipped, deflated or clear for browsers or robots that does not support gz pages. Not only JavaScript ! The innovative packed.it idea is to process both JavaScript and CSS to create a single project file just compiled to be served using gzip, deflate or clear text. In this case your server will not need to do anything, just serve correct file verifying its sha1 summary to ...