<?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 James Margrove on Medium]]></title>
        <description><![CDATA[Stories by James Margrove on Medium]]></description>
        <link>https://medium.com/@jamesmargrove?source=rss-9e0dd9a4e9ff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tb9GJDepJARCTQyWzMf8Tw.jpeg</url>
            <title>Stories by James Margrove on Medium</title>
            <link>https://medium.com/@jamesmargrove?source=rss-9e0dd9a4e9ff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 08:52:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jamesmargrove/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[How to export and SVG with only one path?]]></title>
            <link>https://jamesmargrove.medium.com/how-to-export-and-svg-with-only-one-path-d1c63acb1e51?source=rss-9e0dd9a4e9ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1c63acb1e51</guid>
            <category><![CDATA[icons]]></category>
            <category><![CDATA[path]]></category>
            <category><![CDATA[sketch]]></category>
            <category><![CDATA[gimp]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[James Margrove]]></dc:creator>
            <pubDate>Sat, 09 Jan 2021 09:54:43 GMT</pubDate>
            <atom:updated>2021-01-09T09:54:43.727Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s fairly simple but I found a little difficult to get totally streamlined and right. How to create a nice SVG icon for the images in the sketch files. Ok, so you can just export the image as an SVG but I really wanted something more standardized, whereby only one path was exported. Herein lies the problem. How to export and SVG with only one path?</p><ol><li>Make sure the image is formatted correctly. All images for icons should have the same dimensions of 24 x 24px for consistency. Moreover, the images should be in black and white, with a clear boundary between what is the icon and what is the background.</li><li>Export the image as an image .png with Sketch at 10x. I want all my paths within a 24px box. so the image should be within a 240px box.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*Cll1JteH9mFBfJdh5WW2eg.png" /></figure><ol><li>Import your new .png file into Gimp.</li><li>Using the magic wand select the black areas. If there are separate entities within the icon, press the shift key.</li><li>Go to the “Select” dropdown menu and run the “ToPath” function at the bottom.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hkz2MgcIyQq3lVs4KLo0qg.png" /></figure><p>4. Next, scale the image back down to 24px. Click “Image” and “Scale Image”. Inside the popup change the 240px width to 24px. The height should auto adjust and click “Scale”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AAaBMMhQrXB9GsOeLVkU1w.png" /></figure><p>5. Finally, export the path to an SVG. Right-click on the patch image in the layers viewfinder. And at the base, there is the function, Export Path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x6ciXpgEIFpf4kAIyUssiA.png" /></figure><p>Now we are all done. Simply, make sure the image is two-tone and in the correct size. Export as a .png at 10x the size you want, and import into gimp. Select the dark areas you want to be the path using a magic wand. Create the path, and scale down the image. Lastly, export the path. Now you can open the file in a text editor and copy out the path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*xN7I2tvZLCCrYpZLrIJUvA.png" /><figcaption>Finally, I can consistently create an SVG icon with a single path.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1c63acb1e51" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Awaiting for promises]]></title>
            <link>https://jamesmargrove.medium.com/awaiting-for-promises-86ec599eda78?source=rss-9e0dd9a4e9ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/86ec599eda78</guid>
            <dc:creator><![CDATA[James Margrove]]></dc:creator>
            <pubDate>Tue, 21 Jan 2020 22:36:58 GMT</pubDate>
            <atom:updated>2020-01-21T22:36:58.942Z</atom:updated>
            <content:encoded><![CDATA[<p>What is the most straightforward example of a promise with async and await?</p><pre><strong>Block 1 - simple example? (a)</strong> waiter function that returns a promise, and <strong>(b) </strong>async IIFE.</pre><pre><strong>(a)</strong></pre><pre>function <strong><em>waiter</em></strong>() {<br>    return new Promise(function (resolve) {<br>        setTimeout(resolve, 3000) <br>        }<br>    )<br>}</pre><pre><strong>(b)</strong></pre><pre>(async function () {<br>    var now = new Date()<br>    await <strong><em>waiter</em></strong>()<br>    console.log(&quot;end&quot;, new Date() - now)<br>}())</pre><p>Here, there is a typical function named ‘waiter’. ‘Waiter’ is only special because it returns a promise. In this example, the ‘setTimeout’ function was used to delay the completion of the task. In the second section of the code, an immediately invoked asynchronously function expression creates a new execution context. On creation, the variable now was assigned the date-time. The await operator function waits for the promise to resolve (or reject), before login the 3000ms time delay.</p><h4>Promises</h4><p>Going into more detail on what is going on here are two factors — the promise as well as async and await. Key to understand is a promise once invoked with the new operator is an object with three states: <em>pending</em>, <em>fulfilled </em>and <em>rejected. </em>The following code helps here to understand what is going on with the promise.</p><pre><strong>Block 2 - what&#39;s within a promise?</strong></pre><pre>var promise1 = new Promise(function(resolve) {<br>    setTimeout(function() {<br>      <strong><em>resolve</em></strong>(&quot;Hello World&quot;);<br>    }, 10000);<br>});</pre><pre>console.log(promise1);</pre><pre>setTimeout(function() {<br>    console.log(promise1);<br>}, 10000);</pre><p>The JavaScript Engine hoists up the variable “promise1” and assigns it undefined. When the code starts running, the new operator creates an instance of the Promise object type. This object was created with the arguments passed as a function expression taking an argument or resolve (another function expression) which resolves “Hello World” after 10s. This object was assigned to the promise1 variable, and in the next line of code, was logged to the console (block 3).</p><pre><strong>Block 3 - what does a pending promise look like?</strong></pre><pre><em>Promise {&lt;pending&gt;}<br></em>{ <br>    __proto__: Promise, <br>    <em>[[PromiseStatus]]</em>: “pending”, <br>    <em>[[PromiseValue]]</em>: undefined<br>}</pre><p>As expected, the value logged to the console is an object, that has the prototype Promise, and two keys. First Key is the PromiseStatus, which is “pending”; the second key is the undefined promise value.</p><p>Ten seconds later <strong>(block 2)</strong> the setTimeout prints the value of “promise1” to the console again. This time the promise has resolved, and the value is:</p><pre>Promise {&lt;resolved&gt;: &quot;Hello World&quot;}<em><br></em>{ <br>    __proto__: Promise, <br>    <em>[[PromiseStatus]]</em>: “resolved”, <br>    <em>[[PromiseValue]]</em>: &quot;Hello World&quot;<br>}</pre><p>The resolved promise has the value “Hello World”.</p><h4>Async and await</h4><p>JavaScript stops for nothing, and any asynchronous operations such as fetching data will not be waited for during code execution, representing a problem. How can the engine render data to the DOM if it cannot wait for the data to come back from the server? One tool to deal with this is the async and await function.</p><p>An async function can contain an await operator that will pause the execution and wait for the Promise’s resolution. The function’s execution will then resume and evaluates the fulfilled value of the promise.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86ec599eda78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functions in JavaScript (es5)]]></title>
            <link>https://jamesmargrove.medium.com/functions-in-javascript-es5-926820b57877?source=rss-9e0dd9a4e9ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/926820b57877</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[James Margrove]]></dc:creator>
            <pubDate>Sat, 16 Nov 2019 23:06:20 GMT</pubDate>
            <atom:updated>2019-11-17T15:54:46.082Z</atom:updated>
            <content:encoded><![CDATA[<p>Functions are an essential component of the JavaScript language, and as a result, I have been studying them in a little more detail the past few weeks. In this short article, I’ll discuss some types of Javascript functions and what behaviour do they exhibit. In Javascript es5 there are two functions types, the function expression, and function statement.</p><p>Firstly the syntax between a function expression and function statements is slightly different. In the code block below is a <strong>(a) </strong>function statement, and <strong>(b)</strong> is the function expression. A key difference in the written code is that the function expression is an anonymous function assigned to a variable, whereas the function statement is a named function.</p><pre><strong>Block 1 - (a) function statement, and (b) function expression.</strong></pre><pre><strong>(a)</strong></pre><pre>function greet(){<br>    console.log(&quot;Hello World&quot;)<br>}</pre><pre><strong>(b)</strong></pre><pre>var greet = function(){<br>    console.log(&quot;Hello World&quot;)<br>}</pre><p>The second noticeable difference between the function statement and the functional expression is with regards to hoisting. Hoisting moves variables and function statements to the top of their scope before code execution. Hence, for function statements, the syntax parser detects the function keyword, and the JavaScript engine declares the function before any code has run. Therefore function statements are always invoked after the function has been defined. However, organising your code in this way is not in keeping with best practice and should be avoided.</p><p>Nevertheless, to illustrate this, the following code is valid:</p><pre><strong>Block 2 - Hoisting the function expression.</strong></pre><pre>greet()</pre><pre>function greet(){<br>    console.log(&quot;Hello world&quot;)<br>}</pre><p>On initialisation, the JavaScript engine declares the function statement greet<em>,</em> moving it to the top of its scope. Hoisting thus allows and the code to execute successfully.</p><p>Function expressions work a little differently. Here in the code snippet (block 3), the variable greet is assigned an anonymous function. All declared variables are hoisted to the top of their scope before code execution, similar to the function statement; however, values are only assigned to the variables during code execution. Therefore the ‘greet’ variable is assigned the value of undefined on hoisting.</p><pre><strong>Block 3 - Uncaught TypeError: greet is not a function</strong></pre><pre>greet()</pre><pre>var greet = function(){<br>    console.log(&quot;Hello world&quot;)<br>}</pre><p>‘Uncaught TypeError: greet is not a function.’</p><p>Function expressions have additional features that make them useful. Closures, as arguments of other JavaScript functions and as Immediately Invoked Function Expression (IIFE).</p><pre><strong>Code block 4 - an Immediately invoked function expression (IIFE), (a) unasigned, (b) assigned to a variable.</strong></pre><pre><strong>(a)</strong><br>(function(){<br>    return &quot;Hello world <br>}())</pre><pre><strong>(b)</strong><br>var iife = (function () {<br>    return &quot;Hello world&quot;<br>}())</pre><p>Moreover, functions can take function expressions as arguments. In this example <strong>(Block 5)</strong>, a function statement named greeting is declared, which accepts a single argument called ‘callback’. The function expression is passed as an argument to the function statement and is invoked printing ‘Hello World’ to the console.</p><pre><strong>Code block 5 - function expressions passed as arguments to other functions</strong></pre><pre>function greeting(callback){<br>    callback()<br>}</pre><pre>greeting(function(){<br>    console.log(&quot;Hello World&quot;)<br>})</pre><p>Function expressions can also be used to separate codes variables with closures. In block 6, we can see this in action. In this single file, greet was declared three times — once in the global environment, and in each immediately invoked function expression. These closures allow the logging of greet to be clean.</p><pre><strong>Code blok 6 - closures</strong></pre><pre>var greet = &quot;World&quot;;</pre><pre>(function () {<br>    var greet = &quot;Hello&quot;<br>    console.log(greet)<br>}());</pre><pre>(function () {<br>    var greet = &quot;Joe&quot;<br>    console.log(greet)<br>}())</pre><pre>console.log(greet)</pre><p>To run through the code. First, the global greet variables were hoisted to the top of there scope and assigned the primitive value of undefined. Then the code is executed line by line. First, the value “World” was assigned to the ‘greet’ variable. Second, the first IFFE was invoked, greet was hoisted, declared, assigned the value “Hello”, and logged to the console. The second IFFE was invoked and printed “Joe” to the console. Finally, the console.log() is called writing the global variable greet’s value “World”. Using closures like this to partition variables is a trick for reducing the likelihood of conflicts, and is especially useful in the creation of packages, frameworks and large projects.</p><p>In summary, this article outlined the basics of functions in JavaScript. In es5, there are two function types, expressions and statements. Function statements are named, hoisted, and assigned memory space, whereas function expression are anonymous functions assigned to variables. JavaScript functions can be and passed to each other as arguments, and can be immediately invoked (IIFE). JavaScript functions also can create closures, to separate code to keep code separated and avoid conflicts in large codebases or packages. There is an additional function type in es6 called arrow functions, but for now, these are some of the critical aspects of JavaScript functions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=926820b57877" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React-native setup]]></title>
            <link>https://jamesmargrove.medium.com/react-native-setup-6b57fab1a681?source=rss-9e0dd9a4e9ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b57fab1a681</guid>
            <category><![CDATA[cocoapods]]></category>
            <category><![CDATA[navigation]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[James Margrove]]></dc:creator>
            <pubDate>Mon, 03 Dec 2018 23:32:29 GMT</pubDate>
            <atom:updated>2018-12-03T23:32:29.524Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A react-native, typescript, cocoapods, typescript, navigation, and native-base</em></p><p><strong>Step 0.</strong> ensure that all globals are installed. These are yarn, react native, etc. for cocoapods</p><pre>&gt; sudo gem install cocoapods, <br>&gt; npm install -g react-native-cli</pre><p><strong>Step 1.</strong> start a new react native project.</p><pre>&gt; react-native init project_name</pre><p><strong>Step 2.</strong> convert to typescript.</p><pre>&gt; yarn add --dev typescript<br>&gt; yarn add --dev react-native-typescript-transformer<br>&gt; yarn tsc --init --pretty --jsx react<br>&gt; touch rn-cli.config.js<br>&gt; mv App.js App.tsx</pre><p>The third command <em>‘yarn tsc’</em> creates a tsconfig.json file. Add to this file the configuration setting that you want. My current prefered options are:</p><pre>{<br>    <em>&quot;compilerOptions&quot;</em>: {<br>        <em>&quot;baseUrl&quot;</em>: &quot;.&quot;, <br>        <em>&quot;outDir&quot;</em>: &quot;build/dist&quot;,<br>        <em>&quot;module&quot;</em>: &quot;esnext&quot;,<br>        <em>&quot;target&quot;</em>: &quot;es5&quot;,<br>        <em>&quot;lib&quot;</em>: [&quot;es6&quot;, &quot;dom&quot;],<br>        <em>&quot;sourceMap&quot;</em>: true, <br>        <em>&quot;allowJs&quot;</em>: true,<br>        <em>&quot;jsx&quot;</em>: &quot;react&quot;,<br>        <em>&quot;moduleResolution&quot;</em>: &quot;node&quot;,<br>        <em>&quot;rootDir&quot;</em>: &quot;./&quot;,<br>        <em>&quot;forceConsistentCasingInFileNames&quot;</em>: true,<br>        <em>&quot;importHelpers&quot;</em>: true,<br>        <em>&quot;strict&quot;</em>: true,<br>        <em>&quot;strictNullChecks&quot;</em>: true,<br>        <em>&quot;suppressImplicitAnyIndexErrors&quot;</em>: true,<br>        <em>&quot;noUnusedLocals&quot;</em>: true,<br>        <em>&quot;experimentalDecorators&quot;</em>: true,<br>        <em>&quot;allowSyntheticDefaultImports&quot;</em>: true<br>    }<br>}</pre><p>Within the rn-cli.config.js file add this code:</p><pre>module.exports = {<br>    <strong><em>getTransformModulePath</em></strong>() {<br>        return require.resolve(&#39;react-native-typescript-transformer&#39;)<br>    },<br>    <strong><em>getSourceExts</em></strong>() {<br>        return [&#39;ts&#39;, &#39;tsx&#39;]<br>    }<br>}</pre><p><strong>Step 3.</strong> add in decorator support.</p><pre>yarn –dev add @babel/plugin-proposal-decorators</pre><p>The .babelrc file should look like this:</p><pre>{<br>  <em>&quot;presets&quot;</em>: [&quot;module:metro-react-native-babel-preset&quot;],<br>  <em>&quot;plugins&quot;</em>: [[&quot;@babel/plugin-proposal-decorators&quot;, { <em>&quot;legacy&quot;</em>: true}]]<br>}</pre><p><strong>Step 4.</strong> add cocoapods.</p><pre>&gt; cd ios/<br>&gt; pod init <br>&gt; pod install</pre><p>I removed all the files contents with the exception of:</p><pre>target &#39;frontend_lunch&#39; do</pre><pre>end</pre><p>This will probably need editing later in the project but for now, it is fine.</p><p><strong>Step 5.</strong> close down Xcode and open up the .xcworkspace file.</p><p><strong>Step 6.</strong> install navigation.</p><pre>&gt; yarn add react-navigation<br>&gt; yarn add react-native-guesture-handler <br>&gt; react-native link</pre><p>Don’t forget to add in the parts for Android in the MainActivity.java file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6WOalYwDuqVB4AnK9X0yiQ.png" /></figure><p><strong>Step 7.</strong> install native-base.</p><pre>&gt; yarn add native-base <br>&gt; react-native link </pre><p>Overall this code will generate a base of what is needed for a react native project. We have cocoapods to install native dependencies and do all the linking for ios,</p><p><strong>References</strong></p><ul><li><a href="https://docs.nativebase.io/docs/GetStarted.html">Getting Started</a></li><li><a href="https://facebook.github.io/react-native/docs/linking-libraries-ios">Linking Libraries · React Native</a></li><li><a href="https://guides.cocoapods.org/using/index.html">CocoaPods Guides</a></li><li><a href="https://reactnavigation.org/docs/en/getting-started.html">Getting started · React Navigation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b57fab1a681" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up a typescript react-native project with decorators]]></title>
            <link>https://jamesmargrove.medium.com/setting-up-a-typescript-react-native-project-with-decorators-93eb8a8ffa9?source=rss-9e0dd9a4e9ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/93eb8a8ffa9</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[James Margrove]]></dc:creator>
            <pubDate>Sun, 02 Dec 2018 18:32:59 GMT</pubDate>
            <atom:updated>2018-12-02T18:32:59.872Z</atom:updated>
            <content:encoded><![CDATA[<p>How to add decorators to a react-native project in typescript? This problem has plagued me for the last 5 hours. An option in the tsconfig.json file which should fix this — ‘allowExperimentalDecorators’ set to ‘true’.</p><p>yarn install the package</p><pre>&gt; yarn add @babel/plugin-proposal-decorators</pre><p>This package enables compilation of class and object decorators to ES5.</p><p>Next, add the following code to the .babelrc file.</p><pre>{<br>  &quot;presets&quot;: [&quot;module:metro-react-native-babel-preset&quot;],<br>  &quot;plugins&quot;: [<br>    [&quot;<a href="http://twitter.com/babel/plugin-proposal-decorator">@babel/plugin-proposal-decorator</a>s&quot;, { &quot;legacy&quot;: true }]<br>  ]<br>}</pre><p>For newbies like me.</p><p>ES5 is the ECMAScript 5th edition released during mid to late 2009. Babel is a software development tool that compiles code to runs on anything. Decorators are experimental therefore need to be assembled (compiled) into something readable for the browser or mobile (react-native).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93eb8a8ffa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React and .env: a simple guide for setup.]]></title>
            <link>https://jamesmargrove.medium.com/react-and-env-a-simple-guide-for-setup-81970a76e77d?source=rss-9e0dd9a4e9ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/81970a76e77d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[James Margrove]]></dc:creator>
            <pubDate>Thu, 16 Aug 2018 19:09:28 GMT</pubDate>
            <atom:updated>2018-08-16T23:14:11.558Z</atom:updated>
            <content:encoded><![CDATA[<p><em>…a simple react guide to .env (dotenv)</em></p><p>Some quick notes on using .env in react app. How to set it all up in. 7 steps.</p><p><strong>Step 1.</strong> yarn add the “dotenv” package.</p><p>yarn add dotenv</p><p><strong>Step 2.</strong> In the root folder i.e. ‘name-react-app’ for me it is ‘coffee-app’ run:</p><p>touch .env</p><p><strong>Step 3.</strong> Open the .env file. Add in the key value pair that you require.</p><p>REACT_APP_GOOGLE_API=&#39;xyz&#39;</p><p><strong>Step 4.</strong> Note: for create-react-app every key must begin with:</p><p>REACT_APP_</p><p><strong>Step 5.</strong> Call the dotenv config as soon as possible within the app. On this small project I am placing it in the App.js folder.</p><p>require(“dotenv”).<strong><em>config</em></strong>()</p><p><strong>Step 6.</strong> Now we can call the keys anywhere in the app as properties of process.env</p><p>GoogleMapsLoader.KEY = process.env.REACT_APP_GOOGLE_API;</p><p><strong>Step 7.</strong> Remember! Add git ignore the .env. Otherwise you will push the keys to github. This will let the world see, if they want to see, the access keys to for instance your google maps api or Amazon Web Services accounts. This has the potential to drain your bank account and therefore is unwise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YDVLnFdqQAgm16tJJKoQjg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81970a76e77d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>