Posts

Showing posts with the label Code

size maniacs or just twitterable examples ?

maybe both, but I like the idea! Many times I have added something like #tweetcode at the end of a tweet created with the single goal to be small enough for ... well, a tweet! @jedschmidt bought a spanish domain called 140byt.es based over github forks in order to provide all sort of tweets that may solve a specific problem in an efficient way: it kinda work on copy and paste! Kinda ... because rules may not truly work stand alone and snippets are suggested without a "tooltip" example, at least in the main page. What Can We Do In 140 Bytes ? tweet a solution for a simple task provide an idea about how to solve a task solve a task in a truly efficient way Yeah, some snippet is absolutely everything we may need to solve a problem. The most simple example is the hex2rgb and rgb2hex, a problem that could be solved easily via bitwise operators and a tiny bit of math. How Can 140 Bytes Be Enough ? Using few tricks suggested in this page we can realize it is possible to shrink t...

JSLint: The Bad Part

Every programming language has somehow defined its own standard to write code. To be honest, as long as code is readable, clear, and indented when and if necessary, I think we do not need so many "code style guides" and, even worst, sometimes these "code standards" let us learn less about the programming language itself, helping if we are beginners, sometimes simply annoying if we are professionals. Disclaimer This post aim is absolutely not the one to blame one of my favorite JS gurus, this post is to inform developers about more possibilities against imperfect automation we'll probably always find in whatever excellent spec we are dealing with. This post is about flexibility and nothing else! JSLint And Code Quality Wehn Mr D says something, Mr D is 99.9% right about what he is saying ... he clearly represents what we can define a Guru without maybe or perhaps but he, as everybody else here, is still a programmer, and we all know that every programmer ...

Konami Code as DOM Event

If You do not know what is the Konami Code you are too young, or not geek at all. In both cases, it does not matter, nobody is perfect, but what we should know is that some truly affectionate developer though to put this code to enable secret user powers , even if the the software is, as example, extremely recent . So why not? Why can't we all have our secret mode in the most popular platform as the World Wide Web is? Konami Code Event var onkonamicode = function(el, fn){ // The Super Code Event by WebReflection - Mit Style function onkonamicode(e){ konamicode.push((e || event).keyCode || e.charCode); if( konamicode.length === 10 && konamicode.join(".") === "38.38.40.40.37.39.37.39.66.65" ){ if(el.removeEventListener) el.removeEventListener("keydown", onkonamicode, false); else el.detachEvent("onkeydown", onkonamicode); ...

PyramiDOM - from Alpha to Beta

As promised, I have commented and improved my last experiment: PyramiDOM , ( IE version) now with some new feature: One click from bookmark to add PyramiDOM, another one to remove it In a single session, colors are preserved even if PyramiDOM is added and removed more than once Good browsers with W3C DOM events support and/or a console, will experience a better PyramiDOM thanks to automatic update feature and related dom nodes logged in the console last part of the bookmark is the size of each brick. Right now it is 2 but you can easily change it to 4, 6, 8, whatever multiple of 2 you prefer The PyramiDOM Source Code It is really simple and the main logic is behind the Brick constructor and every brick instance. (function(size){ var // shortcut to attach/detach events add = document.addEventListener ? function(node, name, callback){ node.addEventListener(name, callback, false); }: function(node, name, callback){ node....

On My Vicious JavaScript Code

Disclaimer This post is a reply to kangax question : I’m sorry but why such vicious coding style? I'd like to explain my point of view about JavaScript code style so, if interested, please read until the end, thank you :) Some Background I study and use JavaScript since year 2000 and one of the most interesting thing about this language is that even if it is "that old" you never stop to learn something new (techniques, strategies, adapted patterns, etc). At the same time, the " biggest trouble " of this language is its weight in a page, which is the reason we all use minified and gzipped or packed versions of our application. Coming from a " 33Kb modem internet era " I always tried to pay attention about the size and I studied and created both a JavaScript minifier and a compressor . Compressors Rules Unless we are not using an " incremental " compressor, as GIF is, we should consider that packer algorithm, as gzip and deflate , are dicti...

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

Google Code Jam, or better, how to feel a 100% idiot !

Update 2 Congratulations! The results of the Google Code Jam 2008 Qualification Round are now official, and we're happy to announce that you have advanced to Round 1 Cheers :D ----------------------------------------- Update Guys, I do not know what Google judges will think about him/her, but in my mind, the qualification winner, for Python language, is the user camrdale , currently in position 40 of global score grid. That code is extremely clear (come on, that is Python, how can be different!), essential, and the logic is probably not the perfect one, but is so linear that you can understand the problem even without reading them. Well done camrdale, and good luck for the contest :geek: ----------------------------------------- Guys, honestly, I did not think about that kind of selection only to participate, bloody hell! First of All, the selection started at 11pm, and since I am an employee, and an hard worker as well, I though: who care? I have 24 hours to partecipate . This is ...