<?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[Coding Snippets - Medium]]></title>
        <description><![CDATA[Coding problems solved through a lot of head scratching, hair pulling and teeth pulling - Medium]]></description>
        <link>https://medium.com/coding-snippets?source=rss----fef7351e886d---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Coding Snippets - Medium</title>
            <link>https://medium.com/coding-snippets?source=rss----fef7351e886d---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 19:40:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/coding-snippets" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Correlating Services in App Insights]]></title>
            <link>https://medium.com/coding-snippets/correlating-services-in-app-insights-97041fdbe513?source=rss----fef7351e886d---4</link>
            <guid isPermaLink="false">https://medium.com/p/97041fdbe513</guid>
            <category><![CDATA[application-insights]]></category>
            <dc:creator><![CDATA[Damian]]></dc:creator>
            <pubDate>Sat, 26 Oct 2019 14:23:14 GMT</pubDate>
            <atom:updated>2019-10-26T14:20:34.567Z</atom:updated>
            <content:encoded><![CDATA[<p>When one service call another service it is important when troubleshooting latency issues to know how long each service is taking to process, it’s also important to see the stack of calls that happen across both services to help track down errors. To do this you can use a correlation id.</p><p>Microsoft App Insights provides a unique id for each request that comes into service. To access it via code you can do this:</p><pre>System.Diagnostics.Activity.Current?.RootId;</pre><p>Note: You may need to add the nuget package System.Diagnostics.DiagnosticSource</p><p>To pass this ID onto another service will depend on how you are calling that service. If its a REST API i would suggest adding a http header (say operation-id) containing this value.</p><p>The next step for the service to accept that id and use it. In your other service you will need to add a Telemetry Initializer to your App Insights setup code:</p><pre>TelemetryConfiguration.Active.TelemetryInitializers.Add(new CorrelationInitializer());</pre><p>Then create the class CorrelationInitializer.cs:</p><pre>public class CorrelationInitializer : ITelemetryInitializer<br>    {<br>        public void Initialize(ITelemetry telemetry)<br>        {<br>            string operationId = HttpContext.Current.Request.Headers.Get(&quot;operation-id&quot;);<br>            if (!string.IsNullOrEmpty(operationId))<br>            {<br>                telemetry.Context.Operation.Id = operationId;<br>            }<br>        }<br>    }</pre><p>Notice in this case we get the operation id from a http header.</p><p>Now, when service A calls service B the call will include the operationid from A and apply it to B and your application insights logs will look a lot better for it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97041fdbe513" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-snippets/correlating-services-in-app-insights-97041fdbe513">Correlating Services in App Insights</a> was originally published in <a href="https://medium.com/coding-snippets">Coding Snippets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analyse your Ionic App Size]]></title>
            <link>https://medium.com/coding-snippets/analyse-your-ionic-app-size-3568b7f9077f?source=rss----fef7351e886d---4</link>
            <guid isPermaLink="false">https://medium.com/p/3568b7f9077f</guid>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Damian]]></dc:creator>
            <pubDate>Tue, 27 Nov 2018 16:25:06 GMT</pubDate>
            <atom:updated>2018-11-27T16:24:22.603Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s a tip on analyzing your bundle size, the dependencies your app relies on and how to quickly identify payload bloat.</p><p>At the command line produce a stats file of your project:</p><pre>ng build --prod --stats-json</pre><p>Then run webpack bundle analyzer to visualize your app:</p><pre>npx webpack-bundle-analyzer www/stats.json</pre><p>(note: this will run the tool without installing it).</p><p>You should then see a visualization of your Ionic app opened in a browser window:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DpN4JI6eg5QpQzAJuzAddw.png" /></figure><p>The size of each box shows relative size compared to your app. In this example you can see that moment.js take up as much as @angular or @ionic, its now a great candidate to review whether it is needed in the app or whether it can be replaced by something lighter like <a href="https://date-fns.org/">date-fns</a>.</p><p>One word of advice: often the largest part of your application is actually the icons and splash screens and their variations. Consider the larger picture and start with (for example) the generated IPA file for your app. Rename it to .zip, extract it to a folder (rename the .app file to .zip as well and extract that), then review the folder sizes to review icons, splash screens and native plugin sizes. You may get some great savings by optimizing your pngs or using jpg instead.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3568b7f9077f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-snippets/analyse-your-ionic-app-size-3568b7f9077f">Analyse your Ionic App Size</a> was originally published in <a href="https://medium.com/coding-snippets">Coding Snippets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Turning Off Change Detection for Performance in Ionic]]></title>
            <link>https://medium.com/coding-snippets/turning-off-change-detection-for-performance-in-ionic-1e8449388449?source=rss----fef7351e886d---4</link>
            <guid isPermaLink="false">https://medium.com/p/1e8449388449</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[ionic4]]></category>
            <dc:creator><![CDATA[Damian]]></dc:creator>
            <pubDate>Sat, 15 Sep 2018 13:48:18 GMT</pubDate>
            <atom:updated>2018-09-15T13:47:54.411Z</atom:updated>
            <content:encoded><![CDATA[<p>Angular’s change detection is usually quite great, but I found a case where it’s performance was terrible on a page that contained a long vertical list of horizontal lists of images (think the soundcloud home page where there are lots of categories of songs each represented by an image).</p><p>The big problem was that with potentially hundreds of images i wanted to only load images that were within the viewing area.</p><p>For this use case i used IntersectionObserver which does just that. One, thing to note is that it isn’t available on iOS and requires a <a href="https://github.com/w3c/IntersectionObserver/tree/master/polyfill#configuring-the-polyfill">polyfill</a> and requires the polyfill to be tweaked with POLL_INTERVAL of say 1000.</p><p>Next step was to turn off change detection on the page by adding this to @component:</p><pre>changeDetection: ChangeDetectionStrategy.OnPush,</pre><p>and this to the constructor:</p><pre>private cdr: ChangeDetectorRef</pre><p>then this to ngOnInit():</p><pre>this.cdr.detach();</pre><p>Without change detection i needed to know when there were changes to my view or interaction from the user. For the interaction i wanted to know whenever the user scrolled or touched the app. In Ionic 4 I can get the scroll by doing the following:</p><pre>&lt;ion-content #content&gt;</pre><p>then adding the ViewChild for it:</p><pre>@ViewChild(&#39;content&#39;)</pre><pre>content: Content;</pre><p>then in my ionViewDidEnter():</p><pre>const element = await this.content.getScrollElement();<br>this.scrollSubscription = merge(fromEvent(window, &#39;touchstart&#39;), fromEvent(element, &#39;scroll&#39;), interval(1000))</pre><pre>.pipe(debounceTime(300),startWith(0))</pre><pre>.subscribe((e) =&gt; { this.cdr.detectChanges(); });</pre><p>Note: i’ve imported some stuff from rxjs here:</p><pre>import { fromEvent, interval, merge } from &#39;rxjs&#39;;<br>import { debounceTime, startWith } from &#39;rxjs/operators&#39;;</pre><p>So what does this magic do?</p><p>The “getScrollElement” will get the HTML element of the ion-content that scrolls. Then the “fromEvent” gets an observable of events whenever the user scrolls in that content. The “touchstart” code gets events whenever the user touches the screen (eg to slide left/right) and the interval operator gives an event every 1 second. The debounceTime operator ensures i don’t get flooded with events. Finally, the detectChanges causes Angular to manually check for changes in the view.</p><p>The end result is that whenever the user interacts with the page we efficiently check for changes and re-render.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e8449388449" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-snippets/turning-off-change-detection-for-performance-in-ionic-1e8449388449">Turning Off Change Detection for Performance in Ionic</a> was originally published in <a href="https://medium.com/coding-snippets">Coding Snippets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing IOS 11 web apps (apple-mobile-web-app-capable)]]></title>
            <link>https://medium.com/coding-snippets/fixing-ios-11-web-apps-apple-mobile-web-app-capable-e5ed1a8c66e0?source=rss----fef7351e886d---4</link>
            <guid isPermaLink="false">https://medium.com/p/e5ed1a8c66e0</guid>
            <category><![CDATA[ionic-framework]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[ios-11]]></category>
            <dc:creator><![CDATA[Damian]]></dc:creator>
            <pubDate>Sat, 30 Dec 2017 14:11:33 GMT</pubDate>
            <atom:updated>2017-12-30T14:11:14.180Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are building a progressive web app or at least a web app that uses apple’s “apple-mobile-web-app-capable” meta tag then you may have recently run into a problem where if you add your site to the home screen and launch it you have a white 20px bar on the bottom and your content overlaps with the IOS status bar (see below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*UOhp_NiAGZ5JqyiyOrxaNA.jpeg" /><figcaption>Here’s the before and after screenshots</figcaption></figure><p>After some digging i found it’s a problem with using <strong>viewport-fit=cover</strong> which is required for an app to look great on the new iPhoneX (especially with Ionic).</p><p>To get around the problem i conditionally set the viewport-fit property by adding this bit of script to index.html</p><pre>if (window.navigator.standalone) {</pre><pre>document.querySelector(&#39;meta[name=viewport]&#39;).setAttribute(&#39;content&#39;, &#39;width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no&#39;);</pre><pre>}</pre><p>This detects if we are in “<a href="https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html">standalone</a>” web app mode and if so will replace the viewport metatag to be one <strong>without </strong>viewport-fit=cover. I still leave in the metatag:</p><pre>&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover&quot;&gt;</pre><p>That’s essentially it.</p><h3>Did you know you can add an app to the home screen?</h3><p>You can! In IOS Safari press the share icon (in the middle of the bottom toolbar) and choose <strong>Add to home screen </strong>(as shown below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*hxma1nK58424iu4sbTFzFg.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5ed1a8c66e0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-snippets/fixing-ios-11-web-apps-apple-mobile-web-app-capable-e5ed1a8c66e0">Fixing IOS 11 web apps (apple-mobile-web-app-capable)</a> was originally published in <a href="https://medium.com/coding-snippets">Coding Snippets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Javascript DateTime formatting (50x perf)]]></title>
            <link>https://medium.com/coding-snippets/optimizing-javascript-datetime-formatting-50x-perf-b92e552af24e?source=rss----fef7351e886d---4</link>
            <guid isPermaLink="false">https://medium.com/p/b92e552af24e</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Damian]]></dc:creator>
            <pubDate>Wed, 27 Dec 2017 19:16:52 GMT</pubDate>
            <atom:updated>2017-12-27T19:16:32.251Z</atom:updated>
            <content:encoded><![CDATA[<p>Formatting dates and times in javascript can be very expensive in terms of CPU cost. Take this simple piece of code that formats a string value like &quot;2017-12-27T16:37:37.417Z&quot; to 8:37 AM</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef25389a4cfaca7df260ae3cc8a9cabe/href">https://medium.com/media/ef25389a4cfaca7df260ae3cc8a9cabe/href</a></iframe><p>The conversion toLocaleTimeString take a lot of time. We can improve performance by a factor of ~50x by replacing with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4f153c51987b970acb3c03ae257bb7a/href">https://medium.com/media/e4f153c51987b970acb3c03ae257bb7a/href</a></iframe><p>When running both functions 10,000 times asTimeOld takes 4300ms, asTimeNew takes 95ms.</p><p>Note that we create the <strong>Intl.DateTimeFormat</strong> type globally then reuse it in the asTimeNew function.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b92e552af24e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-snippets/optimizing-javascript-datetime-formatting-50x-perf-b92e552af24e">Optimizing Javascript DateTime formatting (50x perf)</a> was originally published in <a href="https://medium.com/coding-snippets">Coding Snippets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gulp.src missing all files]]></title>
            <link>https://medium.com/coding-snippets/gulp-src-missing-all-files-a9f13e79ba38?source=rss----fef7351e886d---4</link>
            <guid isPermaLink="false">https://medium.com/p/a9f13e79ba38</guid>
            <category><![CDATA[gulp]]></category>
            <dc:creator><![CDATA[Damian]]></dc:creator>
            <pubDate>Wed, 29 Nov 2017 20:21:22 GMT</pubDate>
            <atom:updated>2017-11-29T20:21:10.248Z</atom:updated>
            <content:encoded><![CDATA[<p>In a gulp script that’s been working for years:</p><pre>gulp.src([&quot;*.js&quot;, &quot;!*.spec.js&quot;])</pre><p>I found that after installation of gulp globally on a new build server that the above line was returning no files. So had the modify it to:</p><pre>gulp.src([&quot;!(*.spec).js&quot;])</pre><p>This can probably be traced back to <a href="https://www.npmjs.com/package/glob">glob </a>or <a href="https://www.npmjs.com/package/minimatch">minimatch </a>changing at some point in time.</p><p>Hope this helps someone out there!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9f13e79ba38" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-snippets/gulp-src-missing-all-files-a9f13e79ba38">Gulp.src missing all files</a> was originally published in <a href="https://medium.com/coding-snippets">Coding Snippets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rxjs 5.5 “ Property ‘map’ does not exist on type Observable…’”]]></title>
            <link>https://medium.com/coding-snippets/rxjs-5-5-property-map-does-not-exist-on-type-observable-e825129c2068?source=rss----fef7351e886d---4</link>
            <guid isPermaLink="false">https://medium.com/p/e825129c2068</guid>
            <category><![CDATA[ionic3]]></category>
            <category><![CDATA[angular-5]]></category>
            <category><![CDATA[rxjs]]></category>
            <dc:creator><![CDATA[Damian]]></dc:creator>
            <pubDate>Fri, 17 Nov 2017 16:46:01 GMT</pubDate>
            <atom:updated>2017-11-17T16:46:00.911Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve just converted an Ionic app to Angular 5 which relies on rxjs 5.5+. One of the odd errors that i found and didn’t quite understand why was “Property ‘map’ does not exist on type Observable” (or any operator like take or tap).</p><p>It took a moment to realize that the problem was related to the fact that you need to add pipe around all operators. So this:</p><pre>this.myObservable().map(data =&gt; {})</pre><p>becomes this:</p><pre>this.myObservable().pipe(map(data =&gt; {}))</pre><p>And with your operators you need to switch to using <a href="https://github.com/ReactiveX/rxjs/blob/master/doc/lettable-operators.md">lettable operators</a> by switching from an import like this:</p><pre>import &#39;rxjs/add/operator/map&#39;;</pre><p>to this:</p><pre>import { map } from &quot;rxjs/operators&quot;;</pre><p>Also worth noting that the operator “do” has been changed to “tap” in rxjs 5.5 (and many others). This is after it was changed from “tap” to “do” in the <a href="https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md">migration </a>of rxjs 4 to 5 (ngWat <a href="https://twitter.com/shai_reznik"><strong>@</strong>shai_reznik</a>). In the world of Javascript this stuff is moving so fast it almost not worth writing a blog post on it as it has likely changed already.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e825129c2068" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-snippets/rxjs-5-5-property-map-does-not-exist-on-type-observable-e825129c2068">Rxjs 5.5 “ Property ‘map’ does not exist on type Observable…’”</a> was originally published in <a href="https://medium.com/coding-snippets">Coding Snippets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Traversing through a Javascript Object]]></title>
            <link>https://medium.com/coding-snippets/traversing-through-a-javascript-object-b66b35c2a6aa?source=rss----fef7351e886d---4</link>
            <guid isPermaLink="false">https://medium.com/p/b66b35c2a6aa</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angularfire2]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Damian]]></dc:creator>
            <pubDate>Wed, 15 Nov 2017 15:02:17 GMT</pubDate>
            <atom:updated>2017-11-15T15:01:56.829Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve started working with Firebase on a project and one of the interesting quirks with storing json data in its real-time database is that objects cannot have any properties that are undefined (you get “ <em>Error: Firebase.set failed: First argument contains undefined in property</em>”). They have to be stored as null instead.</p><p>However, after stackoverfloogling the problem i found all posted code snippets failed for my use case. So, here’s one i wrote: it recursively traverses the objects properties, including arrays and inspects all sub objects as well replacing properties that are undefined with null.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7df62ee06a5fd8df8a274d32d945e2cb/href">https://medium.com/media/7df62ee06a5fd8df8a274d32d945e2cb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b66b35c2a6aa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-snippets/traversing-through-a-javascript-object-b66b35c2a6aa">Traversing through a Javascript Object</a> was originally published in <a href="https://medium.com/coding-snippets">Coding Snippets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Acting as a Certificate Authority with OpenSSL]]></title>
            <link>https://medium.com/coding-snippets/acting-as-a-certificate-authority-with-openssl-a0d71b17bc95?source=rss----fef7351e886d---4</link>
            <guid isPermaLink="false">https://medium.com/p/a0d71b17bc95</guid>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[openssl]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <dc:creator><![CDATA[Damian]]></dc:creator>
            <pubDate>Tue, 02 May 2017 20:49:59 GMT</pubDate>
            <atom:updated>2017-05-02T21:26:05.149Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*qZe8jmg6705hKJKlhBT1UQ.png" /></figure><p>Certificates for websites and web services are easily obtained on the internet through companies like <a href="https://www.godaddy.com/web-security/ssl-certificate">GoDaddy</a>, <a href="https://www.comodo.com/">Comodo</a> and <a href="https://letsencrypt.org/">Lets Encrypt</a> but what do you do when you cannot access the internet? or want more control of expiration dates?</p><p>This guide provides a way to act as a Certificate Authority (CA) and create certificates signed by your company. It deals with the <a href="https://www.chromium.org/Home/chromium-security/education/tls/sha-1">deprecation of sha1</a> as well as the new requirements on certificates that were added into Google Chrome build 58 causing the error:</p><blockquote><strong>Subject Alternative Name Missing</strong> The certificate for this site does not contain a Subject Alternative Name extension containing a domain name or IP address.</blockquote><p>Steps 1–4 cover the setup process, step 5 shows how to create a certificate for a specific server and steps 6 &amp; 7 cover how to install and trust the certificate.</p><h3>1. Getting OpenSSL installed</h3><p>Visit <a href="https://www.openssl.org/">https://www.openssl.org/</a> and click the downloads link to get OpenSSL installed. For Windows installations visit <a href="https://wiki.openssl.org/index.php/Binaries">https://wiki.openssl.org/index.php/Binaries</a></p><p>For this guide i used the OpenSSL binaries from <a href="https://indy.fulgan.com/SSL/">here</a>. For simplicity i describe all files in the same folder.</p><h3>2. Configuring OpenSSL</h3><p>OpenSSL is highly configurable. For this guide please create a file called <em>openssl.cnf</em> and paste the following contents into it:</p><pre>[ req ]</pre><pre>default_bits = 2048</pre><pre>default_keyfile = server-key.pem</pre><pre>distinguished_name = subject</pre><pre>req_extensions = req_ext</pre><pre>x509_extensions = x509_ext</pre><pre>string_mask = utf8only</pre><pre><br>[ subject ]</pre><pre>countryName = Country Name (2 letter code)</pre><pre>countryName_default = US</pre><pre>stateOrProvinceName = State or Province Name (full name)</pre><pre>stateOrProvinceName_default = NY</pre><pre>localityName = Locality Name (eg, city)</pre><pre>localityName_default = New York</pre><pre>organizationName = Organization Name (eg, company)</pre><pre>organizationName_default = Example, LLC</pre><pre>commonName = Common Name (e.g. server FQDN or YOUR name)</pre><pre>commonName_default = Example Company</pre><pre>emailAddress = Email Address</pre><pre>emailAddress_default = test@example.com</pre><pre>[ x509_ext ]</pre><pre>subjectKeyIdentifier = hash</pre><pre>authorityKeyIdentifier = keyid,issuer</pre><pre>basicConstraints = CA:FALSE</pre><pre>keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment</pre><pre>subjectAltName = @alternate_names</pre><pre>[ req_ext ]</pre><pre>subjectKeyIdentifier = hash</pre><pre>basicConstraints = CA:FALSE</pre><pre>keyUsage = digitalSignature, keyEncipherment</pre><pre>subjectAltName = @alternate_names</pre><pre>[ alternate_names ]</pre><pre>DNS.1 =<strong>myserver</strong></pre><pre>DNS.2 =localhost</pre><pre>DNS.2 =localhost.localadmin</pre><pre>DNS.2 =127.0.0.1</pre><blockquote>Important: You must replace <strong>myserver</strong> in the above file with the fully qualified domain name of the server you are creating a certificate for. Its a good idea to automate this if you want the process to be repeatable, a suggestion would be to copy the config file and have your script replace this entry. If you do not do this then Google Chrome may flag your certificate as insecure.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*BRFv6jeDGEgRB8zIHJh-mg.png" /><figcaption>The pipeline we’ll create for creating certificates for servers</figcaption></figure><h3>3. Creating a private key</h3><p>We’ll create a private key for our root certificate by entering the following at the command prompt:</p><pre>openssl genrsa -aes256 -out rootcertificate.key 4096</pre><p>You will be asked for a pass phrase:</p><pre>Enter pass phrase for rootcertificate.key: <strong>my_root_ca_password</strong></pre><p>Obviously replace <strong>my_root_ca_password</strong> with your own unique password. It will be used later in creating certificates. It’s important that the password and the <em>rootcertificate.key</em> file that is created is kept secret and safe. Exposing these will potentially compromise all certificates you create.</p><h3>4. Creating the root certificate</h3><p>To create your certificate (with filename <em>rootcertificate.crt</em>) enter the following at the command prompt:</p><pre>openssl req -config openssl.cnf -key rootcertificate.key -new -x509 -days 9999 -sha256 -extensions v3_ca -out rootcertificate.crt</pre><p>You will be asked for your pass phrase (what you replaced <strong>my_root_ca_password </strong>with) as well as having to enter a few other questions:</p><pre>Enter pass phrase for rootcertificate.key:<br>You are about to be asked to enter information that will be incorporated<br>into your certificate request.<br>What you are about to enter is what is called a Distinguished Name <br>There are quite a few fields but you can leave some blank<br>For some fields there will be a default value,<br>If you enter ‘.’, the field will be left blank.<br> — — -<br>Country Name (2 letter code) [US]:<strong>US</strong><br>State or Province Name (full name) [NY]:<strong>NY</strong><br>Locality Name (eg, city) [New York]:<strong>New York</strong><br>Organization Name (eg, company) [Example, LLC]:<strong>My Company LLC</strong><br>Common Name (e.g. server FQDN or YOUR name) [Example Company]:<strong>My Company Root CA<br></strong>Email Address [<a href="/service/mailto:test@example.com">test@example.com</a>]:</pre><p>The important question to answer is the <em>Common Name</em>. Other entries are optional.</p><p>You now have 2 files created called <em>rootcertificate.key</em> and <em>rootcertificate.crt</em>.</p><blockquote>The file <em>rootcertificate.crt</em> can be made publicly available and can be installed on any computer or mobile device so that created certificates (in the steps below) will be trusted.</blockquote><h3>5. Creating a server certificate</h3><p>This section will show you how to create a certificate for a particular server that has been signed by your root certificate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*ux3DQIvnhbhnOc2fv7DMEA.png" /></figure><p>We’ll create a private key and a certificate signing request (CSR) for a server whose name is <em>myserver</em>:</p><pre>openssl req -new -nodes -sha256 -keyout myserver.key -config openssl.cnf -out myserver.csr -newkey rsa:2048 -subj &quot;/C=US/ST=/L=/O=/CN=<strong>myserver</strong>&quot;</pre><p>Be sure to replace the <strong>myserver</strong> part of <em>CN=myserver</em> with the full computer name of the server. This creates two files: <em>myserver.key</em> and <em>myserver.csr</em></p><blockquote>Important: notice that we specify the config file called openssl.cnf. In this file there a server specific setting that we should set which is the subject alternative name (subjectAltName). It appears in the file under the [ alternative_names ] section, here you can specify one or more alternative names for the server. Eg blar.com, <a href="http://www.blar.com,/">www.blar.com,</a> mail.blar.com</blockquote><p>We can now create a certificate for the server using this command:</p><pre>openssl x509 -sha256 -extfile openssl.cnf -extensions x509_ext -req -in myserver.csr -CA rootcertificate.crt -CAkey rootcertificate.key -CAcreateserial -out myserver.crt -days 9999 -passin pass:<strong>my_root_ca_password</strong></pre><p>Again, replace <strong>my_root_ca_password</strong> with the pass phrase you set when creating the private key for the root certificate.</p><p>You now have created the server certificate file <em>myserver.crt</em> and you have the associated private key in the file <em>myserver.key</em>. One thing you may want to do is bundle both together as a <em>.pfx</em> file so that they can be installed on the server. To do this:</p><pre>openssl pkcs12 -export -in myserver.crt -inkey myserver.key -out myserver.pfx -certfile rootcertificate.crt -passout pass:<strong>mypassword</strong></pre><p>Make sure to replace <strong>mypassword</strong> with the password you want to use (this will be required to install the <em>pfx </em>file).</p><p>At this point you have everything you need to install the server’s certificate and access the server from a client by installing the <em>rootcertificate.crt</em> on client machines. The following are examples of how to do this with Microsoft IIS for the server and IOS / Windows PCs for the clients.</p><h3>6. Installing the Server Certificate</h3><p>These instructions are for a Windows server running IIS:</p><ul><li>Copy <strong>myserver.pfx</strong> to the server and double click it</li><li>Choose <strong>Store Location</strong> of “<em>Local Machine</em>”</li><li>Click <strong>Next </strong>through the wizard entering the certificate password</li><li>Choose the option “<em>Automatically select the certificate store based on the type of certificate</em>”</li></ul><p>Next we can bind the certificate to your website in IIS:</p><ul><li>Open IIS Manager (Press <strong>start</strong>, type “<em>IIS</em>” and press <strong>Enter</strong>)</li><li>Open <strong>Sites </strong>in the tree view on the left and select the website</li><li>Click <strong>Bindings</strong>… in the menu on the right hand side</li><li>Edit the <strong>https </strong>binding (or <strong>add </strong>it)</li><li>From the SSL certificate drop down choose your certificate</li><li>Press <strong>OK </strong>and Close the site binding window</li></ul><h3>7. Clients trusting us</h3><p>To get clients (eg web browsers, mobile devices) to trust your certificate you must install the Root Certificate (<em>rootcertificate.crt</em>) on the client (usually in the “<em>Trusted Root Certification Authorities</em>” area).</p><h4>Installing on Windows</h4><p>Here’s how to manually install the <strong>root </strong>certificate (This would normally be done by an I.T dept by Group Policy):</p><ul><li>Double click the <em>rootcertificate.crt</em> file</li><li>Click the <strong>Install Certificate…</strong> button</li><li>Click <strong>next</strong>, the choose “<em>Place all certificates in the following store</em>”</li><li>Choose <strong>Browse </strong>and select “<em>Trusted Root Certification Authorities</em>”</li><li>Click <strong>OK </strong>and finish the installation</li></ul><p>Your web browser should now trust any certificates that have been signed by your root certificate.</p><h4>Installing on IOS</h4><p>Two options for installing rootcertificate.crt on iOS include:</p><ul><li>Email rootcertificate.crt and access that mail attachment on the iOS device in the mail application.</li><li>Make rootcertificate.crt accessible on a web page and on the iOS device use safari to open the file</li></ul><p>After either option an “Install Profile” page will appear:</p><ul><li>Press the <strong>Install </strong>button</li><li>Enter your passscode on the device</li><li>Press the <strong>Install </strong>button again on the warning page</li><li>The certificate should appear as “<em>verified</em>”. Press <strong>Done</strong></li></ul><h3>Finally….</h3><p>Thanks for checking out this guide. It covers a simple way to create server certificates. There are other best practices around this such as creating intermediate certificates which are used to create the server certificates but this adds additional complexity. I hope this helps some people out — i wrote it as googling around didn’t provide sufficient answers, if you have questions or comments feel free to reach out in the comments or on twitter <a href="https://twitter.com/damiantarnawsky">@damiantarnawsky</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0d71b17bc95" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-snippets/acting-as-a-certificate-authority-with-openssl-a0d71b17bc95">Acting as a Certificate Authority with OpenSSL</a> was originally published in <a href="https://medium.com/coding-snippets">Coding Snippets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing App Store upload problem with NSPhotoLibraryUsageDescription and PhoneGap Build]]></title>
            <link>https://medium.com/coding-snippets/fixing-app-store-upload-problem-with-nsphotolibraryusagedescription-and-phonegap-build-17cd0e542fe3?source=rss----fef7351e886d---4</link>
            <guid isPermaLink="false">https://medium.com/p/17cd0e542fe3</guid>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[ios-10]]></category>
            <category><![CDATA[phonegap]]></category>
            <dc:creator><![CDATA[Damian]]></dc:creator>
            <pubDate>Wed, 08 Mar 2017 17:33:03 GMT</pubDate>
            <atom:updated>2017-03-08T17:32:40.422Z</atom:updated>
            <content:encoded><![CDATA[<p>After submitting an app to the App Store, Apple added a new requirement in iOS 10 related to any apps using the Camera, Bluetooth, Photo Library etc. Apple will email you about the problem when uploading your IPA. Example:</p><pre><strong>Missing Info.plist key</strong> - This app attempts to access privacy-sensitive data without a usage description. The app&#39;s Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.</pre><pre><strong>Missing Info.plist key</strong> - This app attempts to access privacy-sensitive data without a usage description. The app&#39;s Info.plist must contain an NSBluetoothPeripheralUsageDescription key with a string value explaining to the user how the app uses this data.</pre><pre><strong>Missing Info.plist key</strong> - This app attempts to access privacy-sensitive data without a usage description. The app&#39;s Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.</pre><p>When using PhoneGap Build it isn&#39;t obvious how to supply these values in your config.xml. So, here is how to do it:</p><pre>&lt;config-file platform=&quot;ios&quot; parent=&quot;NSPhotoLibraryUsageDescription&quot; mode=&quot;replace&quot;&gt;<br>   &lt;string&gt;Allows access to photo library&lt;/string&gt;<br>&lt;/config-file&gt;</pre><pre>&lt;config-file platform=&quot;ios&quot; parent=&quot;NSBluetoothPeripheralUsageDescription&quot; mode=&quot;replace&quot;&gt;<br>  &lt;string&gt;Allows access to bluetooth devices&lt;/string&gt;<br>&lt;/config-file&gt;</pre><pre>&lt;config-file platform=&quot;ios&quot; parent=&quot;NSCameraUsageDescription&quot; mode=&quot;replace&quot;&gt;<br>   &lt;string&gt;Allows usage of the camera&lt;/string&gt;<br>&lt;/config-file&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17cd0e542fe3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-snippets/fixing-app-store-upload-problem-with-nsphotolibraryusagedescription-and-phonegap-build-17cd0e542fe3">Fixing App Store upload problem with NSPhotoLibraryUsageDescription and PhoneGap Build</a> was originally published in <a href="https://medium.com/coding-snippets">Coding Snippets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>