<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Julien CROUZET on Medium]]></title>
        <description><![CDATA[Stories by Julien CROUZET on Medium]]></description>
        <link>https://medium.com/@c2c?source=rss-677072ea6c99------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-Dy-bEjt6mWu9yvHP29wvw.jpeg</url>
            <title>Stories by Julien CROUZET on Medium</title>
            <link>https://medium.com/@c2c?source=rss-677072ea6c99------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 00:25:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@c2c/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[No, you’re not looking for a #Javascript developer.]]></title>
            <link>https://medium.com/@c2c/no-youre-not-looking-for-a-javascript-developer-90a62bc88a25?source=rss-677072ea6c99------2</link>
            <guid isPermaLink="false">https://medium.com/p/90a62bc88a25</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Julien CROUZET]]></dc:creator>
            <pubDate>Wed, 11 May 2016 07:24:50 GMT</pubDate>
            <atom:updated>2016-05-11T07:24:50.884Z</atom:updated>
            <content:encoded><![CDATA[<p>“We are actively looking for a Backend NodeJS Developer, &lt;insert some buzzwords here, like IoT, big data, Mean&gt;, &lt;insert some wanna be funny part with some obscure star wars reference and mention the ping pong table&gt;” ; that’s the same headline, on every job board from almost every tech, media or startup company. And to be honest, only a few of them will find their match.</p><p>What if the problem here is “NodeJS” in “We are actively looking for a Backend NodeJS Developer” ?<br>Not that I’m saying that the buzzwords part is not a problem; it is indeed ; or all these wanna be funny sentences from the HR teams which are counterproductive ; nor that the NodeJS platform is the problem.</p><p>No, IMHO, the problem is that you’re over restricting your choice uselessly ; how often did you see a job offer like these one :</p><p>- “Looking for an apple pie pastry cook”<br>- “Looking for a Volvo FL6 truck driver”<br>- “Looking for a 80–90 American Standard toilets plumber”</p><p>Almost never.<br>That’s because apple pie pastry cook is not a job, pastry cook is. “Node.js developer” is not a job, Developer is.</p><p>In fact, you may have more chance to suceed if you hire a senior developer with no experience in Node.js. You may have chosen Node.js (and congratulations, it’s a very good choice), but it’s just a really small detail of the picture. The real skills you need is a solid HTTP(s|2)? protocol knowledge, someone who deeply knows what malloc(), a daemon or UDP are.</p><p>Hire a 15 years-XP c developer with absolutely no knowledge of Node.js, give him 2 or 3 weeks ; he’ll be as good as your “Fullstack developer with a Node.js experience” ; with a rocket fast debugging skill in bonus.</p><p>The language / platforms / frameworks we use will maybe deprecated in 3 years from now, the will be in 10 with no doubt ; let’s just restrict this deprecation on technology, not humans. Hire a developer, he’ll adapt himself to your stack. Hire a stack, you will adapt to your developer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90a62bc88a25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#NodeJS : A quick optimization advice]]></title>
            <link>https://medium.com/full-stack-engineering/nodejs-a-quick-optimization-advice-7353b820c92e?source=rss-677072ea6c99------2</link>
            <guid isPermaLink="false">https://medium.com/p/7353b820c92e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Julien CROUZET]]></dc:creator>
            <pubDate>Wed, 07 Oct 2015 21:15:43 GMT</pubDate>
            <atom:updated>2015-10-14T10:52:04.291Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hDPuAN6PLjuYLK1BOceBkA.jpeg" /></figure><p>Can you spot the difference between these two files :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef8ac8c4020d9acfce4648c3b41f9114/href">https://medium.com/media/ef8ac8c4020d9acfce4648c3b41f9114/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/452fbdef0a1cc6d7ae90d84ec6b85095/href">https://medium.com/media/452fbdef0a1cc6d7ae90d84ec6b85095/href</a></iframe><p>that can explain a 50% performance gain :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*ChsE-NhZBpnhZR0MwEXtgw.png" /></figure><p>If you don’t, it’s normal, you try to read the code abstracting the comment ; it was slightly changed :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*1SdiNDRyhwh2cKcZBDzEJA.png" /></figure><h3>What the ???</h3><p>The small changes made the function body of <em>add()</em> growing over 600 character. v8 optimizer (<a href="http://jayconrod.com/posts/54/a-tour-of-v8-crankshaft-the-optimizing-compiler">crankshaft</a>) <a href="https://en.wikipedia.org/wiki/Inline_expansion">inlines </a>the functions whose body length, including the comments, is less than 600 characters.</p><p>The 600 character limit can be tweaked via the <em>max-inlined-source-size</em> of the node command :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*YI9hSksfkonTciB8ghWKBA.png" /></figure><h3><strong>So when you have a function or callback that’ll be called repeatedly, try to make it under 600 characters (or your tweaked value), you’ll have a quick win !</strong></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7353b820c92e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/full-stack-engineering/nodejs-a-quick-optimization-advice-7353b820c92e">#NodeJS : A quick optimization advice</a> was originally published in <a href="https://medium.com/full-stack-engineering">Full Stack Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My 7 Node.js mantras]]></title>
            <link>https://medium.com/@c2c/my-7-node-js-mantras-edd6c148e8dc?source=rss-677072ea6c99------2</link>
            <guid isPermaLink="false">https://medium.com/p/edd6c148e8dc</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Julien CROUZET]]></dc:creator>
            <pubDate>Thu, 10 Sep 2015 20:59:00 GMT</pubDate>
            <atom:updated>2015-09-14T09:59:49.168Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>I’ve been using Node.js professionally since 3 years (with the help of 13 years of dev. experience in C, C++, PHP, Perl, Javascript, etc.) ; and like everyone else, I’ve faced a lot of (recurring) problems. I solved some using my Javacript knowledge but for the majority, I did it with the help of the community (mostly <a href="http://stackoverflow.com/">StackOverflow</a> and <a href="http://irc.lc/freenode/node.js/">Freenode</a>).</p><p>From this experience, I taught myself 7 mantras for every Node.js projects that keeps me away from a lot of traps and pains.</p><h3>1 — Beauty arise when you get a Promise</h3><p>Really … <a href="https://www.promisejs.org/">Promises</a> are a god’s gift to the JS developer community. Every time you think <em>asynchronous</em> (which happens almost every time with Node.js), you can (should) think Promise.</p><p>Initially, the Node.js adopted a convention for asynchronous functions : your last argument must be a callback function that takes two arguments, the first one being an error, the second one being the operation result.</p><pre>fs.readFile(’/etc/passwd’, function (err, data) {<br>  if (err) throw err;<br>  console.log(data);<br>});</pre><p>Now, in the promise world, this callback hell spaghetti code :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79ad42ce274618a5f32a80391c09ecf2/href">https://medium.com/media/79ad42ce274618a5f32a80391c09ecf2/href</a></iframe><p>Becomes this elegant :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbebdeea9ee8867cebd65955c5268390/href">https://medium.com/media/dbebdeea9ee8867cebd65955c5268390/href</a></iframe><p>Beside the beauty of code, Promise allows you to control with ease all your async operations and makes it easier to debug.</p><p>Last but not least, Promise are available in your old Node.js version with the help of <a href="https://github.com/petkaantonov/bluebird">Bluebird</a> (<a href="https://github.com/petkaantonov/bluebird/tree/master/benchmark">and it’s really fast </a>!).</p><h3>2 — ES6 is more than a bag of tricks</h3><p>Here we are, the long-awaited <a href="https://nodejs.org/en/blog/release/v4.0.0/">Node V4.0</a> is out, with a <a href="https://nodejs.org/en/docs/es6/">lot of ES6 features</a>. We can now safely say that ES6 is de facto a standard for Node.js developers.</p><p>During the last months, ES6 was a real subject but considered as a “cool thing to test” but not production ready ; I disagree. <a href="https://babeljs.io/">Babel</a> produces a nice-to-read, safe and optimized ES5 code, so anyone could already code in ES6 and use its lot of new features. But still, it was a risk because a company would have suffer in hiring an ES6-ready team. Ok.</p><p>But time has changed, with Node V4 and <a href="https://kangax.github.io/compat-table/es6/">all the browser that keeps on implementing it</a>, ES6 should now be a prerequisite for any JS developer position and offers <a href="https://github.com/lukehoban/es6features">a lot</a> of optimization, code sugars, safety and more …</p><p>Choosing ES6 right now is also a strategic point, your ES5 code will soon (months ? a year) be deprecated !</p><h3>3 — Ignoring semver makes problem occur</h3><p>With Node.js comes <a href="https://www.npmjs.com/">n</a>pm. With npm comes your <a href="https://docs.npmjs.com/files/package.json">package.json</a>. package.json is the biggest key to success or failure when it comes to maintainability, deployment and stability.</p><p>Every time you add a dependency to your project with <em>npm install — save</em>, npm will install this package and save it to the <a href="https://docs.npmjs.com/files/package.json#dependencies"><em>dependencies</em></a> property ; but npm doesn’t only saves the package it also the required version — required means here “The version I need to work correctly”. This version respects the <a href="http://semver.org/">semver</a> format.</p><p>It’s important here to not just trust npm (which will use a <em>caret (^) </em>by <a href="https://docs.npmjs.com/misc/config#save-prefix">default</a>) ; using caret means that you <strong>trust</strong> (and I really mean <strong>TRUST</strong>) the package maintainer(s) to respect strictly the semver versioning. It he (they) introduces a breaking change in a minor build, you’re screwed up.</p><p>If you’re working with on a professional project, I advise you to choose a different strategy, like <a href="https://docs.npmjs.com/misc/config#save-exact">exact-save</a> and to upgrade your packages version manually. You’ve got enough work with your bugs, don’t import other’s one !</p><h3>4 — Knowing your dependencies keeps away some diseases</h3><p>This mantra is linked to the previous one. Node.js is module based by architecture and our work, as Node.js dev, is not only to produces code. We have to know, understand, study, observe(and maybe contribute to) <strong>EVERY</strong> package we <em>require()</em>.</p><p>A lot of time, I found myself searching for a node module on Google, then fastly read the description on npmjs.com, and if it matched my needs, a fast <em>npm install — save</em> did the trick… Fatal error !</p><p>Here is my check list now to decide if I <strong>depend </strong>(the word is exact, after all) or upgrade a package :</p><ul><li>The stats on npmjs.com or github</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*OHe2ycf7bGk7ae5l0TL-ng.png" /></figure><ul><li>The <a href="http://keepachangelog.com/">CHANGELOG</a> to check if semver is respected (Eg: <a href="https://github.com/restify/node-restify/blob/master/CHANGES.md">restify</a>)</li><li>The commit history, to check if it’s still active (Eg: <a href="https://github.com/strongloop/express/commits/master">express</a>)</li><li>The issues/<a href="https://help.github.com/articles/using-pull-requests/">PR </a>tracker, to see if the project has a community (Eg: <a href="https://github.com/request/request/issues">request</a>)</li><li>The <a href="https://en.wikipedia.org/wiki/Continuous_integration">CI </a>status if it has unit testing (Eg: <a href="https://travis-ci.org/mochajs/mocha/jobs/79593258">mocha </a>on travis-ci)</li><li>Its dependencies status (out of date) (Eg: <a href="https://david-dm.org/socketio/socket.io">socket.io</a> on <a href="https://david-dm.org/">David</a>)</li></ul><h3>5 — Offer yourself some rest with unit tests</h3><p><a href="https://en.wikipedia.org/wiki/Unit_testing">Unit testing</a> has always been a very good solution to industrial development problems, almost anyone would advise to use it ; I’m personally a big fan of <a href="https://en.wikipedia.org/wiki/Test-driven_development">TDD</a> and I couldn’t agree more. But when it comes to Node.js, my opinion is that it’s not an advise, it’s mandatory and it can defeat all the “<em>it takes too much extra time</em>” argument.<br>Of course, the main goal of unit test is to ensure that your code is not buggy, answers to a problematic and doesn’t introduce new bugs on updates. Like in all languages. But as we saw it in mantra 3 &amp; 4, Node.js is based on a module system, and its philosophy is to use as most as possible the <a href="https://en.wikipedia.org/wiki/Microservices">Microservice pattern</a> ; we <strong>HAVE TO</strong> depend on a lot of external modules ; depending doesn’t mean a blind trust.</p><p>The best way to be sure about a package upgrade is having a collection of unit tests that will performs operations like <em>“Does it return that when I pass this”</em>, <em>“Does it throws if I do that”</em> or <em>“Does my code detects if this does not return that”</em>. This may sound like a waste of time or reinventing the wheel on a package that already has some unit tests, but trust me (not blindly huh ?), soon or later, you’ll regret it and probably spend more time to identify and fix the sub-sub-sub dependency that made your website burping 500 pages while your COO is asking you every 37 seconds on yammer <em>“is it fixed now ? what’s going on ??!</em>”.</p><h3>6 — Knowing V8 will calm your heart rate</h3><p>Let’s talk semantic. PHP is a language. And also a runtime. Zend Engine is it’s engine.<br>Javascript is a language. Node.js a <a href="https://en.wikipedia.org/wiki/Runtime_system">runtime</a>. <a href="https://code.google.com/p/v8/">V8</a> is it’s <a href="https://en.wikipedia.org/wiki/JavaScript_engine">engine</a>. An there again, the word is correct ; you can see it as your car engine.<br>The way to Node.js mastering goes through knowing (at least a little bit) V8. V8 performance makes Node.js performance, and of course, V8 bugs and caveats are Node’s one !</p><p>For this mantra, all is detailed in <a href="https://github.com/petkaantonov/bluebird/wiki/Optimization-killers">Bluebird’s Optimization killers page</a>. For all the TL; DR, here is some ways to make your code slower and buggy :</p><ul><li>Playing with <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Fonctions/arguments"><em>arguments</em></a></li><li>Using more than 128 case-clauses in a switch case</li><li>Using <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Instructions/for...in">for...in</a> or <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Instructions/for...of">for…of</a></li><li><a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Instructions/debugger">debugger</a>, <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/eval">eval</a>, <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Instructions/with">with </a>(KILL IT WITH FIRE, BEFORE IT LAYS EGGS)</li><li>Object litterals with <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Object/proto">__proto__</a>, <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Fonctions/get">get</a> or <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Fonctions/get">set</a></li></ul><h3>7 — Use (AirBnB) eslint and reviewers doesn’t squint</h3><p>This last one is very personal and I don’t think it’s a good or a bad practice, it’s mine.<br>Javascript is a very flexible language, code readability (although it’s very difficult to rate it) goes to <a href="https://gist.github.com/freundTech/7cbb095ffca731a4aea1">WTF</a> to <a href="http://addyosmani.com/resources/essentialjsdesignpatterns/book">poetry</a>.</p><p>Anyway, we have to work together and respect some conventions, the main reason being :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*C6X_uifGuIDYW-yLAMVx3Q.jpeg" /></figure><p>The greatest code style with a popularity I found so far is <a href="https://github.com/airbnb/javascript">AirBnB Javascript Style Guide</a>, they did a great work with detailing all their choices and it meets almost all of my preferences.</p><p>That being said, having a code convention is a thing, respecting it is another. That’s the <a href="https://en.wikipedia.org/wiki/Lint_(software)">linter</a>’s job, and for this work, <a href="http://eslint.org/">eslint</a> is my best choice (After some years of fidelity to <a href="http://jshint.com/">JSHint</a>).<br>ESlint is pluggable, fast, they have a <a href="http://eslint.org/docs/rules/comma-dangle.html">detailed page</a> about each rule tested and it’s actively maintained.<br>Oh and it’s <a href="http://eslint.org/blog/2014/11/es6-jsx-support/">ES6 ready</a>.<br>Oh(2), as I’m a lucky guy, AirBnB has published an <a href="https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb">ESlint package</a> for their style guide.</p><p>So, when I’m allowed to do it (a lot of company I’ve worked for has their own style guide and/or linters), I always setup this little stack in my <a href="https://docs.npmjs.com/misc/scripts"><em>npm prepublish</em></a> script to check my code before publishing and activate <a href="https://www.jetbrains.com/webstorm/help/eslint.html">ESlint support in Webstorm</a> (yeah, another subject ;).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edd6c148e8dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An idea : npm should use DNS for optimization]]></title>
            <link>https://medium.com/@c2c/npm-should-use-dns-for-optimization-a3e60bc0350?source=rss-677072ea6c99------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3e60bc0350</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[npm]]></category>
            <dc:creator><![CDATA[Julien CROUZET]]></dc:creator>
            <pubDate>Wed, 09 Sep 2015 20:04:54 GMT</pubDate>
            <atom:updated>2015-09-10T06:46:43.183Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>Now that Node.js v4 <a href="https://nodejs.org/en/blog/release/v4.0.0/">is released</a>, I was thinking about the number of people that will try out this new version on their project and the traffic, resources usage and iops<a href="https://www.npmjs.com/about"> npm, Inc.</a> staff will face during the first days. Of course, they have a great architecture (<a href="http://blog.npmjs.org/post/75707294465/new-npm-registry-architecture">http://blog.npmjs.org/post/75707294465/new-npm-registry-architecture</a>) and everyone can agree that they do a wonderful job with an almost 100% uptime.</p><p>However, like every time I think about about an architecture, I was wondering how can this system can be optimized and I ended with that idea : <em>What if npm, Inc. was using </em><a href="https://en.wikipedia.org/wiki/Domain_Name_System"><em>DNS </em></a><em>for all the read operations ?</em></p><h3>This would be only partial</h3><p>First, it’s important to understand that this switch would be only for the <strong>READ </strong>operations. DNS is, by nature, a <em>client-read-from-server</em> protocol and NPM is a full <a href="https://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> system. The idea would be to switch all READ operations like “<em>What is the latest version of this package</em>” or “<em>What are the dependencies of this package</em>”. Basically this means the<a href="https://docs.npmjs.com/api/view"> view operation of the NPM Api</a>.</p><p>Even if this is only a fourth of the CRUD stack and it’s only one in all &gt;40 operations, it’s the main one in terms of use cases and traffic. Every time someone does a <em>npm update/install</em> or a <em>npm outdated</em> for example, a view operation is done on each of your dependencies (and each of the dependencies of your dependencies and so on…). The Create Update and Delete operations are more occasional.</p><p>So this change would be crucial and important.</p><h3>How it work now (briefly) and the optimization key</h3><p>Let’s say I have a project which depends on <a href="https://www.npmjs.com/package/lodash">lodash </a>…</p><p>When I do a <em>npm install</em>, npm will parse my <em>package.json</em> file and try to install all dependency, by their name.</p><p>That means, for each dependency, it’ll make an HTTP request like <a href="http://registry.npmjs.com/lodash">http://registry.npmjs.com/lodash</a> :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10322e2a8d6cb3e486e23343719edb4c/href">https://medium.com/media/10322e2a8d6cb3e486e23343719edb4c/href</a></iframe><p>Two things are important here :</p><ol><li>The hostname we made the request on is <strong>registry</strong>.npmjs.com ; so yes, it’s a data registry, so is a DNS server :) ;</li><li>The server header : “<em>CouchDB/1.5.0” </em>; so ye’s we’re making a (cached by <a href="https://www.fastly.com/">fastly</a>) HTTP query to NPM database. Basically, registry.npmjs.com is a <a href="https://en.wikipedia.org/wiki/CouchDB">CouchDB</a> database.</li></ol><p>As you can see, the body of the answer is a JSON document which contains <strong>ALL </strong>the packages information (name, description, versions, repository URL, authors, etc.) ; so npm will check if the package is installed or if it needs to be updated according to the <a href="https://docs.npmjs.com/files/package.json#dependencies">dependencies </a>declaration.</p><p>For lodash, it’s (at the time of writing this post) 109kB ; and, let’s say we’re doing a <em>npm outdated </em>on <a href="https://github.com/strongloop/express">express</a>, it’s a total of 27 HTTP requests and <strong>700kB</strong> of data… Damn, we just wanted to check our package versions !</p><p>Well, let’s be honest, this is <strong>NOT</strong> what happens each time npm checks a version of a package, to get these numbers, I cheated a bit (sorry). npm keeps a cache of the answers (in <em>~/.npm/registry.npmjs.org/&lt;package&gt;</em>) with the full JSON document plus a property named <em>“_etag” </em>to respect the <a href="https://en.wikipedia.org/wiki/HTTP_ETag">Non-Match/304 Not modified</a> part of the HTTP protocol. So yes, it’s already optimized for that part but still, we have to query their server on each package and parse a full big JSON document every time.</p><h3>The concept</h3><p>(For anyone that is not comfortable with DNS, should be good to <a href="http://www.appliedtrust.com/resources/infrastructure/understanding-dns-essential-knowledge-for-all-it-professionals">read a bit about it</a> before).</p><p>Imagine that, besides this wonderful architecture, npm, Inc. provides a DNS server for simple queries like the latest version of a package or the tarball url of a specific version ? What we need here is a protocol that will provide an information from a registry when requested with a specific key. DNS is perfect. Specifically the<a href="https://en.wikipedia.org/wiki/TXT_Record"> TXT Record</a>.</p><p>Querying an information from registry will be a DNS question to <em>&lt;package_name&gt;.&lt;property_path&gt;.domain</em></p><p>So let’s say this DNS server has the delegation for <em>dns.npmjs.com</em> …</p><blockquote>You want the latest version of the lodash package ?<br>$&gt; dig +short -t TXT lodash.dist-tags.latest.dns.npmjs.com<br>3.10.1</blockquote><blockquote>You want the tarball url of the version 0.3.0 of lodash ?<br>$&gt; dig +short -t TXT lodash.versions.0.3.0.dist.dns.npmjs.com<br>{shasum: “e7db413e8b50d48834e86f82c52fd64f0a9e5d6e”,tarball: “<a href="http://registry.npmjs.org/lodash/-/lodash-0.3.0.tgz">http://registry.npmjs.org/lodash/-/lodash-0.3.0.tgz</a>&quot;}</blockquote><blockquote>You want the description of lodash ?<br>$&gt; dig +short -t TXT lodash.description.dns.npmjs.com<br>The modern build of lodash modular utilities.</blockquote><p>Well, I think you got the concept.</p><h3>The advantages</h3><h4>Less traffic</h4><p>An average HTTP query is 250B + the package name length, a DNS question message is 16B + the domain length, that’s more than 90% less.</p><p>The average response (considering a 304 not modified answer) is also on an average of 250B, a DNS resource message is 10B + the domain length + the data, we’re still in a huge traffic reduction.</p><h4>Yeah UDP !</h4><p>Yep, UDP traffic is faster, easier to manage and reduces latency</p><h4>Less parsing</h4><p>Avoiding the whole JSON document parsing every time you only need to check a package version is a huge win, you can update, deploy and install faster !</p><h4>Like a free and bigger CDN</h4><p>Every DNS record has a <a href="https://en.wikipedia.org/wiki/Time_to_live#DNS_records">TTL</a>, this means that every user’s internet provider would offer npm, Inc. a free and optimized CDN while they can still decide and control how long the answer will be cached. <a href="https://developers.google.com/speed/public-dns/">Google’s public DNS</a> would become an opportunity of a damned fast mirror !</p><h4>Easier implementation</h4><p>Third party project that monitor your package versions (like <a href="https://github.com/alanshaw/david">david</a>) would be able to perform a version check without the overhead of the whole npm dependency and parsing.</p><p>Even more, it opens to other languages (Go, PHP, pyton, etc.) the availability to query the npm, Inc. registry easily for interoperability.</p><h4>Less firewall hassle</h4><p>Allowing your production server to query <em>registry.npmjs.com</em> is often a nightmare in the enterprise world, you have to negociate hardly with your sysadmin or use a proxy. Well, DNS is quite never blocked because it’s done via a local server. No more configuration !</p><h3>Implementation</h3><p>Another good news is that it doesn’t seem very hard to implement, it would need two steps :</p><h4>A custom DNS server</h4><p>This part is the easier, with the help of <a href="https://github.com/tjfontaine/node-dns">node-dns</a>, it’s just about parsing the queried domain, to parse the JSON from CouchDB (and probably cache it to redis or so) and to reply with the asked property.</p><p>This server would be delegated <em>*.dns.npmjs.com</em> and that’s it.</p><h4>Update <a href="https://github.com/npm/npm">npm/npm</a></h4><p>The goal here is to detect these READ operations to migrate it to a DNS query and to keep the classic CouchDB query where needed.</p><p>I will make a POC in the next days … If it sounds good to you. Does it ?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3e60bc0350" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Where is this, and what is that ?]]></title>
            <link>https://medium.com/@c2c/where-is-this-and-what-is-that-883feec907be?source=rss-677072ea6c99------2</link>
            <guid isPermaLink="false">https://medium.com/p/883feec907be</guid>
            <dc:creator><![CDATA[Julien CROUZET]]></dc:creator>
            <pubDate>Wed, 18 Feb 2015 05:16:03 GMT</pubDate>
            <atom:updated>2015-02-19T15:15:42.766Z</atom:updated>
            <content:encoded><![CDATA[<h2><strong>#javascript : Where is this, and what is that ?</strong></h2><h3><strong>AKA : Let’s finally STOP this crazy<br><em>that = this</em> thing …</strong></h3><h3>TL; DR</h3><p>The <strong><em>var that = this;</em></strong> “pattern” on callback function to bypass the <em>loosing </em><strong><em>this</em></strong><em> value</em> is a very bad idea.</p><p>Use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind">Function.prototype.bind()</a> or, if you’re an old browser, a proxy function like <a href="http://api.jquery.com/jquery.proxy/">jQuery.proxy()</a>.</p><h3>A history on violence …</h3><p>Let’s admit it, we’ve all used at least once the <em>var that = this; </em>technique, we even saw some <a href="https://luizfar.wordpress.com/2012/04/28/dont-use-this-in-javascript/">crazyness</a> about this. Let’s (re) define the reason of that non-sense.</p><p>Javascript is (theorically…) a <a href="http://en.wikipedia.org/wiki/Single_threading">mono-thread language</a>, so <a href="http://www.i-programmer.info/programming/theory/6040-what-is-asynchronous-programming.html">asynchronous events</a> are handled by “callbacks” :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc67a42c6b853343b5de8b5ac63a529b/href">https://medium.com/media/dc67a42c6b853343b5de8b5ac63a529b/href</a></iframe><p>We can interpret it by “<em>when this thing occurs, run this function</em>”.</p><p>Now let’s consider a more complex use of callback inside an object :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbb61ef315c4fea2f3e508349a6e39c0/href">https://medium.com/media/fbb61ef315c4fea2f3e508349a6e39c0/href</a></iframe><p>As you can see, when we run the <em>timer</em> method, <em>this.property</em> is equal to ‘fooBar’ ; <em>callback</em> method, <em>this.property </em>is now undefined. Why ?</p><p>The answer is simple, <em>this</em> is <strong>no more</strong> what you think ; it’s now the global object (window for browsers, for example). Ok. But then again, why ?</p><p>If you ever used <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply">Function.prototype.apply</a> to run a closure manually, you’ve seen that its signature is :</p><pre>func.apply(thisArg [, argsArray])</pre><p>It can be read as “<em>run this closure with </em><strong><em>thisArg</em></strong><em> as the value of </em><strong><em>this</em></strong><em>, and </em><strong><em>argsArray</em></strong><em> as its arguments</em>”.</p><p>So when we run :</p><pre>setTimeout( this.callback, 1000);</pre><p>Your Javascript interpreter will wait 1 second before calling :</p><pre>this.callback.apply( null );</pre><p>As the spec says : “<a href="http://devdocs.io/javascript/global_objects/null"><em>null</em></a><em> and </em><a href="http://devdocs.io/javascript/global_objects/undefined"><em>undefined</em></a><em> will be replaced with the global object</em>”, it is now clear that <em>this</em> in my callback is now … the global object !</p><p>And then … we started using this “design pattern” :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3aff374e38babac89fd6b1d06d05e48/href">https://medium.com/media/a3aff374e38babac89fd6b1d06d05e48/href</a></iframe><p>Javascript developers <strong>love</strong> it and use it widely, <strong>very</strong> widely. (<a href="https://github.com/search?utf8=%E2%9C%93&amp;q=%22var+that+%3D+this%22+language%3Ajs&amp;type=Code&amp;ref=searchresults">38,399 occurrences</a> in GitHub at the time of writing this post).</p><h3>Why is it wrong ?</h3><h4>It is semantically wrong.</h4><p>English is not my first language, and I can’t say I’m totally fluent in english (you‘ve probably already guessed it, right ?) ; but still, I can understand that <strong><em>this and that</em></strong> is a way to differentiate two <strong>distinct</strong> thing.</p><p>I’m always obsessed about code readability ; and if we’re not talking about esoteric languages like <a href="http://brainfuck.tk/">Brainfuck</a>, <a href="http://www.dangermouse.net/esoteric/ook.html">Ook</a> or <a href="http://progopedia.com/dialect/spoon/">Spoon</a>, I consider that a good program is something that you can almost understand when you read it as english.</p><p>Here we start with a ambiguous declaration, not the best way to start.</p><h4><strong><em>“that”</em></strong> is not reserved or protected.</h4><p>Ecmascript 5 defined <strong><em>this</em></strong> as a <a href="http://www.ecma-international.org/ecma-262/5.1/#sec-7.6.1.1">reserved keyword</a>, this means that you cannot create a variable named <em>this</em> nor you can change its value. The following declarations :</p><pre>var this = { };</pre><pre>this = 90;</pre><p>will throw a <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/ReferenceError">ReferenceError</a>.</p><p><strong><em>that</em></strong> is not a reserved keyword. Not at all. It’s a common variable, and it can be overwritten, edited, deleted, … If we consider the following code :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f0139d3c72f1a7af33a180de1217a68/href">https://medium.com/media/8f0139d3c72f1a7af33a180de1217a68/href</a></iframe><p>You can see that we can<strong>not</strong> rely on the <strong><em>that</em></strong> variable. Here, we’re loosing one of the benefits of a specified language construct : stability.</p><h4>And finally, … it’s useless !</h4><p>And that’s what we’ll see in the next chapter.</p><h3>How to handle the “I’m losing this” dilemma</h3><h4>Make a proxy function</h4><p>We’ve seen that the problem is that our setTimeout callback execution can be rewritten as :</p><pre>callback.apply( null );</pre><p>Our first solution is to make a “proxy” function that will ensure that the <strong><em>thisArg</em></strong> argument of</p><pre>func.apply(thisArg [, argsArray])</pre><p>is set with the correct value :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2489d885cf5181a9fe366f13dec62a5/href">https://medium.com/media/a2489d885cf5181a9fe366f13dec62a5/href</a></iframe><p>The <em>myProxy</em> function is basically <strong>returning another function</strong> that will run the following code :</p><pre><strong><em>callback</em></strong>.apply(<strong>thisArg,</strong> arguments);</pre><p><em>By the way, you can see that we have to translate the </em><strong><em>arguments</em></strong><em> object to an array by using </em><strong><em>Array.prototype.slice.call(arguments);</em></strong></p><p>This technique will ensure that <strong><em>callback</em></strong> will be passed the correct arguments.</p><p>Remember that this type of proxy function is already implemented in almost every Framework / Library ; for example with jQuery, you can use <a href="http://api.jquery.com/jQuery.proxy">jQuery.proxy</a> :</p><pre>$(&#39;#myId&#39;).on(&#39;click&#39;, <strong>$.proxy(this.onClick, this)</strong>);</pre><p>(See source <a href="http://james.padolsey.com/jquery/#v=2.0.3&amp;fn=jQuery.proxy">here</a>).</p><h4>Use the function.prototype.bind method</h4><p>(NB: If you want an IE8 compatibility, you can’t. But that’s not your worst problem …)</p><p><a href="http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4.5">ECMAScript 5.1 (ECMA-262</a>) introduced a new method on the Function object :</p><pre>func.bind(thisArg[, suppArg1[, suppArg2[, ...]]])</pre><p>The bind method does the same thing as our previously <em>proxy</em> method, but natively :</p><pre>$(&#39;#myId&#39;).on(&#39;click&#39;, <strong>this.onClick.bind(this)</strong>);</pre><pre>setTimeout( (function() { console.log(this); }).bind({}), 1000 );<br>// -&gt; { }</pre><h4>Buy a Delorean and go to the future</h4><p><a href="https://people.mozilla.org/~jorendorff/es6-draft.html">ECMAScript 6</a> introduced a new feature : <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">Arrow functions</a>.</p><p>Arrow functions offers a syntax improvement (I’ll cover it one day) that we’ll skip here, but another noticeable feature is that Arrrow function keeps the <strong><em>this</em></strong> value unchanged :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5e2291b8fa8d9a7f7448f08c789c8e0/href">https://medium.com/media/a5e2291b8fa8d9a7f7448f08c789c8e0/href</a></iframe><p><em>(You can try it in latest Firefox)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=883feec907be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#javascript: console lesser known features.]]></title>
            <link>https://medium.com/@c2c/javascript-console-lesser-known-features-9fe3852ce48b?source=rss-677072ea6c99------2</link>
            <guid isPermaLink="false">https://medium.com/p/9fe3852ce48b</guid>
            <dc:creator><![CDATA[Julien CROUZET]]></dc:creator>
            <pubDate>Wed, 18 Feb 2015 01:34:48 GMT</pubDate>
            <atom:updated>2015-02-18T01:54:34.050Z</atom:updated>
            <content:encoded><![CDATA[<p>We’ve all used the <a href="https://developer.mozilla.org/en-US/docs/Tools/Web_Console">console</a> tools for age (Thank you Firebug) ; but most of us use only use the basic features like console.log() or console.error().</p><p>However, the console API is really powerful and offers a lot of very interesting features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/64/0*ia51gPssz_wHWydB.png" /></figure><p>Always keep in mind that the console API is not standard and is not going to be standardized. There is absolutely no guarantee that these features will be available and <em>you should never use console on production.</em></p><h3>String substitutions</h3><p>console.log() and other printing message methods (info, warn and error) supports string substitution (like the C printf function).</p><p>You can so use :</p><pre>console.log(&#39;User %s has %d items&#39;, &#39;John&#39;, 5);</pre><pre>&gt;&gt; &quot;User John has 5 items&quot;</pre><p>It’s often useful for string concatenation, to avoid the “ + “ agony and prevent the quote/double-quotes errors.</p><pre>var example = &quot; This -&gt; &#39; and this -&gt; &#39;&quot;; console.log(&#39;Here is my string &quot;%s&quot;&#39;, example);</pre><pre>&gt;&gt; &quot;Here is my string &quot; This -&gt; &#39; and this -&gt; &#39;&quot;&quot;</pre><p>Currently, here are the supported identifiers :</p><p><strong>%s</strong> <em>String </em>: IE, Chrome, Firefox</p><p><strong>%d or %i</strong> <em>Integer</em> : IE, Chrome, Firefox</p><p><strong>%f</strong> <em>Floating point value : </em>IE, Chrome, Firefox</p><p><strong>%o</strong> <em>Javascript object</em> : IE, Chrome, Firefox<br>Object will be pretty-printed or a link to the inspector.<br>DOM Object are also handled.</p><p><strong>%c</strong> <em>Apply these CSS rules to the following text. </em>Chrome, Firefox<br>Exemple :</p><pre>console.log(‘There are now %c%d%c listeners’, ‘font-weight: bold;’, 2, ‘font-weight: normal;’);<br>There are now <strong>2</strong> listeners</pre><p><strong>%b</strong> <em>Value as binary</em>: IE</p><p><strong>%x </strong><em>Value as hexadecimal</em>: IE</p><h3>Grouping messages</h3><p>Messages can be grouped with console.group() and console.groupCollapsed() and console.groupEnd().</p><pre>console.group(&#39;First group&#39;);<br>console.log(&#39;a&#39;);<br>console.log(&#39;b&#39;);<br>console.log(&#39;c&#39;);<br>console.groupEnd();</pre><pre>console.group(&#39;Second group&#39;);<br>console.log(&#39;1&#39;);<br>console.log(&#39;2&#39;);<br>console.log(&#39;3&#39;);<br>console.group(&#39;Embeded subgroup&#39;);<br>console.log(&#39;α&#39;);<br>console.log(&#39;β&#39;);<br>console.log(&#39;γ&#39;);<br>console.groupEnd(); // For the &quot;Embeded subgroup&quot; console.groupEnd(); // For the &quot;Second group&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/0*KuUuTbzSY35WqzA0.png" /></figure><pre>console.groupCollapsed(&#39;Pre-collapsed to save your eyes&#39;);<br>console.log(&#39;Never Gonna %s&#39;, &#39;Give You Up&#39;);<br>console.log(&#39;Never Gonna %s&#39;, &#39;Get you down !&#39;);<br>console.info(&#39;This is a potato&#39;);<br>console.groupEnd();</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/0*ZSz2c8hW_LbgJJvi.gif" /></figure><h3>Measuring &amp; profiling</h3><p>console.time() and console.timeEnd() allows you to measure the time elapsed between their call.</p><p>They both takes a label as argument so you can start simultaneously several timers (docs says up to 10,000) and know which one you want to stop.</p><pre>var slowInitializer = function() {<br>    var collection = [];<br>    for (var i = 20000000; i &gt; 0 ; i--) {<br>        collection.push(i);<br>        if (i === 1000) {<br>            console.time(&#39;Last iterations&#39;);<br>        }<br>    }<br>    console.timeEnd(&#39;Last iterations&#39;);<br>};<br>console.time(&#39;Slow initializer&#39;);<br>slowInitializer();<br>console.timeEnd(&#39;Slow initializer&#39;);</pre><pre>&gt;&gt; Last iterations: 0.123ms Slow initializer: 2778.002ms</pre><p>console.profile() and console.profileEnd() allows you to profile a part of your code.</p><p>console.profile() takes a label as argument so you can start simultaneously several timers (no infos on how many) ; console.profileEnd() will end the last started profiler.</p><p>The code profiling will be shown in the <em>profiles </em>or <em>profiler (</em>how any other related name) on your brower ; with the memory/cpu/calls etc usages.</p><pre>var fibonateIt = function(n) {<br>    return ((n &lt; 2) ? n : (fibonateIt(n-1) + fibonateIt(n-2)));<br>};</pre><pre>console.profile(&#39;Fibonnaci generation&#39;);<br>fibonateIt(32);<br>console.profileEnd();</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/0*Mpt7g0SXJ_zt7U2E.png" /></figure><p><em>On IE</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/0*ujLuW64NU0wsHCf9.png" /></figure><p><em>On Chrome</em></p><p>You may also use console.count() to count the times a label has been executed :</p><pre>$(&#39;#image&#39;).on(&#39;click&#39;, function() {<br>    console.count(&#39;Click on my image&#39;);<br>});</pre><pre>&gt;&gt; Click on my image : 1<br>&gt;&gt; Click on my image : 2<br>&gt;&gt; // [...]<br>&gt;&gt; Click on my image : 12</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/64/0*EAniKBbxGH2EVQJs.png" /></figure><p>Don’t use console.count() on fast and numerous loops (like previous previous example on the fibonacci numbers. This will cause your console to print a <strong>lot </strong>of information and make your browser slow/unstable/angry.</p><h3>Make a conditional logging</h3><p>console.assert() allows you to condition your debug by using a condition as its first argument.</p><p>If your first argument is false (loose comparison aka == and not ===), it will print out your message (or object), elsewhere it will be ignored.</p><p>For example, if you want to log every 100 iteration of a loop :</p><pre>for (var i = 0; i &lt;= 10000; i++) {<br>    // Do something awesome.<br>    console.assert(i % 1000, &#39;Iteration #%d&#39;, i);<br>}</pre><pre>&gt;&gt; &quot;Iteration #0&quot;<br>&gt;&gt; &quot;Iteration #1000&quot;<br>&gt;&gt; &quot;Iteration #2000&quot;<br>&gt;&gt; &quot;Iteration #3000&quot;<br>&gt;&gt; &quot;Iteration #4000&quot;<br>&gt;&gt; &quot;Iteration #5000&quot;<br>&gt;&gt; &quot;Iteration #6000&quot;<br>&gt;&gt; &quot;Iteration #7000&quot;<br>&gt;&gt; &quot;Iteration #8000&quot;<br>&gt;&gt; &quot;Iteration #9000&quot;<br>&gt;&gt; &quot;Iteration #10000&quot;</pre><p><strong>assert </strong>may sound like unit test to you, and of course, you can use it also to make some kind of unit testing, like :</p><pre>console.assert(<br>    (fibonateIt(-1) === -1),<br>    &#39;Fibonacci for -1 should be -1&#39;<br>);<br>console.assert(<br>    (fibonateIt(0) === 0),<br>    &#39;Fibonacci for 0 should be 0&#39;<br>);<br>console.assert(<br>    (fibonateIt(10) === 55),<br>    &#39;Fibonacci for 10 should be 55&#39;<br>);</pre><h3>Pretty-print tabular datas (Arrays, objects, etc.)</h3><p>console.table() allows you to debug some tabular datas in a graphical table in your console :</p><pre>console.table([[&#39;a&#39;, &#39;b&#39;, &#39;c&#39;], [&#39;easy as&#39;], [1,2,3]]);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/0*ZfvC0yyWz0n4d51c.png" /></figure><p>Some browsers “decides” if whether a table is needed or not to display your data. For example, console.table([1,2,3]); will probably not be displayed in a table.</p><p>You can filter out the fields you would like to show :</p><pre>var Crush = function(name, hobby, salary, cute) {<br>    this.name = name;<br>    this.hobby = hobby;<br>    this.salary = salary;<br>    this.cute = cute;<br>};</pre><pre>var venal_crushes = [<br>    new Crush(&#39;john&#39;, &#39;animals&#39;, &#39;70K&#39;, true),<br>    new Crush(&#39;steeve&#39;, &#39;cars&#39;, &#39;0K&#39;, false),<br>    new Crush(&#39;peter&#39;, &#39;computers&#39;, &#39;160K&#39;, false),<br>    new Crush(&#39;marcel&#39;, &#39;france&#39;, &#39;20K&#39;, true)<br>];</pre><pre>console.table(venal_crushes, [&#39;name&#39;, &#39;salary&#39;]);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/0*QO8Sx7tz_UbK9ily.png" /></figure><h3>Log a stack trace</h3><p>console.trace() allows you to show a stack trace to the line where you called it.</p><pre>var a = function() {<br>    console.trace(&#39;Hello I\&#39;m a stack trace&#39;);<br>};</pre><pre>var b = function() {<br>    a(5);<br>};</pre><pre>var c = function() {<br>    b();<br>};</pre><pre>var d = function() {<br>    try {<br>        throw new Error(&#39;Ouch&#39;);<br>    } catch(err) {<br>        c(err);<br>    }<br>};</pre><pre>(function() { d(); })();</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/0*JvgIvd7M4fFl8YiV.png" /></figure><p><em>Originally published at </em><a href="https://github.com/jucrouzet/til/blob/b024a15bd58cda05f5c7c16d26dea00b4f081772/javascript/console_lesser_known_features.md"><em>github.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9fe3852ce48b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>