<?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 Cookie Engineer on Medium]]></title>
        <description><![CDATA[Stories by Cookie Engineer on Medium]]></description>
        <link>https://medium.com/@cookiengineer?source=rss-42d40cbc7945------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bz9SDjiKWNEE0eB_biD-Jw.png</url>
            <title>Stories by Cookie Engineer on Medium</title>
            <link>https://medium.com/@cookiengineer?source=rss-42d40cbc7945------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 21:00:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cookiengineer/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[The best headphones for ADHD coders and audiophiles]]></title>
            <link>https://medium.com/@cookiengineer/the-best-headphones-for-adhd-coders-and-audiophiles-749ae84d0ff3?source=rss-42d40cbc7945------2</link>
            <guid isPermaLink="false">https://medium.com/p/749ae84d0ff3</guid>
            <category><![CDATA[sports]]></category>
            <category><![CDATA[audiophile]]></category>
            <category><![CDATA[music]]></category>
            <category><![CDATA[headphones]]></category>
            <dc:creator><![CDATA[Cookie Engineer]]></dc:creator>
            <pubDate>Wed, 01 Aug 2018 18:42:44 GMT</pubDate>
            <atom:updated>2018-08-01T20:42:34.665Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>Okay, so this time my headphones broke down, again. I typically have two different types of headphones, one that I’m using for stationary purposes and one pair that I’m using when doing sports (aka slack-lining or doing martial arts forms in the park).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GiUCdVDGdOHlTjgORB3pIQ.jpeg" /><figcaption>AKG K242HD — best headphones I’ve ever tested © Image by <a href="https://www.kopfhoerer.de/test/akg-k-242-hd/">kopfhoerer.de</a></figcaption></figure><p>For the stationary purpose, I use the K242HD headphones because they are cheap, reference-class and you can find them in pretty much every audio studio on the planet. By cheap I mean around <a href="https://www.ebay.com/sch/i.html?_nkw=AKG+K242HD">50 bucks on ebay</a> if you’re lucky. They are also over-ear headphones (not on-ear and not in-ear), which means they are very comfortable to wear for longer periods and you can even sleep with them in case you have a noisy environment. The downside of the K242HD is that they ship with a cable so long that you could easily use it as a lasso. Also, the klinke plug is mounted directly with the cable, so you cannot modify and use them in case you have a military-grade IP68 smartphone (as I do) as the plug just won’t fit in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*BTPz_L89j7DclqpuZBuqYA.jpeg" /><figcaption>Etymotic HF5 — very good sports headphones using klinke plugs © Image by <a href="http://headphones100.com/review-etymotic-hf5-in-ear-headphones/">headphones100.com</a></figcaption></figure><p>For sports purposes I was still using in-ear non-bluetooth headphones most of the past time, because the bluetooth ones were so ridiculously expensive that they were also actually never worth using. Seriously, the market is flooded with 180EUR+ models that are total crap — I mean, why build a product that can be used for 4 hours and has a charging time of 2 hours while it cannot be used? How do you even come up with an idea like that?</p><p>So previously, I was using the Etymotic HF5 and they are pretty amazing. Very well implemented plugs, they stick in my ear (usually other models don’t) and you don’t hear surrounding noise. You can literally stand next to the Autobahn and hear nothing of the traffic nearby. They were around 80–90 bucks depending on where you would buy them. I also modified the cables to have some shrinking tubes on them so they are a bit more sturdy.</p><p>The only problem is: They break down every 6 months and are impossible to re-solder afterwards. So quality-wise the common denominator is always breaking cables for my sport headphones.</p><h3>DIY noise cancelling headphones</h3><p>Okay, so it was time for reflection on what I want. In the past, I tried to build an analog noise-cancelling self-made product with the <a href="https://reddit.com/r/3dprinting">/r/3dprinting </a>community. A pretty nice introduction on how to build those using some electronic parts and an easy circuit with an Arduino is available here to get you started, in case you want to go for it: <a href="https://www.instructables.com/id/Analog-Noise-Cancelling-Headphones/">https://www.instructables.com/id/Analog-Noise-Cancelling-Headphones/</a></p><p>But you can pretty much forget analog noise-cancelling as the frequencies it can blend out are very very limited and have a specific range. Usually they focus either on middle frequencies or lower frequencies, depending on how the electronics circuit looks like. In my case, the final product also weighted around 1.5kg, so it wasn’t really ready for real-world usage.</p><p>An additional problem that should not be underestimated is the quality of the enclosure and sound waves that can’t escape. For that reason most noise cancelling headphones are actually not closed, and usually are open and have the microphones on both sides on the outside. If you want to build that yourself like in my case, I heavily recommend to use a polycarbonate-ready printer. You won’t have a good time using PLA, as it will break down very easily and the material is just not made for both the flexibility and sturdiness requirements.</p><p>Again, this is very hard to do… and you can only progress by iterative tryouts, I spent literally 5 months non-stop and finally kind of gave up to build something like this myself. Analog noise cancelling just causes more troubles in the build process than it actually solves.</p><p>Nevertheless it was a nice experience to figure out what I actually want from my headphones, and I learned a lot when it comes to acoustics and the underlying electronic circuits.</p><h3>Specifying what to buy</h3><p>My specifications for my new replacement headphones for sports are the following:</p><ul><li>Bluetooth, as I don’t want to fuck with cables anymore. Srsly, fuck cables in particular, man. Ain’t doing that no more.</li><li>Listening time of at least 12 hours so I can stay in the zone without interruptions.</li><li>Price should be around 50–100 bucks, not more — because higher price ranges are flooded with crap products and my risk assessment algorithm just says no to going for high price-range products. Looking at you, Bose, Beats, JPL and the like. You let me down in the past too often.</li></ul><h3>How to find recommendable models</h3><p>First, I was trying to use my Google Fu to come up with some good reviews that I could rely on. But they were so shitty most of the time that you could not rely on them — srsly, they were totally opinionated, diversed and in multiple price ranges. So you had reviews where both 40 bucks and 400 bucks headphones were tested. I cannot express how wrong the testing criteria actually is, but I’m not gonna dig into that for now.</p><p><strong>Then I thought: What about amazon reviews?</strong></p><p>So I built a little scraper plugin for my AI “cluster” and let it run for a couple minutes. My criteria for the reviews were mostly trying to find the best ones, where the price range stays below 100 bucks for the product (in unused and still-has-warranty condition).</p><p>The winners of that criteria were the following headphones (in the order from 1st to 3rd):</p><ul><li>Mpow 059 (4.5/5 rating, 20hrs playtime, 34.99$): <a href="https://www.amazon.com/dp/B01NAJGGA2/ref=twister_B01N5ETX25?_encoding=UTF8&amp;psc=1">Amazon Link</a></li><li>COWIN E7 (4.3/5 rating, 30hrs playtime, noise cancelling, 60.29$): <a href="https://www.amazon.com/dp/B019U00D7K/ref=psdc_12097479011_t1_B01NAJGGA2">Amazon Link</a></li><li>Avantree Audition (4.3/5 rating, 40hrs playtime, 44.99$): <a href="https://www.amazon.com/Avantree-Bluetooth-Headphones-COMFORTABLE-Lightweight/dp/B00J0BXPD4?ascsubtag=[]st[p]cj63ustkt00327lyewskmt8kt[i]Slh8Yj[z]m[d]D[r]nymag.com/consent.html&amp;tag=strat-related-prod-20">Amazon Link</a></li></ul><h3>Summing it up</h3><p>So in my case, I was going for the Cowin E7 headphones, as they also had active noise cancelling built-in and were closed over-ear headphones. I’m currently still waiting for the package to arrive, but I’m confident that the amazon community won’t let me down. I’ll update this post with the review once I’ve used them for a while and have a good feeling on how they compare to my reference-class headphones (the AKG K242HD ones).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=749ae84d0ff3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I implemented my own JSON.stringify() and console API]]></title>
            <link>https://medium.com/@cookiengineer/why-i-implemented-my-own-json-stringify-and-console-api-c711dac38fa8?source=rss-42d40cbc7945------2</link>
            <guid isPermaLink="false">https://medium.com/p/c711dac38fa8</guid>
            <category><![CDATA[v8]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[servers]]></category>
            <dc:creator><![CDATA[Cookie Engineer]]></dc:creator>
            <pubDate>Wed, 25 Jul 2018 10:42:38 GMT</pubDate>
            <atom:updated>2018-07-25T10:42:38.721Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>This time, I am writing an article that could be interpreted as a nerdraging one. But actually, I’m just trying to fix stuff so that I can focus on work instead; without getting annoyed all the time that debugging is so hard.</p><h4>TL;DR</h4><p>node.js console API is shitty, JSON.stringify() sucks, this is the polyfill for a better developer experience: <a href="https://gist.github.com/cookiengineer/05581bc59f5d7d3dbaa09e6018678740">https://gist.github.com/cookiengineer/05581bc59f5d7d3dbaa09e6018678740</a></p><h4>Why</h4><p>In node.js, the console API is pretty much the definition of being utterly useless. Every time you want to console.log(object) and the object is, say, of nested nature, you can’t see shit about what’s going on. Not only that, the standard (native) console API also totally does not print out functions when an object has one.</p><p>Every time I am debugging whether or not the current object actually has methods, I have to manually do something like this, just to be able to see what’s going on:</p><pre>let keys = Object.keys(object);</pre><pre>keys.forEach(key =&gt; {<br>    console.log(key, typeof object[key]);<br>});</pre><p>To be honest, this is a huge time killer for me. Debugging console.log() statements in a server-side log, maybe even connected via ssh, is making me smash my keyboard into the monitor.</p><h4><strong>Step 1: Formulating the Problem</strong></h4><p>Okay, so I started to reflect on the underlying problem: Why do I get pissed? What’s the problem? What’s the inefficiency? How would my ideal console API look like?</p><p>I started to mock up some ideas I had in mind, and took some notes over a couple hours on what particular stuff I was dumping in the console and why I had to rework my code, and re-execute the program(s) later. Turns out most of my use cases that were pretty simple:</p><ul><li>console.log(long_array) leads to shitty displays, and I need to scroll up and down and actually log it in chunks, so that I have less scroll space used</li><li>console.log(matrix) makes my head hurt, because I usually have matrices in a one-dimensional array and I have no idea which index I’m looking at in the console dump</li><li>console.log(nested_object) usually is reduced in the second hierarchy, I’d prefer something similar to JSON.stringify(), but for ALL data types, not hiding any properties on the objects</li><li>console.log(object) is shitty when I want to debug instances of functions (instances of classes, composites, or whatever). Mostly because properties with their type being a function is unreadable, even when using a JSON.stringify replacer is making situation worse as it will lead to \\n all over the place. Impossible to desanitize later.</li></ul><p><strong>Implementing a better console API for node.js</strong></p><p>So I like things minimal, I like things without dependencies and I like things shiny and sparkly in my Terminal. We have 2018, so a colored console can be assumed pretty much anywhere. If not, then the user should write perl code instead and just get on with his dying craftsmanship.</p><p><strong>Color Codes</strong></p><p>So I decided I want color codes in the shell when using the console API in order to identify logs that have different types more efficiently. Emojis usually fail via SSH (I guess UTF8 is still messed up everywhere), so for the time being I just stay with good ol’ color codes:</p><ul><li>console.info() should be highlighted in green</li><li>console.warn() should be highlighted in yellow</li><li>console.error() should be highlighted in red</li><li>console.log() should stay uncolored</li><li>console.clear() should clear the console, so that the screen usage is more efficient when being used via, say, ssh or similar network tunnels</li></ul><p>As not all shells and usages later support color codes, there should be an identifier as the first character per-statement that identifies the type. This would be something like (L) for console.log() calls, and (I) , (W) or (E) for the other log levels.</p><p><strong>Data Types</strong></p><p>Usually when debugging stuff in the console, some data types are totally messed up. For example console.log(new Date()) will be pretty much random on how it will be printed, and when working with timestamps and optimizing large code bases, you have no idea what you’re looking at because shit gets complex with many states real fast.</p><p>Also, arrays that contain primitives should be rendered differently than arrays containing, say, nested objects. If it contains only primitives, it usually would be better to just render it in a single line (given it’s no matrix), as the values and cells are much easier to both count and identify then.</p><p>If an array is a matrix, and matches the criteria of being power-of-two it can be rendered in a squared form. Also, usually matrixes contain many many values, and when the commas of the cells are not arranged, it is very very hard to debug what’s going on. So this auto-alignment feature is key to being more efficient when looking at those matrix arrays.</p><p>Primitive data types should behave like JSON, but extend it so that Infinity, -Infinity , NaN and undefined are also printed correctly.</p><h4>Step 2: Trying to use JSON.stringify()</h4><p>When trying to implement a little helper method, most solutions on the internet (aka stackoverflow) suggest using a custom replace for JSON.stringify() — but I heavily disrecommend it for the following reasons:</p><p>If you use JSON.stringify() with properties that would be rendered in multiple lines (e.g. a large array, a function body or nested objects), you cannot implement it using the replacer callback, as every string returned will be mapped with \\n in the end and are pretty much impossible to sanitize later.</p><pre>let object = {<br>    foo: function() {<br>        return &#39;something&#39;;<br>    }<br>};</pre><pre>console.log(object); // Look ma, it&#39;s gone!</pre><pre>let blob = JSON.stringify(object, &#39;\t&#39;, function(key, val) {<br>    if (typeof val === &#39;function&#39;) {<br>        return (val).toString();<br>    } else {<br>        return val;<br>    }<br>});</pre><pre>console.log(blob); // will have a single line containing the function body, but with a value similar to &quot;function(){\\n...&quot;</pre><p>So yeah, we’ve pretty much ruled out JSON.stringify() with above problem already. It gets more complex when you want to render different types of arrays in a different manner, but we’ll ignore that for now.</p><p>Let’s just assume that I spent several hours trying to desanitize the strings correctly later, and I finally gave up because there’s no real solution to it that won’t fuck up function bodies that have, say something like return &#39;\n&#39;; in them.</p><h4>Step 3: Implementing a custom console API</h4><p>Now that we’ve cleared up what we cannot use, it’s time to describe on what we can actually use to implement above described featureset. In order to render things correctly, we will have to implement the following featureset in a custom manner:</p><ul><li>_stringify(data, indent) to have a similar behaviour as JSON.stringify(data, &#39;\t&#39;) would have</li><li>_args_to_string(args, offset) so that we can use multiple arguments in the console.log(a, b, c) statements and an offsetthat allows us to indent things based on the process.stdout.columns so that the full terminal width can be used</li></ul><p>It’s probably a bit too complicated to dig into the code more in detail, but the polyfill for the better console API is — for the sake of simplicity — put into a gist over here on github: <a href="https://gist.github.com/cookiengineer/05581bc59f5d7d3dbaa09e6018678740">https://gist.github.com/cookiengineer/05581bc59f5d7d3dbaa09e6018678740</a></p><h4>Step 4: The final result</h4><p>So when using a demo code like this:</p><pre>#!/usr/bin/env node</pre><pre>require(&#39;./console-polyfill.js&#39;);</pre><pre>let data1 = {<br>    foo: {<br>        bar: {<br>            qux: [<br>                1,<br>                2.3,<br>                true,<br>                false,<br>                Infinity,<br>                -Infinity<br>            ]<br>        }<br>    }<br>};</pre><pre>let data2 = {<br>    time: new Date(),<br>    method: function(a, b, c) {</pre><pre>// Look ma, it&#39;s correctly indented!<br>        if (a === b) {<br>            return c + 1;<br>        }</pre><pre>return a + b;</pre><pre>},<br>    matrix: [<br>         1,  2,  3,  4,<br>         5,  6,  7,  8,<br>         9, 10, 11, 12,<br>        13, 14, 15, 16<br>    ]<br>};</pre><pre>console.log(&#39;Better console API demo&#39;);<br>console.info(new Date());</pre><pre>console.log(data1);</pre><pre>console.warn(data2.time);<br>console.log(data2);</pre><pre>console.info(new Date());</pre><p>… it will lead to this pretty and shiny output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*k4FkLfT4XF92eqBGZRxAig.png" /><figcaption>Better console API for node.js</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c711dac38fa8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Faith in Humanity: Busted — The Nazi Bell]]></title>
            <link>https://medium.com/@cookiengineer/faith-in-humanity-busted-the-nazi-bell-2b6f430f58f1?source=rss-42d40cbc7945------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b6f430f58f1</guid>
            <category><![CDATA[conspiracy-theories]]></category>
            <category><![CDATA[tinfoilhatshit]]></category>
            <category><![CDATA[chronograph]]></category>
            <category><![CDATA[antigravity]]></category>
            <category><![CDATA[nazi-bell]]></category>
            <dc:creator><![CDATA[Cookie Engineer]]></dc:creator>
            <pubDate>Fri, 11 May 2018 18:34:29 GMT</pubDate>
            <atom:updated>2018-05-16T10:46:35.019Z</atom:updated>
            <content:encoded><![CDATA[<p>Okay folks, today I was casually browsing YouTube and then something amazing happened: The autoplay functionality led me to some tinfoil hat idiots channel.</p><p>The video that was being played there was titled: “The Nazi Bell: Secret Anti-Gravity Technology” and I was kind of curious, assuming some scientists in the Nazi era were also working on the base research of Nikola Tesla’s EM drive — which currently is being validated in space, because it worked in the almost-vacuum tests at the JPL lab.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FHvKF7v_TmWI%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DHvKF7v_TmWI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FHvKF7v_TmWI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/22b7a096f91916a2cd8702779fbadd19/href">https://medium.com/media/22b7a096f91916a2cd8702779fbadd19/href</a></iframe><p>But apparently, there’s an internet full of millions of people that believe that the nazis had that kind of technology already, anti-gravity bells that were “chained so they do not take off into the sky” (literally that’s what she said).</p><p>So I was then curious what the underlying base input data was, so that people get so confused and literally think this is legit.</p><p>Turns out that the underlying patent was from <a href="http://www.hanhart.com/">Hanhart</a>, a well-known Germany manufacturer of chronographs (which is basically wrist watches or clocks for that matter, just to be clear). Some people were probably reading chronographs and knew the word “chrono” — assuming it then must have had to do with time travel. Because there’s also a scene that assumes the Nazi Bell was a time machine :D</p><p>Long story short, here are the scanned photos of the patent regarding the chronograph; or the “Nazi Bell” not-a-time-machine-and-neither-an-emdrive-thingie:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*-cDvtuRef6SQivC7Q4R-rA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*IkQJzbMNtwZc_QyHJrGRQA.jpeg" /><figcaption>“Die Glocke” or “The Nazi Bell”, which is basically a wrist watch and not a time machine. Sorry to disappoint you.</figcaption></figure><p>Translating above photos for non-German speaking readers: It describes a pocket watch, or chronograph for that matter, which is able to display not only hours and seconds, but also years, months and days.</p><p>They also combined the chronograph with another feature that lets you measure width and height of objects (assuming GPS was not available at the time, otherwise it could’ve been longitude/latitude, but please don’t think they invented GPS. They did not, GPS is digital technology.).</p><p>The button on the top changes the functionalities of the chronograph and basically toggles between a “relative” measurement mode (like in Olympics competitions) and absolute mode to display the current date/time.</p><p>The second photo or attachment B of the document describes pretty much only the front cover and back cover of the watch. It has some electrodes that are connected to the back cover, which are probably either for recharging purposes or anti-static purposes; so that when you walk with rubber shoes on a carpet the watch does not break.</p><p>As the patent is a design document, it does not describe the internals of the watch, so we can’t know for sure whether it was already of electrical nature or whether it still used a mechanical source of energy (like a gyro wheel / dynamo).</p><p><strong>Further Thoughts</strong></p><p>So, the idea of this blog series is that when I find some funny (in the being stupid sense) videos on the internet, and I feel the obligation to bust them — then I will write some more detailed article about them.</p><p>What do you think? Awesome or not? Suggestions on what video I should watch next? Reply below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b6f430f58f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The day autoconf broke half the Linux world (and probably half the internet)]]></title>
            <link>https://medium.com/@cookiengineer/the-day-autoconf-broke-half-the-linux-world-and-probably-half-the-internet-ad59da168a0a?source=rss-42d40cbc7945------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad59da168a0a</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[gnome]]></category>
            <category><![CDATA[autoconf]]></category>
            <category><![CDATA[c]]></category>
            <category><![CDATA[gtk]]></category>
            <dc:creator><![CDATA[Cookie Engineer]]></dc:creator>
            <pubDate>Sat, 21 Jan 2017 15:53:57 GMT</pubDate>
            <atom:updated>2017-01-21T20:37:30.871Z</atom:updated>
            <content:encoded><![CDATA[<p>Okay, this is kind of a rant post. I’m not sure how this article will turn out, but I think it’s quite important.</p><p>Somehow autoconf introduced special “[” and “]” characters somewhere over the last year. As many of you might guess, many many build files (probably all) somewhere use sed to find out version numbers from raw header source files of libraries those projects use.</p><p>As the #define syntax in C/C++ allows to have spaces in between, the syntax of an sed command uses optional whitespaces in the regular expression. sed needs the [[:space:]] syntax to work properly and will fail once you only use [:space:] .</p><p>Now with the autoconf update, this broke all sed commands that use whitespaces; of every open source library using autoconf; of every open source project; on every build server; worldwide.</p><p>I’m now busy fixing mozjs (spidermonkey), so that I can fix gjs, so that I can fix gtk3, so that I can fix gnome-shell so that I can go on with my normal dev life and use my computer again :-/</p><h3>TL;DR</h3><p>If you use autoconf, all your projects probably broke.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad59da168a0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning for Dummies: Part 2]]></title>
            <link>https://blog.chatbotslife.com/machine-learning-for-dummies-part-2-270165fc1700?source=rss-42d40cbc7945------2</link>
            <guid isPermaLink="false">https://medium.com/p/270165fc1700</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Cookie Engineer]]></dc:creator>
            <pubDate>Thu, 19 Jan 2017 18:21:49 GMT</pubDate>
            <atom:updated>2017-01-25T11:09:58.101Z</atom:updated>
            <content:encoded><![CDATA[<p>The last article covered an introduction to Neural Networks and Evolutionary AI Concepts, in particular Genetic Programming and NEAT.</p><p>In case you’ve missed it, it is required to understand this article. So go ahead and read it first: <a href="https://medium.com/@cookiengineer/machine-learning-for-dummies-part-1-dbaca076ec07">https://medium.com/@cookiengineer/machine-learning-for-dummies-part-1-dbaca076ec07</a></p><p>This article will focus on Neural Networks and Feed-Forward Neural Networks in general. It will cover the implementor’s view on things and (hopefully) be easy to follow.</p><h3>0. Back to Neural Networks</h3><p>In order to understand how Backpropagation works we first need to get back to Neural Networks themselves. If you remember, Neural Networks basically look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*3lBKD_dVPzlTiEfZ9QBBMA.png" /><figcaption>Neural Network architecture (Input layer, hidden layers and output layer)</figcaption></figure><p>We also know that neurons themselves always have a value and weights representing their connections to the neurons of the previous layer. When talking about previous and next, previous means a layer more to the left in our architecture chart.</p><p>So, for example, layers[1] in our above network has 4 neurons with 2 weights each (because the layers[0] is the input layer and has 2 neurons).</p><pre>// A neuron inside a NN where the hidden layers<br>// (and input layer) have each 3 neurons</pre><pre>let neuron = {<br>    value:   _random(),        // value for computation<br>    weights: [ 0.5, 0.5, 0.5 ] // weights for connections<br>};</pre><p>In order to understand the concept of backpropagation, we first have to take a step back and understand how a neural network is implemented.</p><p>Don’t be afraid, a simple feed forward neural network is a few lines of code and not so complicated as everyone thinks they are.</p><p>Our example Brain will be constructed in a generic sense, so that we can reuse it later for our own games and even in our advanced NEAT projects.</p><h3>1. Implementing Neural Networks</h3><p>A Neural Network consists of three different types of layers in our Brain: an input layer, some hidden layers and an output layer.</p><pre>const Brain = function() {</pre><pre>    // TODO: Proper initialization<br>    this.layers = [];</pre><pre>    // input layer<br>    // this.layers[0]</pre><pre>    // output layer<br>    // this.layers[this.layers.length - 1]</pre><pre>    // each layer has multiple neurons<br>    // this.layers[l][n] is a Neuron</pre><pre>};</pre><p>Many people ask how big a neural network should be until it works. As an ANN guy, I have something like a “rule of thumb” for the size, arguing with the situation that every input neuron must be able to reach an output neuron diagonally, so that a worst-case XOR situation from the “most top input” to the “most bottom output” can be computed successfully.</p><p>However, if you have time-sensitive data this might not be what you want. I’m going to dig into time-sensitive data problems later in this article series as it’s not so simple to understand right now.</p><p>The important part to remember is that in the minimum situation of 1 input and 1 output we still need at least 3 layers for our network, having one input layer, one hidden layer and one output layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*tSmKPlVFpTlryhdUO0ipMw.png" /><figcaption>Neural Network Size (Rule of Thumb)</figcaption></figure><p>Note that in the right example the diagonal overlapping over the horizontal center is important; as this will allow decisions made from the most top input to be influenced by decisions made from the most bottom input.</p><p>Other people have a different “strong” opinion on that, they like mathematical proof and “you can’t argue with that” and bla.</p><p>I don’t care; it works, is simple to remember and gets the job done and causes no problems in situations the math guy didn’t respect. So far my own experience hasn’t proven me wrong with that rule of thumb; but I encourage you to try to find scenarios where it won’t work.</p><p>To describe our network sizes in code, we now need four different sizes to create a neural network:</p><ul><li>input_size that represents our input (sensor) array’s length</li><li>output_size that represents our output (control) array’s length</li><li>layers_size that represents the amount of layers we need</li><li>hidden_size that represents the amount of neurons per hidden layer</li></ul><p>In code the above “rule of thumb” implementation looks like this:</p><pre>let input_size  = 2; // or, whatever<br>let output_size = 2; // or, whatever<br>let layers_size = 3;<br>let hidden_size = 1;</pre><pre>if (input_size &gt; output_size) {<br>    hidden_size = input_size;<br>    layers_size = Math.max(input_size - output_size, 3);<br>} else {<br>    hidden_size = output_size;<br>    layers_size = Math.max(output_size - input_size, 3);<br>}</pre><h3>2. Example Brain Implementation</h3><p>Now that we know how the rule of thumb can be used to compute a network’s size, we can now start to implement it.</p><p>A typical implementation also wraps Math.random() into something that we can clamp from -1.0 to 1.0 as Math.random() itself in JS (or other languages) only generates values from 0.0 to 1.0 .</p><pre>const _random = function() {<br>    return (Math.random() * 2) - 1);<br>};</pre><p>Neuron values and weights can also be negative! So we need to keep that in mind when debugging our code.</p><p>We also know from the first article that we need to implement an activation function. For now, sigmoid is enough and we implement it like this:</p><pre>const _sigmoid = function(value) {<br>    return (1 / (1 + Math.exp((-1 * value) / 1)));<br>};</pre><p>Going on with our Brain implementation, we need to initialize it properly. As before, we use the same data structures and layers[] array to represent the contents of our neural network.</p><p>When we generate our neural network, we also have to differ between the three different cases:</p><ol><li>The input layer’s neurons have no weights as they are not connected into the previous (to the left) direction.</li><li>Each hidden layer’s neuron has a weights[] array with the same size as the neuron amount from its previous (to the left) layer.</li><li>The output layer is identical in its behaviour as the hidden layers (each neuron has also a weights[] array), but the amount of neurons is the size of the outputs array, therefore it can be different in size compared to the hidden layer and/or input layer.</li></ol><p>An Example implementation can look like this:</p><pre>const Brain = function() {<br>    this.layers = [];<br>};</pre><pre>Brain.prototype.initialize = function(inputs, outputs) {</pre><pre>    // TODO: Task for reader - Insert Rule of Thumb from above<br>    let input_size  = 3;<br>    let output_size = 2;<br>    let layers_size = 3;<br>    let hidden_size = input_size &gt; output_size ? input_size : output_size;</pre><pre>    this.layers = new Array(layers_size).fill(0).map((layer, l) =&gt; {</pre><pre>        let prev = hidden_size;<br>        let size = hidden_size;</pre><pre>        // input layer<br>        if (l === 0) {<br>            prev = 0;<br>            size = input_size;<br>        // first hidden layer<br>        } else if (l === 1) {<br>            prev = input_size;<br>        // output layer<br>        } else if (l === layers_size - 1) {<br>            size = output_size;<br>        }</pre><pre>        // neuron has value and weights (for each previous neuron)<br>        return new Array(size).fill(0).map(_ =&gt; ({<br>            value:   _random(),<br>            weights: new Array(prev).fill(0).map(val =&gt; _random())<br>        }));</pre><pre>    });</pre><pre>};</pre><pre>Brain.prototype.compute = function(inputs) {<br>    // TODO: This will come up next<br>    return null;<br>};</pre><p>As our Example Code above shows, we currently totally ignore training of our Brain as we are not quite ready to understand Backpropagation. Our Neural Network currently gives us only seemingly random outputs to a given set of inputs.</p><p>Alternatively, we can find the weights for each neuron by using evolution or genetic programming (as we’ve learned in the previous article).</p><p>The usage of our Brain implementation is quite simple:</p><pre>// API Usage</pre><pre>let brain = new Brain();<br>let data  = { inputs: [1,0], outputs: [1] };</pre><pre>// inititalize by reference dataset<br>brain.initialize(data.inputs, data.outputs);</pre><pre>// compute inputs and return outputs<br>let outputs = brain.compute(data.inputs);</pre><pre>console.log(&#39;computed:&#39;, outputs);<br>console.log(&#39;expected:&#39;, data.outputs);</pre><p>Note that the usage prepares already for reinforcement learning, so we kind of implement a Brain.prototype.learn(inputs, outputs) method later when we understand backpropagation properly.</p><p>The complete code of the above Brain implementation is available in the <a href="https://github.com/cookiengineer/machine-learning-for-dummies">github repository</a>.</p><h3>3. Implementing Feed-Forward Computation</h3><p>A Feed Forward Neural Network is a simple NN that is only forwarding its values based on the neuron’s connections (weights). As every neuron is typically having randomized weights initially, the use cases of them are fairly limited.</p><p>However, given a Genetic Programming or Evolution concept, they can be powerful NNs that can learn quick, fast and efficient. Typical use cases are bruteforcing or guessing of complex data structures in an efficient manner (for example in the cryptography sector).</p><p>As Feed Forward NNs are *very* easy to implement, we gonna dig into them before we can go and understand how backpropagation (and reinforcement in general) works.</p><p>A typical FFNN is simple to implement and only has two different use cases that we must respect in our code when iterating from the input layer (from the left) to our output layer (to the right):</p><ol><li>The input layer is a special case. No weights, we directly update the each neuron’s values.</li><li>For each hidden layer’s and the output layer’s neuron, we map and store the sum of values into the values variable and summate them together. Afterwards, we activate the neuron with the _sigmoid(value) method where value is the sum of the values of all connected neurons.</li></ol><p>Taking our Example from above, we need to override its Brain.prototype.compute(inputs) method with this code:</p><pre>Brain.prototype.compute = function(inputs) {</pre><pre>    let layers = this.layers;</pre><pre>    // set input values<br>    layers[0].forEach((neuron, n) =&gt; neuron.value = inputs[n]);</pre><pre>    // feed forward for hidden layers + output layer<br>    layers.slice(1).forEach((layer, l) =&gt; {</pre><pre>        let prev_layer = layers[layers.indexOf(layer) - 1];</pre><pre>        layer.forEach(neuron =&gt; {</pre><pre>            // neuron.weights[p] represents connection<br>            let values   = prev_layer.map((prev, p) =&gt; prev.value * neuron.weights[p])<br>            let value    = values.reduce((a, b) =&gt; a + b, 0);<br>            neuron.value = _sigmoid(value);</pre><pre>        });</pre><pre>    });</pre><pre>    // return output values<br>    return layers[layers.length - 1].map(neuron =&gt; neuron.value);</pre><pre>};</pre><p>As we might remember from the previous article, the _sigmoid(value) method is important. It activates each neuron based on the total of values of the previous neurons.</p><p>The neuron.value currently is mostly existing for easy computation purposes right now, as we don’t reuse it except for the generation of the outputs array that is returned by our compute(inputs) method. BUT we need it later for backpropagation, so that we can learn from input values.</p><p>Each neuron’s weight represents the connection to the previous layer. In the above example code that means neuron.weights[p] is equivalent to the layers[l — 1][p] as that is the previous layer’s neuron with the same index.</p><p>Each neuron.weights array is therefore identical in its size to the amount of neurons in the previous layer (layer to the left).</p><h3>TL;DR</h3><p>Neural Networks are important to understand. Rule of thumb is to have an NN layers amount that allows diagonal crossovers to the outputs. Implementing Feed Forward NNs is easy, and necessary to do before moving on into backpropagation and Reinforcement Learning techniques.</p><p>I created a <a href="https://github.com/cookiengineer/machine-learning-for-dummies">github repository</a> with all collected contents of this article series.</p><h3>What’s Next</h3><p>Now that we know how Neural Networks work, we can now dig into Backpropagation and start with the Reinforcement Learning aspect of Neural Networks.</p><p>This article is not ready (yet) but I guess I’ll update this section here with a link and stuff.</p><p>Got comments or questions? Reply below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*bQlRSzFHJEmF4Q7PyrLgng.gif" /></figure><figure><a href="https://chatbotslife.com/bot-communities-mastermind-group-d2dae9876709#.53x0py6ou"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*6XUspT9JOSq0w0Fi35HIaA.png" /></a></figure><figure><a href="https://m.me/ChatbotsLife"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*c1LDMH5vbnIz9rmAka8Hwg.png" /></a></figure><figure><a href="https://chatbotslife.com/how-to-get-a-free-chatbot-b1fb9dfe109#.z9dtp2sy0"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*D0Jf3dI6ZThtqcfwDYY7mg.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=270165fc1700" width="1" height="1" alt=""><hr><p><a href="https://blog.chatbotslife.com/machine-learning-for-dummies-part-2-270165fc1700">Machine Learning for Dummies: Part 2</a> was originally published in <a href="https://blog.chatbotslife.com/">Chatbots Life</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning for Dummies: Part 1]]></title>
            <link>https://blog.chatbotslife.com/machine-learning-for-dummies-part-1-dbaca076ec07?source=rss-42d40cbc7945------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbaca076ec07</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[Cookie Engineer]]></dc:creator>
            <pubDate>Mon, 16 Jan 2017 12:24:04 GMT</pubDate>
            <atom:updated>2020-01-08T12:57:19.912Z</atom:updated>
            <content:encoded><![CDATA[<h4>Code Snippets &amp; Github Included</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3CXBOKNql4qS-lRyHT3pqw.png" /><figcaption>Machine Learning for Dummies</figcaption></figure><p>I often get asked on how to get started with Machine Learning. Most of the time, people have troubles understanding the maths behind all things. And I have to admit, I don’t like the maths either. Math is an abstract way of describing things. And I think the way machine learning is described is too abstract to understand it easily.</p><p>So in this article (series?) I probably try to describe things with foo code or a bit of JS to explain what I’m talking about.</p><p>There will also be an <a href="https://github.com/cookiengineer/machine-learning-for-dummies">experimental github repository</a> where I put everything together, so that you can follow the steps and implement things on your own. I say this is experimental because hurdles might appear from time to time :)</p><figure><a href="https://www.chatbotconference.com/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5QA4jEOW_w_mKaAW" /></a></figure><p>The first thing you have to know is that there are different concepts that allow different solutions.</p><p>There are some different solutions, I’ll dig into the more complex solutions later when you’re ready for them. The problems are mostly divided in time-sensitive data (RNNs and RNN LSTMs), visual or pixel-related data (CNNs) and simple vectorized data (BBNs, BNs, BNNs and QNNs).</p><p>However, there are more complex architectures around from the engineering and biological perspective; and I think they’re a quite powerful toolset to know — as they can be freely combined with “low-level” machine learning solutions.</p><h3>Top 3 Most Popular Ai Articles:</h3><blockquote><a href="https://chatbotslife.com/introduction-to-deep-learning-on-social-networks-how-to-learn-even-more-about-your-personal-life-cd1da6d67770">1) Intro to Deep Learning in Social Networks</a></blockquote><blockquote><a href="https://chatbotslife.com/ultimate-guide-to-leveraging-nlp-machine-learning-for-you-chatbot-531ff2dd870c">2) Ultimate Guide to Leveraging NLP &amp; NLU for you Chatbot</a></blockquote><blockquote><a href="https://chatbotslife.com/deep-learning-in-7-lines-of-code-7879a8ef8cfb">3) Deep Learning in 7 Lines of Code</a></blockquote><p>Explanation of all those concepts would be too much right now, as most of them have other — more coincidental — use cases in other areas like NLP, parsing complex texts or artistic painting.</p><p>I’m also trying not to be language specific and neither framework specific here. The demo codes are written in simple ES2017 JavaScript, so you can easily try them out and fiddle around with the demos.</p><p>The first topic I’ll cover in this article is the raw basics of Neural Networks, Genetic Programming and Evolution.</p><h3>0. Basics of Neural Networks</h3><p>Neural networks aren’t that hard to understand. They are only not-so-well explained to newbies. As everyone is using maths, I’m going to try a different method here.</p><p>If we talk about a simple neural network, it’s always structured in three different “categories”: Input layers, hidden layers and output layers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*3lBKD_dVPzlTiEfZ9QBBMA.png" /><figcaption>(Basic) neural network structure</figcaption></figure><p>The input layer typically represent sensors, where each input value of the array represents a value from 0.0 to 1.0. People like to name that vectors, I name them arrays with values.</p><p>The output layer represents typically a yes/no type of answer to a question — or in other use cases vectorized properties. That could be kind of anything, from enums to position objects (x,y,z vectors).</p><p>The important part is that neural networks can represent complex transformation functions and decisions up to a limit where bayesian solutions chime in.</p><p>Neural networks are dumb. They can only understand values from 0.0 to 1.0; which means we have to write adapters for it so that it can understand what the data means.</p><p>Those adapters do nothing more than to transform values into an area between 0.0 and 1.0. In more generic implementations, they tend to be called sensors or controls, given the idea of reusing them for other neural network structures.</p><p>For example, when we want to analyze a pixel position of a paddle in a pong game, we would use something like this:</p><pre>let input = [ 0, 0, 0 ]; // x,y,z</pre><pre>input[0] = entity.position.x / screen.width;<br>input[1] = entity.position.y / screen.height;<br>input[2] = 0; // we don&#39;t have a z position, have we?</pre><pre>let answer = neural_network.compute(input);<br>if (answer[0] &gt; 0.5) {<br>    entity.moveUpwards();<br>} else {<br>    entity.moveDownwards();<br>}</pre><p>Now we know that a neural network can compute inputs and give us some outputs that can either be something like an answer to a question (if &gt; 0.5 then yes else no) or a data object that we can translate to our simulation world (output = [0.5, 1.0, 0.99 ] would be position coordinate).</p><p>Neural networks themselves are structured in the previously mentioned layers where each layer contains multiple neurons. A simple feed-forward network is built in a way that each and every neuron is connected to each and every neuron in the previous layer; iterating from the left input layer to right output layer.</p><p><a href="https://chatbotslife.com/introduction-to-deep-learning-on-social-networks-how-to-learn-even-more-about-your-personal-life-cd1da6d67770">INTRODUCTION TO DEEP LEARNING ON SOCIAL NETWORKS: “HOW TO LEARN EVEN MORE ABOUT YOUR PERSONAL LIFE…</a></p><p>Those connection and “how active” they are is represented using so-called weights. A weight typically represents one neuron connection. The important part here is that input neurons have no connection to a previous layer, so the compute() method in our implementation must respect that input neurons just directly get their neuron.value set with the input array’s values.</p><p>When talking about how neurons communicate, how the weights change over time and when to activate the next neuron in our network — that’s a so-called activation function. Activation functions are a bit of a fuzz currently, as everyone has their own opinion on that.</p><p>An example sigmoid activation function can be something like this:</p><pre>const _sigmoid = function(value) {<br>    return (1 / (1 + Math.exp((-1 * value) / 1)));<br>};</pre><p>All in all, you only have to know that activation functions are the idea to simulate how neurons work. The activation function in reality does nothing more than take one value (formally speaking a sum of values) and transforms it to another one; where the behaviour is similar to the ease-out or ease-in-out tweening in the user interface and animation world.</p><p>Overfitting and the discussion is a more complex topic, but I’m bluntly gonna ignore it totally here to save time and confusion.</p><p>What you need to know is that the CNN (convolutional) guys finally are using the first two-agent system where one neural network creates fake data and the other one tries to figure out whether it was faked or not.</p><p>As both increase in strength, they get supergood at classifying real world things. You can see that similar to a real-world example where money bills produced by banks always get more detailed because the money forgers get better. Well, at least in modern countries ;)</p><p>However, as an evolutionary ANN guy, this is boring and really nothing new. The idea of competing AIs in a multi-agent system is old, and it’s important to know that it is a seriously powerful idea to advance behaviours of neural networks.</p><p><a href="https://chatbotslife.com/finding-the-genre-of-a-song-with-deep-learning-da8f59a61194">Finding the genre of a song with Deep Learning — A.I. Odyssey part. 1</a></p><h3>1. Genetic Programming and Evolution</h3><p>Genetic Programming is the idea to use the representation of genomes for data. The huge advantage of genetic programming is, when combined with an evolutionary algorithm, that it can achieve pretty good results very fast.</p><p>A basic evolutionary algorithm always has three different cycles: Train, evaluate, breed, repeat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*x9LA-6SIaBrD1U-oYtH6CQ.png" /><figcaption>The three evolution cycles: Training, Evaluation, Breeding</figcaption></figure><p>That is due to the fact that an evolution always consists of a population pool. That population is initially filled with neural networks with random values so that you can achieve those quick results. Those neural networks are typically called agents as they are competing against each other.</p><p>Of course, calling random to achieve the “perfect value” is a bit dumb and takes mathematically literally forever; so there’s something in place called fitness measurement. This fitness can be a simple progress value for each agent and genome.</p><p>For example, in a super mario game the distance to the left or something like “amount of points” or “amount of killed enemies” can be used as a fitness value.</p><p>The fitter agents get, the more likely they are to be bred with other fit agents. Fitter agents produce always two babies, using the idea of a mum and dad with dominant genes. That means one baby looks more like mum (daughter) and the other one looks more like dad (son) to ensure that the knowledge of both have the chance to get better in future cycles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*80sGJ6IV5Xb7FJh0FbEj8g.png" /><figcaption>Genome crossover / zw agent and zz agent</figcaption></figure><p>The crossover algorithm typically randomizes the part “where” to split the genome. That means it is randomized one time and the daughter gets one part (70% mum / 30% dad) while the son gets the other part (30% mum / 70% dad).</p><pre>let dna_split = (Math.random() * mum_genome.length) | 0;<br>let daughter  = new Genome();<br>let son       = new Genome();</pre><pre>for (let d = 0; d &lt; mum_genome.length; d++) {</pre><pre>    if (d &gt; dna_split) {<br>        son[d]      = mum_genome[d];<br>        daughter[d] = dad_genome[d];<br>    } else {<br>        daughter[d] = mum_genome[d];<br>        son[d]      = dad_genome[d];<br>    }</pre><pre>}</pre><p>The values each genome represents typically stands for the values of neural network weights. We learn what neural network weights are later. For now we only have to know that the “contents” of a neural network are represented in that “giant genome array”.</p><p>Each weight of the neural network has an equivalent “cell” in the genome array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*XKvIjpLkSH8-0Y-zjMRX9w.png" /><figcaption>A genome typically represents the weights of all neurons in the neural network</figcaption></figure><p>However; the problems a typical evolution has is that when compared on the timeline, the results aren’t improving much when the passed time gets longer. That is mostly because the mutation rate is constant and/or too high to get better innovations.</p><p>At first, a high mutation rate is good and what you want. It will give you “fairly good” results in a short amount of time. Later on, a high mutation rate isn’t good and will worsen the amount of innovation it can produce.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Tsntw-Ypp_FjyPb48zO6tg.png" /><figcaption>The <a href="https://cdn.rawgit.com/cookiengineer/talks/master/demo/flappy-plane/index.html">Flappy Plane demo</a></figcaption></figure><p>If you want to try out a very simple Evolutionary AI demo I put together, you can do so by opening <a href="https://cdn.rawgit.com/cookiengineer/talks/master/demo/flappy-plane/index.html">the Flappy Plane demo</a> right now in your (modern) web browser.</p><p>As you might see, there will always eventually be one point in time where evolution doesn’t cut it anymore and the neural networks won’t improve into a more perfect state. Without backpropagation, it’s not possible to get better by pure randomization. Well, actually it is, but it will require exactly an infinite amount of time, so we humans probably gonna die before it happens.</p><p>Those mutations on a fitness timeline chart can be identified pretty quickly, because you will see them as “steps” where suddenly all dominant agents get a bit better:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*s0WLYNDX5f7fcaytrI2xoQ.png" /><figcaption>Evolution vs. Backpropagation Fitness over Time</figcaption></figure><p>More advanced concepts like NEAT and HyperNEAT try to tackle the innovations-by-mutation problem by analyzing the behaviour and the mutations over time.</p><p>For example, each genome’s performance gets evaluated on its own and only the “better” genomes survive, but the worse ones are remembered to improve randomization.</p><p>The basic idea behind all advanced evolutionary concepts is still nothing more than to optimize randomization and avoid “already known to fail” random values.</p><p><a href="https://chatbotslife.com/using-augmentation-to-mimic-human-driving-496b569760a9">An augmentation based deep neural network approach to learn human driving behavior</a></p><h3>2. NEAT</h3><p>NEAT is a beast and is hard to explain properly in an easy way. You might know the concept already if you’ve seen the <a href="https://www.youtube.com/watch?v=qv6UVOQ0F44">Mari/o demo by SethBling</a>. I can recommend to watch this video now, so that you’ve got a better clue on what I’m explaining next.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fqv6UVOQ0F44%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dqv6UVOQ0F44&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fqv6UVOQ0F44%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/21d2427a502b7c7cb669220e2e3478c8/href">https://medium.com/media/21d2427a502b7c7cb669220e2e3478c8/href</a></iframe><p>The basic thing you have to know is that NEAT is an algorithm that observes the performance of neural networks and analyses their behaviours. If the behavioural analysis says it got better, it’s used for breeding. If not, the gene (or genome) gets temporarily deactivated.</p><p>NEAT is also typically not used for classical static neural networks and more for ANNs. I call ANNs “Adaptive Neural Networks” because meanwhile pretty much anything is artificial.</p><p>ANNs are the idea that you start from scratch with zero neurons and you let the algorithm find the perfect structure of a neural network. The connections of neurons are randomly removed and created. As the behaviour changes we can learn where to spawn neurons more efficiently.</p><p>The big difference to a “dropout” concept or a DQN concept is that ANNs will come up with a single perfect solution and not the average “well, it works for me” solution. That’s a big difference in what you can do with them, so when comparing a DQN’s performance with NEAT in games like super mario you will see big differences in how they play the game. A DQN will probably never (read: before we humans die) come up with the same uber-solution as an ANN would.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*W3RX3tB93nc-b0c4ba4f-g.png" /><figcaption>Adaptive Neural Network idea</figcaption></figure><p>The basic idea behind NEAT is to track innovations a gene can produce. A gene represents a single connection between neurons.</p><p>As NEAT was pretty neat, there are many different implementations in the wild. The most popular ones are HyperNEAT and ES/HyperNEAT. Those are “sick stuff” that are hard to understand. I will skip most details for now, but we are probably going to implement them later in this article series ;)</p><p>A general concept that HyperNEAT uses to achieve a better behavioural analysis part is a so-called “Compositional Pattern-Producing Network” or in short CPPN. It’s basically a reinforced neural network that learns the relations of inputs and the measured performance of neural networks. The advantage is that it can memorize the structure of ANNs and relate them to their agent’s fitness. So it can categorize more efficiently and figure itself out “what changes in structure” affected “what changes in performance” in the timeline.</p><p>The behavioural analysis is nothing more than the idea to reduce the amount of unnecessary randomization, so that we can automatically guess in a better way which is the “most probable” value for a better guess in future.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*sXU_7ldMou_aMgDD28KS_Q.png" /><figcaption>Compositional Pattern-Producing Network analyses many neural networks (or agents) and categorizes them in species with similar behaviours.</figcaption></figure><p>In a typical NEAT implementation the population pool consists of so called “agents” because it’s a multi-agent concept where many AIs try to solve the same problem with different “ideas”.</p><p>Those agents always compete against each other and always try to be the “fittest” one so that their DNA, and therefore their gained knowledge represented in neural network weights, survives.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*rHRdTSFf8Zr3VUawma6itw.png" /><figcaption>Multi-Agent system sorts agents by fitness and determines the dominant ones (with better mutations)</figcaption></figure><p>The dominant agents in a multi-agent system are the ones that can breed to populate the next evolution cycle. The population pool for the next cycle typically is split up in three different types of agents:</p><ol><li>20% Survivors (crossover breeding of fittest agents)</li><li>20% Mutants (totally randomized neural networks)</li><li>60% Children (crossover breeding between fittest agents and rest of population)</li></ol><p>Those are basically the percentages of a healthy evolution scenario. They are not NEAT specific nor evolution specific and more of a rule of thumb of my own experience.</p><p>A healthy evolution’s population pool always has at least 32 agents, so that there’s always “enough to choose from” for breeding them in a healthy manner.</p><p>A small population pool is not healthy for breeding, as it will only reinforce already known solutions and not give randomization a chance to come up with a better solution.</p><p><a href="https://chatbotslife.com/machine-learning-for-dummies-part-2-270165fc1700">Machine Learning for Dummies: Part 2</a></p><h3>TL;DR</h3><p>Evolution and Genetic Programming allows rapid progress in finding the right values for Neural Networks. However, performance is dependent on randomization (and its innovations). NEAT and HyperNEAT tackle that with behavioural analysis and fitness measurement of agents in relations to their genomes, genes, and neuron connections.</p><p>I created a <a href="https://github.com/cookiengineer/machine-learning-for-dummies">github repository</a> with all contents of this article series.</p><h3>What’s Next</h3><p>Now that we know the basics of a Multi-Agent system and how we can measure the fitness of Agents, we can dig more into Neural Networks in general.</p><p>In a typical AI implementation, an Agent has a Brain, and we are going to learn how the Brain looks like.</p><p><a href="https://medium.com/@cookiengineer/machine-learning-for-dummies-part-2-270165fc1700">Machine Learning for Dummies: Part 2</a></p><p>Got comments or questions? Reply below.</p><p>Over an out.</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fpowered.by.rabbut.com%2Fp%2FqnHY%3Fc%3D0&amp;src=https%3A%2F%2Fpowered.by.rabbut.com%2Fp%2FqnHY%3Fc%3D0&amp;type=text%2Fhtml&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;schema=rabbut" width="500" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/47a0a8491046a6d8bdbb86880dd8fc1e/href">https://medium.com/media/47a0a8491046a6d8bdbb86880dd8fc1e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*bQlRSzFHJEmF4Q7PyrLgng.gif" /></figure><figure><a href="https://chatbotslife.com/bot-communities-mastermind-group-d2dae9876709#.53x0py6ou"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*6XUspT9JOSq0w0Fi35HIaA.png" /></a></figure><figure><a href="https://m.me/ChatbotsLife"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*c1LDMH5vbnIz9rmAka8Hwg.png" /></a></figure><figure><a href="https://chatbotslife.com/how-to-get-a-free-chatbot-b1fb9dfe109#.z9dtp2sy0"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*D0Jf3dI6ZThtqcfwDYY7mg.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbaca076ec07" width="1" height="1" alt=""><hr><p><a href="https://blog.chatbotslife.com/machine-learning-for-dummies-part-1-dbaca076ec07">Machine Learning for Dummies: Part 1</a> was originally published in <a href="https://blog.chatbotslife.com/">Chatbots Life</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[z is the new j, yo!]]></title>
            <link>https://medium.com/@cookiengineer/z-is-the-new-j-yo-eaf93d173894?source=rss-42d40cbc7945------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaf93d173894</guid>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[vim]]></category>
            <category><![CDATA[bash]]></category>
            <dc:creator><![CDATA[Cookie Engineer]]></dc:creator>
            <pubDate>Fri, 13 Jan 2017 11:50:39 GMT</pubDate>
            <atom:updated>2017-01-19T18:53:40.403Z</atom:updated>
            <content:encoded><![CDATA[<p>Today I was casually browsing /r/vim where one of the redditors made a z plugin for vim. If you never heard of z before — I bet it will improve your life by at least 9000%.</p><p>First: z is a shell script that can be included in your bashrc. Download, edit bashrc, source path/to/z.sh and restart your Terminal to get going.</p><p>Link to the z project: <a href="https://github.com/rupa/z">https://github.com/rupa/z</a></p><h4>What does z do?</h4><p>I frequently work in a couple of projects and I always have to cd into them. I have frequently edited the lychee.js’ lychee library:</p><pre>cd /opt/lycheejs;<br>cd ./libraries/lychee;<br>vim; # or whatever to work here</pre><p>So here’s the deal. cd ing into a folder is nagging and annoying. bash autocomplete is nice, but often you have similar starting names and you basically need to cd into it again, because you didn’t expect it.</p><p>z on the other hand maintains a history of commonly cd ed folders (or PWDs of bash instances) — and more importantly — sorts them by frequency.</p><p>That means commonly cd’ed folders are first and are preferred. It also parses them recursively, so you can fuzzy-jump around when you know there’s only one subfolder in the tree with that specific name.</p><pre># old method<br>cd /opt/lycheejs;<br>cd ./libraries/lychee;<br>vim; # or whatever</pre><pre># new method<br>z lycheejs lychee;<br>vim; # or whatever</pre><p>Pretty awesome, hugh?</p><p>Even more awesome is the guy that put out a z.vim plugin for it, so you can now fuzzy-jump around inside VIM: <a href="https://github.com/lingceng/z.vim">https://github.com/lingceng/z.vim</a></p><p>So, that’s it for today. Nevertheless just a casual post. Over and out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaf93d173894" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why to switch from Ubuntu to Antergos]]></title>
            <link>https://medium.com/@cookiengineer/why-to-switch-from-ubuntu-to-antergos-997e2c2d88df?source=rss-42d40cbc7945------2</link>
            <guid isPermaLink="false">https://medium.com/p/997e2c2d88df</guid>
            <category><![CDATA[arch-linux]]></category>
            <category><![CDATA[debian]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[gnu-linux]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Cookie Engineer]]></dc:creator>
            <pubDate>Sun, 06 Nov 2016 20:10:36 GMT</pubDate>
            <atom:updated>2016-11-06T21:45:49.409Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s me again. This time I want to say that Arch is amazing. No seriously, beside the jokes of /r/linuxcirclejerk I want to describe and explain the advantages that an Arch-based distro has over other distributions.</p><p>As I’m a GNOME lover I kind of represent both the “real world user” and a “developer” here. I hate doing things in Terminal (except my only true love VIM ❤) and I want to automate all the things, so the problems never distract me again from my real work on my computer.</p><p>I’m not a hired sysadmin, so I don’t give a f*** about anything related to DevOps. I do not like DevOps, I think it is wasted time. I want to build things, not infrastructure. Having said that, we might continue now :)</p><h3><strong>The Story of Tales with Ubuntu</strong></h3><p>I was using Ubuntu eversince it came out with its first release. Before that I was using Debian GNU/Linux since I was 11 years old. No seriously, I was using Debian-based systems for nearly 18 years now.</p><p>As many things broke over the years, I went to being an APT shadow and compiling things for others. But mostly for my own reasons, because most of the stuff I require on my machine won’t be compiled by others in the first place. At least that’s what I thought when using Debian all the time.</p><p>One day, my machine broke again because the System Upgrade didn’t work. I was skipping my Ubuntu system upgrade since last October (2015.10) of my UbuntuGNOME distribution because I saw my brother doing it; and it broke completely with the 2016.04 release due to systemd and wayland.</p><p>A real Ubuntu user is only one that needs to update his system from scratch because every config breaks anyways ;-)</p><p>So, big deal was a Bug of the Intel driver that was fixed upstream for around 5 years already. It affected me and my old i915 graphics card, so it was really annoying having a backlight display that always re-activates itself when you’re coding in the dark. That shitty bug made me almost rage and hurt my laptop because it was so annoying and nearly impossible to fix.</p><p><strong>Self-fixing Bugs in Ubuntu or Debian</strong></p><p>When you have a Debian based distribution and you want to fix things yourself (because you know that a Bug has been fixed for 5 years already) there’s the so-called “development header packages” concept where libraries themselves are shipped as binaries and their development files are shipped seperately to save the average user hard drive space. At least that’s the basic idea, there seems to be no reasonable naming concept for those packages, as some packages are delivered by single packages (like mesa ships all mesa-* packages, too) etc.</p><p>The real troublemaker behind a “package-dev” concept is the amount of unnecessary source code that lands on your system. If you want to develop, say, a fix for the graphics driver - chances are high that you have to get the source code of the linux kernel and Xorg as well. And tada, you just wasted at least over 5 Gigabytes of your hard drive with unnecessary downloads of source codes that you never wanted in the first place.</p><p><strong>Broken Dependencies</strong></p><p>Ever wondered why you need to install the email-client evolution and its evolution-data-server for the usage of GNOME? A Debian maintainer decided that it’s good as a default package, so you are forced to install that unnecessary 300MB just for the sake “if you choose to use evolution as an email client”.</p><p>That philosophy is basically what got me into going away. If you want to ship or use a newer GNOME shell yourself (or by using say, the Debian testing version of it for yourself directly) you get into trouble real fast. The dependency chain is unimaginably complex and you need to download a shitload of packages to match the version criteria.</p><p>Again, as we use Debian, we cannot simply use the most-up-to-date packages, we have to use specific versions that existed 5 years ago (and therefore limits in how “up to date” we can actually be on the system). I’m just referring to the OpenSSL mess here. Or say, Wayland and systemd. Pretty much all f***ed up in Debian.</p><h3>Why Antergos and not Arch?</h3><p>The question I get a lot is why I’m not using Arch Linux directly, because most of my stuff is bleeding edge anyways. The only reason I have is: I’m too lazy to deal with parted and other commands. I want a graphical installer. I have no Android tablet opened in parallel to _install my system_. It’s not that i gain anything in knowledge here, I did that back in my Slackware-days already. And I’m not going to do it again. It’s effing 2016, man. Grow up and deal with it.</p><p>As dumb as it sounds and as XFCE users are not reading any further by now, I can explain more awesomeness of upstream Arch without having to deal with people using a shell environment variable (HTTP_PROXY and HTTPS_PROXY) to use a Proxy for each networked application.</p><h3>The power of Arch Linux.</h3><p>From my personal developer-and-UI-lover view, I think Arch Linux is still a big deal. Its strength is definitely the build workflow and the package management system.</p><p>Also, pretty much everything is as up-to-date as humanly possible. I mean, VIM comes out and less than 10 hours later I got the binary package update. It’s not only VIM, it’s almost anything because of AUR.</p><p>Granted, I think the pacman syntax (e.g. pacman -Sy and -Su instead of apt-get update &amp;&amp; apt-get upgrade) sucks, but I’ve written <a href="https://gist.github.com/cookiengineer/94265370d66ea73f4782f80c231e126c">apt-pac</a> for exactly that.</p><p>The concept behind Arch’s package management is that they have the official packages (that are hosted at packages.archlinux.org) and the AUR — the Arch User Repository — where pretty much anything that you can even imagine is already available in. If anyone compiled anything on the planet, it’s probably in AUR already. Seriously, I often wonder how awesome that is ❤</p><p>You can imagine the AUR as a centralized PPA alternative. The only difference is that you have a centralized package “host”, not spread-out different ones from dozens of unsynchronized sources like it’s the case on launchpad. You always get into trouble updating from different PPAs, because they most likely ship different dependencies of libraries — dependent on when and on what system they compiled it.</p><p><strong>Fixing my own graphics driver</strong></p><p>So, as it happened before already, I’m not new to this issue. My mind-boggling moment came when I first wanted to fix a package myself and apply a patch to it to see whether a bug in mesa affected me or not.</p><p>I asked over in <a href="https://www.reddit.com/r/archlinux">/r/archlinux</a> on how to achieve that and where to apply the patches to (and basically let them know I was still an Arch Noob at the time). The friendly people over there were uber awesome, they are a friendly community and they always like to help ❤</p><p>So, the real deal behind Arch is ABS — the so-called Arch Build System. You first need to install ABS (by using pacman -S abs) and then you need to execute it one time (sudo abs) to sync its database. That might take a while, depending on your internet connection.</p><p>What that does is it downloads all the PKGBUILD and patch files of all packages. That means you now can build packages yourself on your machine, using the ABS build workflow.</p><p>If you think that ABS explodes in size: It’s currently 50.5MB for each and every package that is available. Take that, suckers!</p><p><strong>Package Dependencies</strong></p><p>On an Arch-based system, you basically need only a few dependencies to start building libraries. In my case I only needed the base-devel package to get going.</p><p>The idea behind Arch’s packages is that all binary libraries ship with their own development headers — excluding the source code. That, my friends, is a big deal in system size. It saves over 8GB on my machine compared to Ubuntu. More free space for more unsorted stuff in my Downloads folder — awesome! :)</p><p>Having said that, it means that when you install the binary library package glibc, it also contains the development headers so that you can include it in your source code right away — without having to download the glibc-dev package, for example.</p><p><strong>Building your own Driver with a Patch</strong></p><p>If you want to build your own driver, you start with the PKGBUILD template of the official package. The complete build workflow from A-Z for a package looks like this, taking the example of the mesa package that needed to be fixed with an upstream patch:</p><pre>sudo pacman -S abs base-devel;<br>sudo abs;</pre><pre>mkdir -p ~/abs/extra/mesa;<br>cp -R /var/abs/extra/mesa ~/abs/extra/mesa/;</pre><pre>cd ~/abs/extra/mesa;</pre><pre># Apply patch files now, edit PKGBUILD file</pre><pre>makepkg -s;</pre><p>As you see, no further dependencies were required to compile mesa. The cool thing is that the ABS build workflow does not need further package dependencies regularly installed (and probably uninstalled) on your system, so you can simply delete the folder afterwards to give up free space.</p><p>My <a href="https://github.com/cookiengineer/abs">personal ABS repository </a>contains all the fixes that I apply on my system on a regular basis (and I use the releases section for binary packages). Currently, I decided to create a <a href="https://github.com/cookiengineer/gnome-shell">GNOME shell fork</a> and to make some heavy changes to it. And I required exactly zero libraries to be additionally installed for that :)</p><p>The build flow was setup within less than 5 minutes and I was able to release my own GNOME shell fork to the public (read: as a binary package) within less than 3 hours; while 99% of the time was me writing code, not infrastructure build chain.</p><h3>Arch is blazing fast</h3><p>No, seriously. I mean it. You never experienced the power of systemd before it. No matter what you think, I think there’s no way of getting faster as with an Arch-based system. It has proper UEFI “ultra fast boot” mode support, systemd is rocking hard.</p><p>I even plotted an SVG for you, if you don’t believe me (generated with systemd-analyze plot), unmodified, running Arch on a low-end Intel NUC i5 (worth 100$ as it’s 2 generations old by now) with a 1.8Ghz dual core:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*lfD10y2leAFB8e24KaHqng.png" /></figure><p>Now you can try to compete with that on Debian. Good luck, I think it’s impossible. The equivalent Debian system took way more than 50 seconds to bootup on identical hardware. 6.32 seconds is the unoptimized OEM Arch/Antergos setup and the default behaviour; auto-login into GNOME, with chromium, TOR, cjdns and all other things already being started — with all the generic kernel mods loaded. Take that, initrc suckers!</p><h3>TL;DR</h3><p>I found a GPL violation. No, just kidding — I wanted to say that Arch is amazing. If you are a normal user, check out Antergos. Antergos to Arch is basically the Ubuntu to Debian and even more amazing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=997e2c2d88df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Criticism about Angular 2 from an Entity/Component Perspective]]></title>
            <link>https://medium.com/@cookiengineer/criticism-about-angular-2-from-an-entity-component-perspective-43ce364e4fa4?source=rss-42d40cbc7945------2</link>
            <guid isPermaLink="false">https://medium.com/p/43ce364e4fa4</guid>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular2]]></category>
            <dc:creator><![CDATA[Cookie Engineer]]></dc:creator>
            <pubDate>Fri, 22 Jul 2016 14:07:12 GMT</pubDate>
            <atom:updated>2016-07-24T19:47:31.209Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>As some of you might know, I was kind of a Game Engine Architect and did some low-level cross-platform 2D / 3D stuff in the past. Coming from the hardcore C/C++ corner of the internet I meanwhile switched to ECMAscript6 and I really prefer it, even over Haskell, CommonLISP and Python. I’m also totally lazy, so I like to at least automate my life as far as possible.</p><p>I decided to write about Angular2. My new job kind of requires that I develop with Angular2, they ain’t doing anything related to my previous research in the AI or engine sector and they do pretty much only the 0815 HTML5 stuff; so I kind of am new to this whole Angular2 Typescript SystemJS story. I didn’t give Angular1 much attention — after 2 projects I did with it I shortly realized that it’s a conceptual disaster.</p><p>A friend of mine, also familiar with typical game engine concepts and cross-platform (not cross-browser, that’s a difference …) development, asked me to write down some stuff about my experience with it.</p><p>It’s hard to describe and I have very mixed feelings about Angular, but I try to be as objective as possible here. Please be kind, I really try to. I’m also trying to cover the UX perspective (from a Beginner’s view) here, because that chimes in the most. Impossible debugging is a killer for me to use any framework.</p><h3>Angular 2 Tutorials</h3><p>The amount of working tutorials of Angular 2 are very rare. If you think that Angular Class is up-to-date, you’re wrong. Everything related to Angular 2 is only up-to-date on the angular.io Website. Even if the tutorial you find is 9 days old, it’s probably out of date. Very very many things currently get renamed and restructured in the Angular 2 codebase, and it’s very important to use “@angular/submodule” as a package name. If you don’t do that, everything will burn up faster than you can fix it.</p><p>From a Beginner’s perspective, this is not so good. You don’t have a working Boilerplate, you only have the thousand-pages long Tutorial and no place to start. As Angular 2 still has no code or project conventions that are enforced, pretty much anything you find on github will break when you start the idea to copy/paste/modify it in your project.</p><p>Recommendation here is: Use a github repository for the Angular Developer Guide. Use subfolders for different Tutorial steps, so people can download a simple ZIP file and unpack it, do `npm install` and everything works right out of the box. If you have to start from the beginning to figure out how Dependency Injection works, it’s a total nightmare. Nobody has time to do some 3 hours tutorial to figure out an implementation detail. With the ZIP files you have no pain, much gain, everything is fine and everybody can use it.</p><h3>Error Messages and Debugging</h3><p>The error messages in Angular 2 are so generic that you have no effing clue what’s going on. Always there will be a message “cannot find property blub” and it can literally be related to anything in the code, from components to HTML to even re-using components and/or services and directives.</p><p>The typical problems you will have on the first days are things like:</p><ul><li>Cannot bind to routerLink since it isn’t a known property [<a href="http://stackoverflow.com/questions/34642478/cant-bind-to-routerlink-since-it-isnt-a-known-native-property-using-angular2">StackOverflow</a>] [<a href="http://stackoverflow.com/questions/34317044/angular2-exception-cant-bind-to-routerlink-since-it-isnt-a-known-native-pro">StackOverflow2</a>]</li><li>You need to <a href="http://stackoverflow.com/questions/31415052/angular-2-0-router-not-working-on-reloading-the-browser">activate HashLocationStrategy</a> (second answer, not the accepted one) to prevent the 404 Browser reload error on any subroute. The defaulted server (that is recommended in the angular.io Tutorial) does not ship a config that works.</li><li>RouteParams is deprecated (no matter what the Tutorial says) and you need to use <a href="http://stackoverflow.com/questions/36496752/angular-2-error-cannot-resolve-all-parameters-for-routeparams">ROUTER_PROVIDERS</a>. If you are wondering how you can access the current active route, you need to use [<a href="http://stackoverflow.com/questions/34323480/in-angular-2-how-do-you-determine-the-active-route">routerLinkActive</a>] and <a href="http://blog.thoughtram.io/angular/2016/06/14/routing-in-angular-2-revisited.html">ActivatedRoute</a> but only for Master/Detail views. If you want to have, say a list of items and a detail view, then this approach won’t work and you need an iteration + model dependency injection (covered later).</li><li>Dependency Injection uses the `@Decorator()` syntax. Every time you do something like `@Component` or `@Input`, you are injecting dependencies. Took me a long while to realize that, because the angular.io Tutorial on Dependency Injection does not tell you that.</li><li><a href="http://stackoverflow.com/questions/30580083/angular2-no-provider-for-nameservice">Services</a> are injected with Dependency Injection.</li><li>Make sure all &lt;router-outlet&gt; tag notation is everywhere in pretty much all component templates, otherwise it’s basically impossible to reuse components. See this <a href="http://stackoverflow.com/questions/38225358/angular2-router-cannot-find-primary-outlet-to-load-homecomponent">question on SO</a> that made me realize that.</li></ul><h3>Components (well, not so much)</h3><p>Angular2 Components are not well designed from an Architecture viewpoint. They always have paths relative to the executed environment, which means a source / build / dist workflow will completely fail when you have relative paths (except you just copy/paste everything in a giant gulpfile again).</p><p>For example, any Component has to have a templateUrl and styleUrls that are relative to the main.ts entry point. That means, if you have a folder structure like “./client/src/app/components/dashboard/dashboard.ts” you will have to use “app/components/dashboard/dashboard.html” as a path. You cannot simply use “./dashboard.html”, because that would’ve been to easy and would just make more sense because it’s a `@Component` decorator anyways.</p><p>All Components basically need the ROUTER_DIRECTIVES in them, otherwise you will have a very very bad time debugging it. If you want to interact with your application (like navigating to other links or having a back button, which every component somehow has), you need the ROUTER_DIRECTIVES. Why this is not defaulted is a riddle because no one tells you that. Also, this means that Components are not decouple-able because they are always having a dependency to the router setup (and therefore the router directives with static maps like “/dashboard/blub”). Therefore it’s totally senseless to have a special [routerLink] property when it’s not mapped and therefore not fullfilling any purpose compared to a simple &lt;a href=”/static/path”&gt; which fullfills the exact same featureset without the missing property errors and the ROUTER_DIRECTIVES that need to be injected. Just sayin’.</p><p>From my personal perspective, these are all reasons why the Angular Components are no Components. Components are plug and play, having the idea to spread no glue code. In Angular 2 this is not the case, therefore they are not Components and neither are they Entities.</p><p>Every Component’s styleUrl (CSS file) needs global styles when being used as a SubComponent. That means those styles can only be written inside the Master and not the SubComponent itself.</p><p>For example, you have a DashboardComponent rendering multiple EventComponents. If you think you could simply write the EventComponent’s CSS inside the EventComponent’s CSS file; then you guessed wrong. The final view encapsulation (no matter what you set) will generate an `nghost` for the Dashboard element and an `ngcontent` for the Event element in the DOM. That means the Event element is unstyle-able in a Master/Children setup.</p><h3>Build System</h3><p>The build system currently introduces SystemJS. Personally I think the idea behind SystemJS is great, but the implementation and API isn’t.</p><ul><li>TypeScript files need to be built by tsc, the typescript compiler. In order to do so, you need to use a tsconfig.json. You need to make sure that the tsconfig has the entry “module = system” and “moduleResolution = node”. Otherwise you will have a hard time debugging it, because it’s close to impossible to follow what kind of errors will occur.</li><li>Typings is still buggy and ignores subfolders, so if you want to ignore typings/foo and typings/bar, it will unignore all entries (even node_modules as a separate entry in the config). So basically, just use top level entries, otherwise it will also fuck up everything.</li><li>SystemJS-Builder is the recommended tool to bundle everything. Turns out, bundling is more complex than you think. Angular has a specific dependency order on other libraries. The exact order is “core-js/shim.js”, “zone.js”, “Reflect.js” and “system.js”. After these polyfills you can load “Rx.js” and “angular” and concat everything together. Make sure polyfills are separate, otherwise everything will be burning in a big inferno. Also, the systemjs builder has no features to simple export the systemjs config file. That means for each build you need to manually create your own systemjs config file, depending on _WHERE_ you use them and you need to change the module resolution based on the environment (runtime). Yes, that is completely preventing the whole purpose of why systemjs exists in the first place. Also, minifying ain’t easy, you need to have dummy packages in the systemjs config for each package you were bundling into the file. For example “@angular/core” needs to have “{main:’index’}” just for the sake that the loader knows what was already loaded before you gave it the config. Yes, this is a concept fail on many levels.</li><li>As I said before, Components have relative paths to their CSS files. That means all CSS stuff (assuming you use :host and other web component selectors) still has to be shipped in an uncompressed manner or have to be inlined inside the JS files (again, this is not good because of decoupling reasons). I haven’t found a way to automatically inline the CSS/HTML without crashing up the whole codebase, but I’ve heard it is “easy” to do.</li></ul><p>Maybe gulp-inject helps, but as you can figure out already, this stuff is heavily unautomated and results in a gulp file bigger than 900 LOC for a single build. So I think the whole SystemJS/TypeScript/whatever thingie here is a design fail. Lacking conventions, lacking automation and lacking sense of duplicated information on all levels. systemjs builder could automate pretty much everything because it knows everything already when you create it inside the nodejs context. It just needs to export and inject it. I don’t want to write build files half time of my life, goddammit.</p><h3>Models and Services</h3><p>I have to say that Angular 2’s approach of injecting Models and Services is very nice compared to anything else. The decorators ease up every injection and you can simply list it in a constructor as a parameter and it’s automatically injected. Of course, you need to use the import syntax in the code and you need relative paths (which makes decoupling them from components impossible).</p><p>But yeah, it somehow is still nice I think. I guess I like decorators much, not the things that are built with them.</p><h3>Dependency Injection</h3><p>I think <a href="https://angular.io/docs/ts/latest/guide/dependency-injection.html">Dependency Injection in Angular</a> works completely with Decorators. I kind of am unsure, but this is what it looks like as every Dependency that is related to the Angular framework gets injected with `@Component`, `@Injectable` and `@Input` (for example). If you don’t use their decorators, you have a hard time injecting everything even more manually.</p><p>I like Decorators so far, but not how Angular uses them. They could simply provide an API based on conventions (with their default behaviour) and provide an optional settings API to override those defaults.</p><p>For example, having to inject the ROUTER_DIRECTIVES, having to set the templateUrl, having to set the styleUrls, having to set the selector, having to set the Service, having to set the Model, having to set it to an Injectable are ALL completely automate-able. Granted, the only exception is `@Input` here, but I’m okay with that because it offers a nice API to rewrite the input parameter (`@Input(‘foo’) public bar makes it possible to use new Qux({ foo: contentofbar })).</p><p>And by automateable I mean that the information required to do the task is already there without it. Everything could be automated by conventions. And that’s why I hate it. I hate it so much because the Angular approach removes the idea of Composites from Decorators. What the heck, it removes the behaviour-driven design pattern, because everything is abstracted both in time and location.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43ce364e4fa4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The all-around Macbook wakes up from Sleep Mode (or Wi-Fi) Bug]]></title>
            <link>https://medium.com/@cookiengineer/the-all-around-macbook-wakes-up-from-wi-fi-bug-beedf6eb8702?source=rss-42d40cbc7945------2</link>
            <guid isPermaLink="false">https://medium.com/p/beedf6eb8702</guid>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[macbook-pro]]></category>
            <category><![CDATA[el-capitan]]></category>
            <category><![CDATA[os-x]]></category>
            <dc:creator><![CDATA[Cookie Engineer]]></dc:creator>
            <pubDate>Sun, 17 Jul 2016 21:41:03 GMT</pubDate>
            <atom:updated>2016-07-17T21:52:12.416Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>Today I woke up from my Macbook because it woke up from sleep. I literally woke up from sleep and was totally confused what caused it. Turns out this problem is really hard to debug and googling for it will give you a shitload of users asking for generic questions, always posting answers that have literally zero correlation with the problem.</p><p>So, what’s the problem? The problem is not a simple one, it’s caused by multiple annoying settings that the Macbook (in particular OSX El Capitan) ships with.</p><h3>1. Disable Wake Up on LAN</h3><p>Open the System Preferences, go to “Energy Saver” and make sure that you disable “Wake for Wi-Fi network access” and “Enable Power Nap” (in both Battery Mode and Power Adapter Mode). Take the screenshot on how it should look like after you did that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cYdrhzV93dY-pUAfLHOffA.png" /><figcaption>System Preferences &gt; Energy Saver</figcaption></figure><h3>2. Add a Wi-Fi Location</h3><p>Yes, I’m serious here. Another bug related to this problem will cause the Macbook to wake up when you don’t have a named Location. In defaulted Automatic mode it will wake up resulting to random connections to other Wi-Fis. This took me like 2 hours to debug.</p><p>Open the System Preferences, go to “Network”, select “Edit Locations” from the Select Menu on the Top. Create a new Location (that is not named “Automatic”), select it and click Done. It will look like this if you did everything correctly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*5cY1cz2SYhYcu3dQ1v58HA.png" /><figcaption>System Preferences &gt; Network &gt; Edit Locations Overlay</figcaption></figure><h3>3. Change the MTU of your Wi-Fi</h3><p>Yes, I’m serious again. Another bug will cause the Hardware to wake up and ignore all settings if your MTU is not set right. From the security perspective I can’t express how wrong it feels to even write something like this down here. You can find things about this bug of users posting something like “Macbook 2015 slow Wi-Fi” and randomly find some guys having Sleep Mode problems. Turns out my Macbook Pro is also affected.</p><p>Open the System Preferences, go to “Network”, click the “Advanced” button on the Bottom Right, select the “Hardware” tab on the Right. Now select “Configure” and set it to “Manually”. Select “MTU” and set it to “Custom”.</p><p>In the newly appearing input field, enter the value “1453”. I repeat, the value is “1453”, NOT 1500 as the standard value. Click OK and Apply to save the changes. It should look like this if you did everything correctly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Swfqtgd4IOdzOjr3Tlkq4w.png" /></figure><h3>4. Figure out what caused Wake Reasons</h3><p>This took me quite long as well, in the “Console” (Spotlight &gt; Console) you can filter for the term “Wake Reason” and it will show you a bunch of results.</p><p>In my case there were a lot of Wake Reasons related to ARPT (which means AirPort and is related to Wi-Fi and yes, it should not be there, because we deactivated it already. But it will still appear, thanks Apple). But that’s not the trouble-causing one, if there’s something like “Wake Reason: ?” you might have an App open that prevents the Macbook from really going to “real sleep mode”.</p><p>The Macbook will look like it sleeps, it will lock the screen when opening the Lid again — but it won’t be sleeping fo’ real and activate your external hard drive every 15 minutes in sleep mode. There are couple hundred posts about this on the interwebz, but most guys had no clue what caused it. But I think I’ve figured it out.</p><h3>5. Figure Out what prevented Sleep Mode</h3><p>Open the “Activity Monitor” (Spotlight &gt; Activity Monitor). This System App will help you to find the opened App that prevents Sleep Mode. In my case I figured out that <a href="https://trac.videolan.org/vlc/ticket/16488">VLC has a Sleep Mode Prevention Bug</a> which literally is completely ignored by the developers.</p><p>Anyways, in the Activity Monitor you need to go to the “Energy” Tab in the Center Top. In this view there’s a bunch of Apps opened, but the important part is on the Right. There’s a column named “Preventing Sleep Mode”. If there’s a Yes, that’s bad.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gMz2IfV39uO4tYQjzliBSQ.png" /><figcaption>VLC preventing Sleep Mode and causing it to Wake Up</figcaption></figure><p>And if you look closely in the screenshot, the trouble-causer is VLC in my case. Thankfully my Macbook can now rest in peace again without waking me up.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=beedf6eb8702" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>