<?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 Simon Frost on Medium]]></title>
        <description><![CDATA[Stories by Simon Frost on Medium]]></description>
        <link>https://medium.com/@simonhfrost?source=rss-b4f8ef85d4e1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*9i3p15Mwj_my5M3a.jpeg</url>
            <title>Stories by Simon Frost on Medium</title>
            <link>https://medium.com/@simonhfrost?source=rss-b4f8ef85d4e1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 18:27:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@simonhfrost/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[Getting started in React with Redux]]></title>
            <link>https://medium.com/@simonhfrost/getting-started-in-react-with-redux-8b2b42b66dee?source=rss-b4f8ef85d4e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b2b42b66dee</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Simon Frost]]></dc:creator>
            <pubDate>Fri, 02 Jun 2017 17:33:16 GMT</pubDate>
            <atom:updated>2017-06-02T17:33:16.220Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BpaqVMW2RjQAg9cFHcX1pw.png" /></figure><p>React is lightweight compared to similar front-end technologies (it’s just the V in your typical MVC), so it requires a lot of supporting libraries. One of the most commonly used is the state management system Redux.</p><p>Redux is deceptively small, even on the github repository it says: “It is tiny (2kB, including dependencies)”. It has a simple premise, but there’s plenty to learn in order to use it properly, especially in large applications. Here are some of the key points I learned, using it for the first time.</p><h4><strong>Redux won’t take care of your model structure for you</strong></h4><p>Redux deals with model state, but it doesn’t provide commonly needed functionality like: preparing and parsing data from the backend, data validation, and change detection. You’ll either need to bring in supporting libraries, or if your project is small enough you can take care of it on a case by case basis.</p><h4><strong>Not all of your state should be in Redux</strong></h4><p>Redux <a href="https://twitter.com/dan_abramov/status/727278011591045122">emphasises there being a single source of truth</a> for your data. This is hard when you’re dealing with the DOM which already has a representation of it. Sometimes leaving this data in the DOM is sufficient (think of a toggle switch with enabled/disabled states) as bringing that property into Redux may unnecessarily complicate things.</p><h4><strong>You can try to group related properties</strong></h4><p>When your state grows it means you’ll likely want to group properties in order to identify them faster. If you’ve decided you want to store UI state (related to the point above), I’ve found <a href="http://stackoverflow.com/questions/33556252/how-to-separate-ui-and-application-state-in-redux/33558557#33558557">grouping properties under ‘ui’ and ‘data’</a> to be nice starting point.</p><h4><strong>You should use container components</strong></h4><p>Container components serve as the connection between your React components and Redux. They abstract the state management of Redux so your components don’t have to know <strong>how</strong><em> </em>redux is managing your state. If your app is at least moderately sized, I would consider saving yourself the headache and <a href="http://redux.js.org/docs/basics/UsageWithReact.html#presentational-and-container-components">using container components</a> from the start.</p><h4><strong>Structuring your reducers well is important</strong></h4><p>When starting out it’s fine to write all of your reducer logic in one file. But in the future you’ll probably want to separate distinct areas of your application into different files using the function ‘combineReducers’ supplied by redux.</p><p>There are many ways of structuring your Redux files, a common paradigm is called <a href="https://github.com/erikras/ducks-modular-redux">Ducks</a>. Ducks is a good starting point, but finding a good solution to your project size and needs is a complex problem, and can greatly affect your productivity. I’d recommend reading up on some of the <a href="http://redux.js.org/docs/recipes/StructuringReducers.html">advice in the official documentation</a>.</p><h4><strong>Selectors can help with structuring your reducers</strong></h4><p>Selectors work by specifying the local area of the state you want to work on. This helps by abstracting away unneeded parts of the state, and gives you more flexibility. You need to bring in a library to make use of selectors, the most popular is called <a href="https://github.com/reactjs/reselect">Reselect</a>. <a href="https://github.com/voronianski/flux-comparison/blob/e85d18c7a2c1d059537b32e7e43405d923c00d0f/redux/js/components/ProductsContainer.jsx#L27">Here’s a selector being used in action</a></p><h4><strong>You should use Redux DevTools for debugging</strong></h4><p>Because the state managed by redux isn’t directly tied to the UI where it’s visible, it’s great to have a tool that lets you inspect both the entire structure as well as diffs between actions. Installation instructions for different browsers are found <a href="https://github.com/zalmoxisus/redux-devtools-extension">here</a>.</p><h4><strong>You might want to use Immutable.js</strong></h4><p>It’s important in Redux for previous states to be immutable <a href="https://stackoverflow.com/a/44051657/660076">due to a number of factors</a>. Using a library like <a href="https://github.com/facebook/immutable-js">Immutable.js</a> to ensure previous states aren’t modified is great, but I find the API cumbersome to work with. Although I haven’t used it yet, <a href="https://github.com/rtfeldman/seamless-immutable">seamless-immutable</a> seems to solve this problem so that you can use immutable data structures, while still preserving the old syntax.</p><h3><strong>Conclusion</strong></h3><p>Redux surprised me with how many supporting libraries and contextual knowledge was required to use it efficiently. Especially as it’s so small itself.</p><p>I find with redux there’s not often a single way to do things, which is reflected in my tentative answers above. Hopefully these points give you a solid foundation for starting your next project in React with Redux.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b2b42b66dee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Agile Development Doesn’t Work For Music Production]]></title>
            <link>https://medium.com/@simonhfrost/agile-development-doesnt-work-for-music-production-633437deb185?source=rss-b4f8ef85d4e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/633437deb185</guid>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[music]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Simon Frost]]></dc:creator>
            <pubDate>Tue, 03 May 2016 21:23:07 GMT</pubDate>
            <atom:updated>2016-05-03T21:23:07.158Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Project</h3><p>Recently my friend asked if I would be interesting making music for his final year project for his Animation course.</p><p>I’m a big believer in building motivation by setting deadlines, especially if you involve a third party. Involving someone else makes the project more than just an internal struggle (which can be constantly postponed). More is on the line such as your reputation and even your relationship with others.</p><p>My friend also mentioned it would be showcased at film festivals around the world, which was great as I’ve been trying to get more involved with music production — as well any boosting my public profile</p><h3>My Approach</h3><p>When I jumped into the project I had a clear set of paradigms taken from my experience working as a programmer within Agile Development teams.</p><p>A lot of the knowledge I’ve obtained programming I consider fairly universal — much like how I think programming can be extremely similar to making music (maybe I’ll write a blog post about this in the future).</p><p>These are the three main categories:</p><h4>1. Staying Healthy</h4><p>Ambitious projects are well known to cause health issues for people that try to exert more than their body can endure. Not only obvious physical issues (wrist pain, eyestrain), but also mental issues from lack of sleep or poor diet. This is an even bigger struggle when you have to juggle a full time job on the side.</p><p>Agile Development doesn’t exactly say anything about health, but it has certain measures such as time boxing and estimations, that shields individuals from unrealistic expectations, which can then consequently cause strain on personal health.</p><p>Here is what I focused on with staying healthy:</p><ul><li>Being conscious of how many hours of sleep I sacrificed, and for what purpose (it’s easy to fall into the trap of thinking you’ll catch up on sleep in the future).</li><li>Trying to maintain healthy eating habits by ensuring there’s plenty of healthy food at home that doesn’t take too long to prepare.</li><li>Minimising alcohol consumption. Alcohol can be great for strenuous projects as it can (temporarily) reduce stress. But it the long run I find it decreases energy levels and enthusiasm.</li></ul><p>For staying healthy I feel I did well. The biggest challenge was paying attention to the amount of sleep sacrificed and making sure I made it up in the future.</p><h4>2. Communication</h4><p>Good communication is essential in any project. Agile Development tries to provide guidelines and facilitate communication by creating meetings such as stand-ups and other reoccurring meetings that have an explicit and clear purpose.</p><p>I’m a firm believer that the majority of issues in large projects have bad communication at least partly to blame somewhere in the process. From figuring out vision and requirements, to communicating issues while the project is in progress. Communication is prevalent at almost every step and any unaddressed issues are hard to overcome.</p><p>In this project there was the unique problem that my friend was living in New Zealand while I was in Berlin, which caused a ten hour time difference.</p><p>Here is what I focused on for communication:</p><ul><li>Preferring vocal communication over text messages as it’s generally more efficient and less likely that key points will be missed.</li><li>Communicating often, and not only about the project. Talking about non-project related topics can give context and subtly communicate mood. It’s good to keep in sync, much like how a stand-up does for Agile teams.</li></ul><p>For communication I feel like I could have definitely improved. There was an initial conversation over Skype about requirements, but after that the remaining conversation was done over email which introduced a lot of latency and ambiguity. For future projects I would like to place more emphasis on regular conversations with explicit purposes.</p><h4>3. Providing Consistent Feedback</h4><p>Arguably one of the best features of Agile Development is the idea that a product is always usable. If priorities shift or resources change, you can still technically publish the product, although likely at a lower quality than desired.</p><p>This aspect is great for big projects, as it’s often unsure what the end product will be — or even if there will be enough resources for it. It’s also good for constantly adjusting goals based on feedback, to make sure the end result is similar to what was imagined at the start.</p><p>Here is what I focused on for consistent feedback:</p><ul><li>Sending mixes back for feedback often in order to stay on track and communicate progress.</li><li>Trying to reach a stable state as early as possible, in order to account for any problems later in the project.</li><li>Focusing on horizontal slices instead of physical slices ie. everything finished but with average quality, versus the first seconds done perfectly, but the rest unfinished. This makes it continuously ready to release.</li></ul><p>For providing consistent feedback I feel it was one of the biggest points I failed on. It made me realise that artistic projects don’t necessarily make sense when you consistently evaluate the status. It’s not until you add ‘that sick bass’ that the rest of the mix makes sense, or that ‘bit of red’ that the painting becomes complete.</p><h3>Conclusion</h3><p>I’ve read a lot of criticism about Agile Development recently — and rightly so. Choosing a workflow is one of the core decisions that will influence the way you work and plan throughout a project, so it makes sense to analyse it as much as possible.</p><p>Agile Development isn’t the best for every situation, and using it outside of programming, for something more creative definitely highlighted some points where it’s not so useful.</p><p>There are also other situations where it isn’t the best tool. Smaller projects, and also bigger ones with clearly defined goals won’t leverage advantages that Agile Development really shines in like adaptability and transparency.</p><p>Agile Development doesn’t work for music production, and likely isn’t the best solution for many other creative projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=633437deb185" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Animation Options]]></title>
            <link>https://medium.com/@simonhfrost/practical-web-animations-9867973d1b92?source=rss-b4f8ef85d4e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/9867973d1b92</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Simon Frost]]></dc:creator>
            <pubDate>Mon, 11 Apr 2016 20:50:56 GMT</pubDate>
            <atom:updated>2016-04-11T20:56:40.501Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been using web animations a lot recently, but haven’t managed to standardise how I use them in large projects. I feel it’s important to standardise the approaches and frameworks you use in a project in order to keep it maintainable and ease of comprehension high.</p><p>This is especially true with large projects maintained by multiple people where there may be many variants all achieving a similar outcome. Context switching can easily slow you down when you’re trying to focus on other aspects of your project like state management or business logic.</p><p>I’m a strong believer in ‘Separation of Concerns’ and feel like animations relate more to design than functionality, so I decided to evaluate moving all animation related Javascript to CSS in a project I’ve been working on. Here are some of the main ways of animating in web and some of the lessons I learned.</p><h4>Javascript Animations</h4><p>Here’s an example of how to use animations in Javascript with a popular animation library called <a href="http://ricostacruz.com/jquery.transit/">Transit</a>:</p><pre>// Show<br>$element.transition({ opacity: 1.0, 500ms });</pre><pre>// Hide<br>$element.transition({ opacity: 0, 500ms });</pre><h4>CSS3 Transitions</h4><p>And here’s how you can perform the equivalent animation with CSS3 transitions:</p><pre>.my-element {<br>  transition: opacity 500ms;<br>  opacity: 0;<br>}</pre><pre>.my-element.show {<br>  opacity: 1.0;<br>}</pre><pre>// Trigger the animation by adding the class with Javascript<br>$(&#39;.my-element&#39;).addClass(&#39;show&#39;);</pre><p>CSS3 Transitions are great because they embody the concept of progressive enhancement (they gracefully degrade if the transition is not recognised, ie. browser compatibility), but there are other setbacks. The biggest one being ‘how do I get an element to transition immediately after some other transition?’</p><p>Sequencing and instantiation is a major problem when using CSS3 transitions. There are hacky workarounds, but ultimately it’s hard to make an element transition when it’s instantiated (what does it transition from?), and also when chaining multiple animations.</p><h4>CSS3 Animations</h4><p>One solution is to use the alternative ‘animation’ property, which supports sequencing animations via keyframes:</p><pre>.my-element {<br>  opacity: 0.0;<br>  animation: fadeIn 500ms linear forwards;<br>}</pre><pre>@keyframes fadein {<br>  to {<br>    opacity: 1.0;<br>  }<br>}</pre><p>The important part here is the ‘forwards’ keyword which makes the element maintain the final state of the animation after it has finished.</p><p>The CSS3 animation property is great because the keyframing starts as soon as the element exists, solving the issue with animating on instantiation. It also solves the issue of sequencing animation, as keyframing supports multiple properties over time (not shown in the example above).</p><p>One setback is that they don’t support progressive enhancement — if the animation for some reason does not run correctly, then the element won’t end up in the expected state (I had this problem with flexbox width animations).</p><h4>Looking back at JavaScript animations</h4><p>I was at a conference last year where a speaker said ‘HTML is good for unary states (data), CSS is good for binary states (toggling), and JavaScript is good for multi states (interaction).’</p><p>Investigating CSS animations in depth definitely reinforced this for me, as it seems ideal for two simple states, but anything else is generally too complex.</p><p>Javascript animations are also arguably more expressive and easier to use, for example it’s common to have convenient access to common sequencing of animations like ‘shaking’ of an element. They are also improved constantly by the countless libraries and communities that make them more accessible and performant.</p><h4>Conclusion</h4><p>For now I’ve decided to use javascript animations with ‘Transit’, but I’m glad I spent some time investigating different options and becoming more confident in my decision.</p><p>I hope one day I can put animations in CSS where believe they belong. But at this point in time, I’ll reserve that for webpages with simple functionality such as static pages with little to transition.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9867973d1b92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pixi.js Sprite Animation]]></title>
            <link>https://medium.com/@simonhfrost/pixi-js-sprite-animation-1546867f64ae?source=rss-b4f8ef85d4e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1546867f64ae</guid>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Simon Frost]]></dc:creator>
            <pubDate>Sat, 31 Oct 2015 23:05:15 GMT</pubDate>
            <atom:updated>2019-03-18T02:55:24.363Z</atom:updated>
            <content:encoded><![CDATA[<p>When I work on projects I get distracted with writing boilerplate and simply getting things to work, that I often run out of energy or time when it comes to doing the interesting parts. That’s why for my next project I want to focus on smallest subsection possible, and polish it well.</p><p>The focus was on sprite animation, and elegantly swapping between animations when interacting with the environment. A co-worker recommended Pixi.js which looked great for doing sprite sheet based animations. This blog documents my progress implementing the final result which you can see here: <a href="http://www.simonhfrost.com/runner">http://www.simonhfrost.com/runner</a>.</p><p>After browsing the Pixi.js documentation I dove into a basic sprite sheet example found at <a href="http://pixijs.github.io/examples/index.html?s=basics&amp;f=spritesheet.js&amp;title=SpriteSheet%20Animation">http://pixijs.github.io/examples/index.html?s=basics&amp;f=spritesheet.js&amp;title=SpriteSheet%20Animation</a>. I wanted to use my own sprites so found this great one from the game Braid:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*v-9KSDYtRcYIoCHv.png" /></figure><p>When working with sprite sheets you also need an accompanying configuration file that maps the individual sprites. I found a sprite mapping tool at <a href="http://www.leshylabs.com/apps/sstool/">http://www.leshylabs.com/apps/sstool/</a>, which had kick ass automatic parsing (but just needed a bit of tweaking).</p><p>The .json output was a bit different to what was required in Pixi.js. I wanted to investigate the .json in the Pixi.js example, but it wasn’t easily available. After a bit of investigation I found it on Github at: <a href="https://github.com/pixijs/examples/blob/gh-pages/examples/assets/spritesheet/fighter.json">https://github.com/pixijs/examples/blob/gh-pages/examples/assets/spritesheet/fighter.json</a>. The format was actually very similar, the main differences being that the co-ordinates were in different sections, and it also referenced the sprite sheet image within a meta element.</p><p>When re-mapping json, to minimize ones sanity I highly recommend using this JSON formatter: <a href="https://jsonformatter.curiousconcept.com/">https://jsonformatter.curiousconcept.com/</a></p><p>Working on this simple example was a great short introduction to Pixi.js but I was starting to feel that it doesn’t give you much control over the animations and user interaction. I found this blog post: <a href="http://www.html5gamedevs.com/topic/2393-creating-an-object-with-multiple-animations-in-pixijs/">http://www.html5gamedevs.com/topic/2393-creating-an-object-with-multiple-animations-in-pixijs/</a> which said:</p><blockquote><em>Pixi can certainly be used to create games, but it’s focus is more on being a kick-ass rendering engine — which it is. Having said that, you will find a lot of the “niceties” of some gaming engines just aren’t available in Pixi.js — that’s just not its job.</em></blockquote><p>I decided to cut this project short, and re-evaluate if Pixi.js is a good tool for creating a sufficient prototype. Another option would be to use <a href="http://phaser.io/">http://phaser.io/</a> which is more of a game engine and supports user interaction better. But for now I’ll leave <a href="http://simonhfrost.com/runner/">http://simonhfrost.com/runner/</a> to live out it’s legacy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1546867f64ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[One Week of Joylent]]></title>
            <link>https://medium.com/@simonhfrost/one-week-of-joylent-24a91da1d794?source=rss-b4f8ef85d4e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/24a91da1d794</guid>
            <category><![CDATA[food]]></category>
            <category><![CDATA[health]]></category>
            <dc:creator><![CDATA[Simon Frost]]></dc:creator>
            <pubDate>Sat, 31 Oct 2015 23:04:06 GMT</pubDate>
            <atom:updated>2015-10-31T23:04:06.705Z</atom:updated>
            <content:encoded><![CDATA[<p>For the last week I’ve been drinking only Joylent for my food, you can find more information about Joylent at <a href="http://www.joylent.eu/">http://www.joylent.eu/</a>. Drinking three shakes a day is aimed at being a complete food substitute, complete with nutrients and vitamins.</p><p>I started by buying 10 packages online, which together with a shaker were delivered by the Amsterdam based company to me in Berlin in around one week. Each package has enough sustenance for one day, so usually I split the bag into three equal portions which I would then add water to and drink from my shaker.</p><p>I had four main motives for trying Joylent:</p><ul><li>Convenience: Less taking out trash, less cleaning of dishes</li><li>Non-disruptive: Since you can drink while working, you don’t need to schedule time to eat</li><li>Cheaper: At €1.83 a meal, it’s substantially cheaper than what I was currently spending</li><li>Healthier: The shakes contain your daily recommended nutrients and nothing more, which helps reduce overeating</li></ul><p>Joylent is advertised as being a ‘tasty’ shake, but I timidly disagree. While it’s not revolting, I would instead say that it’s ‘not a bad tasting shake’. The best description of I can think of is ‘drinkable bread, with subtle flavouring’.</p><p>I learned pretty quickly in the week that the key is to use plenty of water when mixing. When skimping on water, the consistency gets a lot thicker and unpleasant which resulted in a few dry retches. Near the end of the week I started drinking 4 shakes with higher water content as I found it a lot more pleasant.</p><p>I didn’t experience any radical changes while on this diet. I dropped 1kg, but attribute that just to fluctuations in my body mass. I’m confident though if I stayed on Joylent for longer I would lose more mass, as I often felt slight levels of hunger which wasn’t un-comforting and gave me the impression that my body was burning more fat reserves.</p><p>At the end of the seven days I celebrated by ordering a large stuffed crust pizza. Although I won’t be converting any time soon to a long-term Joylent only diet, I do like the idea of having it available for the few times where convenience is important. The team at Joylent is doing a great job at making science more available with their amazing marketing and image. I can’t wait to see how the company develops from here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24a91da1d794" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unminifying Google Tag Manager]]></title>
            <link>https://medium.com/@simonhfrost/unminifying-google-tag-manager-3d1d23e8e666?source=rss-b4f8ef85d4e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d1d23e8e666</guid>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Simon Frost]]></dc:creator>
            <pubDate>Sat, 31 Oct 2015 23:03:32 GMT</pubDate>
            <atom:updated>2015-10-31T23:03:32.660Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently had to enhance the analytic tracking capabilities at work. We use Google Tag Manager (GTM) along with Google Analytics (GA).</p><p>If you haven’t heard of GTM, it’s essentially a code snippet you include that provides capability to dynamically modify ‘tags’ which include code snippets such as Google Analytics.</p><p>I unminified the GTM snippet due to timing issues related to our implementation that couldn’t be resolved by recommended solutions found online in order to better understand how the script is loaded asynchronously.</p><p>Here is the original GTM snippet provided:</p><pre>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({&#39;gtm.start&#39;: new Date().getTime(),event:&#39;gtm.js&#39;});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!=&#39;dataLayer&#39;?&#39;&amp;l=&#39;+l:&#39;&#39;;j.async=true;j.src= &#39;//www.googletagmanager.com/gtm.js?id=&#39;+i+dl;f.parentNode.insertBefore(j,f); })(window,document,&#39;script&#39;,&#39;dataLayer&#39;,&#39;GTM-XXXXXX&#39;);</pre><p>Using a tool can automatically insert whitespace which greatly helps in readability. I used <a href="http://unminify.com/">http://unminify.com/</a></p><pre>(function(w, d, s, l, i) {<br>  w[l] = w[l] || [];<br>  w[l].push({<br>  ‘gtm.start’: new Date().getTime(),<br>    event: ‘gtm.js’<br>  });<br>  var f = d.getElementsByTagName(s)[0],<br>      j = d.createElement(s),<br>      dl = l != ‘dataLayer’ ? ‘&amp;l=’ + l : ‘’;<br>  j.async = true;<br>  j.src = ‘//<a href="http://www.googletagmanager.com/gtm.js?id=%27">www.googletagmanager.com/gtm.js?id=’</a> + i + dl;<br>  f.parentNode.insertBefore(j, f);<br>})(window, document, ‘script’, ‘dataLayer’, ‘GTM-XXXXXX’);</pre><p>Here we can see a function is defined and immediately executed with a set of values. A function is used to create an scope apart from the global scope, and parameters are used instead of local variables in order to save characters from an extra var.</p><p>Next I renamed the function parameters and internal variables. Luckily in this example the characters are the first letter of the values applied.</p><p>There are other methods of parameter naming such as in the Google Analytics snippet where the letters ‘I S O G R A M’ are used. An isogram can be: ‘a word or phrase in which each letter appears the same number of times’, which is a nice easter egg :)</p><pre>(function(window, document, script, datalayer, id) {<br>        window[datalayer] = window[datalayer] || [];<br>        window[datalayer].push({<br>            &#39;gtm.start&#39;: new Date().getTime(),<br>            event: &#39;gtm.js&#39;<br>        });<br>        var firstScript = document.getElementsByTagName(script)[0];<br>        var gtmScript = document.createElement(script);<br>        var dataLayerParam = datalayer != &#39;dataLayer&#39; ? &#39;&amp;l=&#39; + datalayer : &#39;&#39;;<br>        gtmScript.async = true;<br>        gtmScript.src = &#39;//www.googletagmanager.com/gtm.js?id=&#39; + id + dataLayerParam;<br>        firstScript.parentNode.insertBefore(gtmScript, firstScript);<br>    })(window, document, &#39;script&#39;, &#39;datalayer&#39;, &#39;GTM-XXXXXX&#39;);</pre><p>Above is the final unminified code. In summary:</p><ul><li>A global datalayer array is created for event tracking</li><li>A timestamped datalayer event for ‘GTM initializtion’ is added to the datalayer array</li><li>An async script element with a configurable GTM id and an optional dynamic datalayer name are prepared</li><li>The async script element is finalised and inserted into the DOM before all other scripts on the page</li></ul><p>For a more comprehensive analysis, please view the annotated source at the bottom of the file.</p><p>After I finished I was curious what the referenced script actually does. I decided not to investigate since it was hundreds of lines long, but would guess it’s responsible for modifying and handling events within the datalayer variable created within the snippet.</p><p>I then found an article related to asynchronous script loading here: <a href="https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/">https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/</a> where I found that not only does the property async = true provide asynchronous loading, but by creating an element and then inserting it into the DOM it also provides async support for older browsers that don’t support the async flag.</p><p>After understanding the snippet and reading the above article, I now felt a lot more confident about asynchronous script loading and managed to fix my issue.</p><p><strong>ANNOTATED SOURCE</strong></p><pre>(function(window, document, script, datalayer, id) {<br>        // Retrieve datalayer array from window scope or create an empty array if it doesn&#39;t exist<br>        window[datalayer] = window[datalayer] || [];<br><br>        // Push a timestamped event for GTM initialisation<br>        window[datalayer].push({<br>            &#39;gtm.start&#39;: new Date().getTime(),<br>            event: &#39;gtm.js&#39;<br>        });<br><br>        // Get the first script included on the page<br>        var firstScript = document.getElementsByTagName(script)[0];<br><br>        // Create a script element <br>        var gtmScript = document.createElement(script);<br><br>        // Optionally prepare the query parameter string for the datalayer name<br>        var dataLayerParam = datalayer != &#39;dataLayer&#39; ? &#39;&amp;l=&#39; + datalayer : &#39;&#39;;<br><br>        // Enable asynchronous loading for the GTM script<br>        gtmScript.async = true;<br><br>        // Finalise link to GTM script<br>        gtmScript.src = &#39;//www.googletagmanager.com/gtm.js?id=&#39; + id + dataLayerParam;<br><br>        // Insert new script element into DOM<br>        firstScript.parentNode.insertBefore(gtmScript, firstScript);<br><br>    })(window, document, &#39;script&#39;, &#39;datalayer&#39;, &#39;GTM-XXXXXX&#39;);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d1d23e8e666" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debugging Javascript Callbacks with the Chrome Debugger]]></title>
            <link>https://medium.com/@simonhfrost/debugging-javascript-callbacks-with-the-chrome-debugger-973c9e77240e?source=rss-b4f8ef85d4e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/973c9e77240e</guid>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Simon Frost]]></dc:creator>
            <pubDate>Sat, 31 Oct 2015 20:23:13 GMT</pubDate>
            <atom:updated>2015-10-31T20:23:13.869Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently worked on a bug within isolated and untested code written with a functional reactive programming language <a href="https://github.com/baconjs/bacon.js">Bacon.js</a>. The following are observations and experiences learned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/0*rqGLMs28JE5thBP4.png" /></figure><p>As with most bugs it’s simpler to isolate single input elements in order to divide and conquer. Ensure to solve one element or event at a time.</p><p>For me this element was hidden which didn’t affect functionality but made it harder to debug. I found this was easiest made visible by running $(“.myClass”).attr(“type=’text’”) in the console after each page refresh.</p><p>Adding logging to event handlers such as $($0).change(function( console.log(“changed”); ); can help in debugging user interaction, but unfortunately doesn’t trigger when the input is programatically set which is the case with callbacks.</p><p>There can be issues when debugging blur events if your breakpoint is too generic and triggers on both focus and blur. When the breakpoint triggers on focus, focus will then be given to the console which will prevent you from triggering the blur event.</p><p>You can solve this by being more specific with your breakpoints or creating conditional breakpoints that contain the event explicitly. event.type === focus works well.</p><p>If you have access to the event, but not it’s origin — Event.target is a useful property that will tell you the element origin. This will give you clues on why the event was fired.</p><p>There are multiple ways that event handlers can be specified on an element. Some can be subtly added by a css class which is picked up in an external library, others can be more obviously defined within your codebase itself.</p><p>Events in Javascript are complex yet prevalent, so it’s important to understand their complexities. I learnt a lot from debugging this particular bug.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=973c9e77240e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making my first iOS app at Midihack]]></title>
            <link>https://medium.com/@simonhfrost/making-my-first-ios-app-at-midihack-7d75cd815d6b?source=rss-b4f8ef85d4e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d75cd815d6b</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[midi]]></category>
            <dc:creator><![CDATA[Simon Frost]]></dc:creator>
            <pubDate>Sat, 31 Oct 2015 20:22:10 GMT</pubDate>
            <atom:updated>2015-10-31T20:22:10.812Z</atom:updated>
            <content:encoded><![CDATA[<p>My friend Ashok and I attended <a href="http://www.midihack.com/">Midi Hack</a> this year in Berlin and decided to make a iPhone app with Objective-C. You can see the final outcome here: <a href="https://github.com/ashokfernandez/MidiHack2015">The Certified Organic, Vegan Sequetron 5000</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*gkjY_bi_TveVxjPz.png" /></figure><p>Initially I didn’t make the connection between Objective-C and C, but came to realise Objective-C is essentially a layer on top of C that provides object-orientated functionality such as memory management. I have minimal experience with C and C++, but it was comforting that Objective-C wasn’t going to be a completely new language for me.</p><p>Ashok and I decided quite early on to split development between the backend (audio processing) and the frontend. At the end of the first 24 hours we met in the middle connecting the interface, and it just worked. It was such a great feeling!</p><p>It quickly became clear that there were a few niceties working with Javascript that I’ve taken for granted. Some of the biggest oddities that stood out to me in Objective-C were:</p><ul><li>Nil terminating an array [1, 2, 3, 4, nil]</li><li>Having to use wrapper classes for primitives that added memory management for you. NSString instead of string, etc.</li><li>Odd syntax such as [dog bark] which calls the bark method on the dog object</li><li>The lack of debugging tools and not being able to inspect local variables while at a breakpoint. But perhaps I just wasn’t familiar with the tools.</li></ul><p>There were also other aspects that gave me more insight into programming:</p><ul><li>Using the xcode interface for programming UI interaction was very unique. Ashok said it felt like the UI helped you along a lot, not like eclipse or other bloated editors that make it feel too clunky.</li><li>The UI programming workflow was a lot different to CSS. Paddings and margins are used with constraints which was initially confusing. The tools were completely different than fiddling around in the chrome debugger.</li><li>It felt so good to be able to write terrible code. There just simply wasn’t enough time to read up and implement best practices. That combined with knowing we were essentially going to throw the app out after the hack day lead to a 30 minute copy and paste session. A small guilty pleasure.</li></ul><p>Overall the event was really great. Amazingly organised, and tons of inspiring and passionate people to talk to. It was probably the first time I’ve managed to make an MVP and still have time on our hands. It was great to use that to focus on polish and jokes :)</p><p>At the end of the hack we both felt a bit guilty as we said we would make a launchpad and raspberry pi sequencer, but due to lack of organisation completely switched it up. Hopefully we’ll still be invited back next time :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d75cd815d6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>