<?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 Borama Apps on Medium]]></title>
        <description><![CDATA[Stories by Borama Apps on Medium]]></description>
        <link>https://medium.com/@boramaapps?source=rss-6f4d571df888------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*C-MXL1CEDx0Oiu6E.</url>
            <title>Stories by Borama Apps on Medium</title>
            <link>https://medium.com/@boramaapps?source=rss-6f4d571df888------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:49:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@boramaapps/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[Reverse audio files on IOS and Mac using Swift and Accelerate framework.]]></title>
            <link>https://boramaapps.medium.com/reverse-audio-files-on-ios-and-mac-using-swift-and-accelerate-framework-4b6fffd6ba12?source=rss-6f4d571df888------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b6fffd6ba12</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[avfoundation]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[audio-programming]]></category>
            <dc:creator><![CDATA[Borama Apps]]></dc:creator>
            <pubDate>Wed, 28 Jul 2021 01:29:12 GMT</pubDate>
            <atom:updated>2021-07-28T01:33:01.912Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently my task at <a href="https://kinzoo.com/">Kinzoo</a> was to add an option to reverse audio files. I’ve found a few examples, but they weren’t fast. I decided to use the reverse function from the Accelerate framework. It works fast!!!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86cb1b30b546ee5367af70ef22173bcc/href">https://medium.com/media/86cb1b30b546ee5367af70ef22173bcc/href</a></iframe><p>It’s important to note that file format is not the same as processing format, messing it up can lead to weird errors or wrong sample rate.</p><p>The main job is done inside a loop processing floatChannelData for each input file channel.</p><pre><strong>guard</strong> <strong>let</strong> data = buffer.floatChannelData <strong>else</strong> { <strong>return</strong> <strong>nil</strong> }<strong>for</strong> i <strong>in</strong> 0..&lt;buffer.format.channelCount {<br>  <strong>let</strong> stride = vDSP_Stride(1)<br>  vDSP_vrvrs(data.advanced(by: Int(i)).pointee, stride, vDSP_Length(frameLength))<br>}</pre><p>That’s it!<br>Please check my <a href="http://twitter.com/boramaapps">Twitter</a> and my <a href="https://borama.co/">apps</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b6fffd6ba12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Re-sign H3lix for IOS (yes Jailbreak…)]]></title>
            <link>https://boramaapps.medium.com/re-sign-h3lix-for-ios-yes-jailbreak-edb82f609c93?source=rss-6f4d571df888------2</link>
            <guid isPermaLink="false">https://medium.com/p/edb82f609c93</guid>
            <category><![CDATA[jailbreak]]></category>
            <category><![CDATA[iphone]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[cydia]]></category>
            <dc:creator><![CDATA[Borama Apps]]></dc:creator>
            <pubDate>Sat, 06 Feb 2021 21:33:19 GMT</pubDate>
            <atom:updated>2021-02-06T21:33:19.134Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been using h3lix (<a href="https://h3lix.tihmstar.net/">https://h3lix.tihmstar.net</a>) in the past on my Iphone. Recently I needed it again, but it turned out Cydia Impactor doesn’t let you install h3lix anymore.</p><p>There was a tweet about it:</p><p><a href="https://twitter.com/EzequielTBH/status/1197231387255939073">https://twitter.com/EzequielTBH/status/1197231387255939073</a></p><p>and followed the steps:</p><ol><li>Download h3lix (<a href="https://h3lix.tihmstar.net/">https://h3lix.tihmstar.net</a>)</li><li>Download (or copy paste) script and run it, patching downloaded h3lix.ipa. <a href="https://gist.github.com/jakeajames/b44d8db345769a7149e97f5e155b3d46">https://gist.github.com/jakeajames/b44d8db345769a7149e97f5e155b3d46</a></li><li>Create a new project in Xcode, run it on iPhone, to update certificates</li><li>Run IOS App Signer (<a href="https://www.iosappsigner.com/">https://www.iosappsigner.com</a>),</li></ol><p>4a. Enter your valid Certificate</p><p>4b. Enter Provisioning Profile using the one you created with your new project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MiZ5fnZF8HcVt3axC3GDWQ.jpeg" /></figure><p>4c. Change App Display Name if you wish</p><p>5. After “Done”, drag / drop signed h3lix with your certificate using Xcode (Devices and Simulators window)</p><p>6. Run H3lix (or how you named it) on your iPhone</p><p>7. Run Cydia, install Open SSH.</p><p>8. Restart device</p><p>9. Run H3lix (Kickstart again). You need to wait a bit (around 1 minute) after the phone is booted up, otherwise it will fail to kickstart.</p><p>That’s it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edb82f609c93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IOS, building WebRTC from source with bitcode enabled]]></title>
            <link>https://boramaapps.medium.com/ios-building-webrtc-from-source-with-bitcode-enabled-c8757d78c748?source=rss-6f4d571df888------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8757d78c748</guid>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[webrtc]]></category>
            <dc:creator><![CDATA[Borama Apps]]></dc:creator>
            <pubDate>Thu, 14 Jan 2021 17:11:58 GMT</pubDate>
            <atom:updated>2021-01-14T17:11:58.917Z</atom:updated>
            <content:encoded><![CDATA[<h3>Install depot_tools:</h3><pre>git clone <a href="https://chromium.googlesource.com/chromium/tools/depot_tools.git">https://chromium.googlesource.com/chromium/tools/depot_tools.git</a><br>export PATH=/path/to/fetched/depot_tools:$PATH</pre><h4>Build:</h4><pre>mkdir webrtc<br>cd webrtc<br>fetch --nohooks webrtc_ios<br>gclient sync<br>cd webrtc/src</pre><p>Enable bitcode and specify architecutres needed.</p><pre>tools_webrtc/ios/build_ios_libs.py --bitcode --arch arm64 x64 arm</pre><p>Framework is inside:</p><p>webrtc/src/out_ios_libs/</p><p>Official docs:</p><p><a href="https://webrtc.github.io/webrtc-org/native-code/ios/">iOS</a></p><p>How to strip unwanted architectures (when distributing to app store you need to strip x64 or i386).</p><p><a href="http://ikennd.ac/blog/2015/02/stripping-unwanted-architectures-from-dynamic-libraries-in-xcode/">Daniel Kennett</a></p><p>That’s it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8757d78c748" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IOS/OSX Messaging Using the Network Framework and Bonjour Service.]]></title>
            <link>https://boramaapps.medium.com/ios-osx-connections-with-network-framework-and-bonjour-service-7fa6130f5789?source=rss-6f4d571df888------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fa6130f5789</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[bonjour]]></category>
            <dc:creator><![CDATA[Borama Apps]]></dc:creator>
            <pubDate>Mon, 30 Nov 2020 12:52:26 GMT</pubDate>
            <atom:updated>2021-01-13T20:20:48.908Z</atom:updated>
            <content:encoded><![CDATA[<h3>IOS/OSX Messaging Using the Network Framework and Bonjour Service (no external server required!).</h3><p>Today we’ll explore how to send messages between multiple Apple devices using <strong>the Network framework</strong>, without the need of having external server. We’ll also use <strong>Bonjour</strong> service to let clients discover the each others automatically.</p><p>Let’s start with the first task: discovering devices using <strong>Bonjour </strong>(<a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/NetServices/Introduction.html">https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/NetServices/Introduction.html</a>)</p><p>To accomplish this task we’ll need a server a browser. The server does the advertising and handles clients, the browser finds available servers (listeners).</p><p>First of all, we need to add <strong>NSBonjourServices</strong> key to <strong>Info.plist </strong>(<a href="https://developer.apple.com/documentation/bundleresources/information_property_list/nsbonjourservices">https://developer.apple.com/documentation/bundleresources/information_property_list/nsbonjourservices</a>), and pass an array of Bonjour service types. In our case, we’ll define one type and we’ll use TCP protocol. The underscores in the type field are required!</p><pre><strong>&lt;key&gt;</strong>NSBonjourServices<strong>&lt;/key&gt;<br>&lt;array&gt;<br>&lt;string&gt;</strong>_superapp._tcp<strong>&lt;/string&gt;<br>&lt;/array&gt;</strong></pre><p>Next, we want to use any network available, preferably a local network, and to be able to use the local network on devices running IOS14 we need to add to <strong>Info.plist NSLocalNetworkUsageDescription</strong> key.</p><pre><strong>&lt;key&gt;</strong>NSLocalNetworkUsageDescription<strong>&lt;/key&gt;<br>&lt;string&gt;</strong>Why do we use Local Network????<strong>&lt;/string&gt;</strong></pre><p>We want to be able to see logs for both server and client (or browser) simultaneously in the Console.app for that we’ll create a global helper function and we’ll stick it in AppDelegate.swift</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29fbd0ea03685ba0a6e55fa231ed48bf/href">https://medium.com/media/29fbd0ea03685ba0a6e55fa231ed48bf/href</a></iframe><p>To run multiple Console.app instances, to open up a new Console.app, in the terminal type:</p><pre>open -n /System/Applications/Utilities/Console.app</pre><p><strong>Create server and start advertising</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f64a07a51e50bc74648d24ea5070c96e/href">https://medium.com/media/f64a07a51e50bc74648d24ea5070c96e/href</a></iframe><p>We use <strong>TCP</strong> protocol, we don’t use <strong>TLS</strong> (to keep the code super simple) and we use <strong>Bonjour service</strong> to advertise. As a name, we user “server” and as a type, we use the same type we added into <strong>Info.plist</strong>.</p><p>Before starting listener we need to add handlers otherwise it will not work.</p><p><strong>Create a browser and browse for available servers using Bonjour</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7b21e7073989b035adbcd7333ed1249/href">https://medium.com/media/c7b21e7073989b035adbcd7333ed1249/href</a></iframe><p>When creating NWBrowser it’s important to use the same type specified inside Info.plist and used in the NWListener. Also, we need to add handlers to the browser before starting it.</p><p><strong>Testing discovering server using Bonjour.</strong></p><p>We made both Browser and Server global so we can use them directly from SwiftUI View like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/613840025ed2f3158abade1e8741ec4f/href">https://medium.com/media/613840025ed2f3158abade1e8741ec4f/href</a></iframe><p>Now let’s run the app on two devices, start the server on the first device and tap the “Client” button on the second one.</p><p>On my <strong>server</strong> device console shows:</p><pre><strong>listener.stateUpdateHandler waiting(POSIXErrorCode: Network is down)<br>listener.stateUpdateHandler ready</strong></pre><p><strong>The client </strong>device shows:</p><pre><strong>browser.stateUpdateHandler ready</strong></pre><pre><strong>2020-11-30 07:47:02.461367+0100 MultiConnect[36355:9740017] [MPLogging] browser.browseResultsChangedHandler result: Result(nw: server._superapp._tcp.local.@[en0], endpoint: server._superapp._tcplocal., interfaces: [en0], metadata: &lt;none&gt;)</strong></pre><pre><strong>2020-11-30 07:47:02.724386+0100 MultiConnect[36355:9740017] [MPLogging] browser.browseResultsChangedHandler result: Result(nw: server._superapp._tcp.local.@[awdl0], endpoint: server._superapp._tcplocal., interfaces: [awdl0], metadata: &lt;none&gt;)</strong></pre><p><strong>Yay! The client’s phone was able to discover the server.</strong></p><p>Our second task: do something useful with our system (ie. send messages between devices). We’ll create a Client and Connection, to handle sending messages, we will start with Connection.swift</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7af9d7cbd614bdd53cdbed0d4ef587a2/href">https://medium.com/media/7af9d7cbd614bdd53cdbed0d4ef587a2/href</a></iframe><p>We will initiate the connection with either NWEndpoint (our client’s outgoing connection) or NWConnection (server’s incoming connection). We need to add stateUpdateHandler before starting the connection.</p><p>To test it, for now, we’ll just update the browser:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1af6050cb5021fe05cf945863adb2ea/href">https://medium.com/media/a1af6050cb5021fe05cf945863adb2ea/href</a></iframe><p>Update the server:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbf1eb2dc32e353306805ba421d368d4/href">https://medium.com/media/fbf1eb2dc32e353306805ba421d368d4/href</a></iframe><p>Let’s run it on two devices. We should see something like this in logs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0mwlA7osNlyE3syJWDnXWA.png" /></figure><p>Currently, our server will let us connect only one device, we will update the code to handle multiple simultaneous connections.<br>First, create Client.swift which will be shared across the app instead of Connection.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cce8209840b6032b1e3907756a7ad019/href">https://medium.com/media/cce8209840b6032b1e3907756a7ad019/href</a></iframe><p>Now, it will be the client role to connect to the server, not the browser.</p><p>Update Browser.swift:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f094b7e6e7f9e0e62c60520e620f216/href">https://medium.com/media/5f094b7e6e7f9e0e62c60520e620f216/href</a></iframe><p>The browser will discover available servers and pass the result to the client.</p><p>Update Server.swift</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8eb1b53ea12c3b56c6260db6ef76fa2/href">https://medium.com/media/d8eb1b53ea12c3b56c6260db6ef76fa2/href</a></iframe><p>The server will now store an array of connections instead of having one connection available.</p><p>We also have a <strong>send</strong> function which will send a messages to all connected clients.</p><p>Let’s update the connection:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/893f0c80581433cfe3f9f6ca905cf219/href">https://medium.com/media/893f0c80581433cfe3f9f6ca905cf219/href</a></iframe><p>We’ve added <strong>send(_ message: String) </strong>and<strong> receive() </strong>functions. The <strong>receive()</strong> function is first called when the connection state is <strong>.ready</strong>. <strong>connection.receive(…)</strong> schedules a single receive completion handler, so we need to call <strong>receive() </strong>again inside the handler, to receive more messages.</p><p>To test the system lets add the “Send” button to our ContentView, which will trigger sending a message:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c36830f437a3fde92fa8ccc7f9026aff/href">https://medium.com/media/c36830f437a3fde92fa8ccc7f9026aff/href</a></iframe><p>Let’s build and run the project on your devices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9PqZvuy1GovdgXRvIajMMg.png" /></figure><p><strong>Yay (v2)!!!! We can send and receive messages between our server and two clients.</strong></p><p>We don’t handle errors, and disconnections, because I wanted to make the code as short as possible, but of course in the production app it would have to be handled.</p><p>Here’s a WWDC talk about using Network framework:</p><p><a href="https://developer.apple.com/videos/play/wwdc2019/713/">https://developer.apple.com/videos/play/wwdc2019/713/</a></p><p>Here’s a sample project using Network framework to play Tic Tac Toe game, it’s a bit more advanced than my blog post project :)</p><p><a href="https://developer.apple.com/documentation/network/building_a_custom_peer-to-peer_protocol">Building a custom peer-to-peer protocol | Apple Developer Documentation</a></p><p>Here’s link to final version of the sample code:</p><p><a href="https://github.com/standinga/PeerConnections.git">standinga/PeerConnections</a></p><p>Please check my other posts, show some love (👏), follow me on twitter: <a href="http://twitter.com/boramaapps">http://twitter.com/boramaapps</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fa6130f5789" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep dive into Apple’s URLRequest Cache Policies]]></title>
            <link>https://medium.nextlevelswift.com/urlrequest-cache-policy-f7c30a96b698?source=rss-6f4d571df888------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7c30a96b698</guid>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[app-development]]></category>
            <dc:creator><![CDATA[Borama Apps]]></dc:creator>
            <pubDate>Sun, 23 Aug 2020 01:39:57 GMT</pubDate>
            <atom:updated>2020-12-30T17:27:11.413Z</atom:updated>
            <content:encoded><![CDATA[<h4>Hands-On analysis of Apple’s Cache Policies working together with a Node.js Express Server to increase API efficiency and performance</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TliA_uvta4IL0kxKzSKP0Q.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@cleyder-duque-1585619?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Cleyder Duque</a> from <a href="https://www.pexels.com/photo/photo-of-warehouse-3821385/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p><em>There are only two hard things in Computer Science: cache invalidation and naming things.</em></p><p><em>— Phil Karlton</em></p><p>Fortunately for us, Apple helps us by providing robust and powerful cache policies. Policies we should use instead of building a custom (NSCache) solution!</p><p>In this post, we’ll explore different URLRequest cache policies and the consequences of using them. Those policies apply to both iOS and macOS. We’ll use a hands-on approach looking both on server and front-end sides.</p><p>To make things easy, the Node.js Express Server (the Backend) will return strings, and we’ll log the responses in the console. <em>(Check out the source code for both Server and App at the bottom).</em></p><h4><strong>Cache Policy #1: useProtocolCachePolicy</strong></h4><p>The official Apple’s documentation shows a well-presented decision tree. <a href="https://developer.apple.com/documentation/foundation/nsurlrequest/cachepolicy/useprotocolcachepolicy"><em>https://developer.apple.com/documentation/foundation/nsurlrequest/cachepolicy/useprotocolcachepolicy</em></a>.</p><p>When looking at the responses, we are looking for both Cache-Control and the <a href="https://en.wikipedia.org/wiki/HTTP_ETag">HTTP Etag</a>. There are a couple of scenarios we will look at:</p><ol><li><strong>Cache-Control</strong> is not set, and <strong>Etag</strong> is disabled:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*P44d12YGhpxNWrTtMMG0gA.png" /></figure><p>The app did connect to the server, but URLSession ignored the updated response. It might not be what we expect as we can use Etag on the server to sync the app with the server after updating the assets on the server.</p><p>2. <strong>Cache-Control</strong> is not set, and<strong>Etag</strong> is changed every 2 seconds:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*DQTxje9XegafvLszJVSrYA.png" /></figure><p>Now every time the Etag changes, the URLSession gives us an updated asset.</p><p>3. <strong>Cache-Control</strong> is set to 4 seconds,<strong> </strong>and<strong> </strong><strong>Etag</strong> is changed every time the server asset changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*ZmJ3xo_qN5mbRtJv6CjiQg.png" /></figure><p>After receiving the first response with the max-age header set to 4 seconds, the app was hitting the server every 3 seconds. Still, the server returned the URLSession response every second with the status code 200. Secondly, the asset was updated when fetched from the server.</p><p>4. <strong>Cache-Control</strong> is set to 0 seconds, and<strong>Etag</strong>is not set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oO8TnJH2BiQ_Pd9hXxR5XA.png" /></figure><p>We hit the server on every call, but URLSession returns the same asset each time.</p><p>5. <strong>Cache-Control</strong>is set to 0 seconds (or not set at all), and <strong>Etag</strong> changes on each incoming request</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9myeZjrdORje-P2Z9t-5bw.png" /></figure><p>We hit the server on every call, and URLSession gives us the most recent asset version. This is the same behavior we would get from using the CachePolicy reloadIgnoringLocalCacheData , always returning the latest asset version.</p><h4><strong>Cache Policy #2: returnCacheDataElseLoad</strong></h4><p>Apple’s documentation says: “Use existing cache data, regardless of age or expiration date, loading from originating source only if there is no cached data.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*ICSqKhh28Osu_AdOYvly-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*0mfC45VKled3FjrBCv6-xw.png" /></figure><p>When we use this policy, no matter how we set (or not set) both Etag and Cache-Control on the server, we’ll get just one “snapshot” of the asset, and the server will never be hit again unless we clear the local cache with for example:</p><pre>URLCache.shared.removeAllCachedResponses()</pre><p>It seems like URLRequest.CachePolicy.returnCacheDataElseLoad<strong> </strong>is quite a dangerous policy!</p><h4><strong>Cache Policy #3: reloadIgnoringLocalCacheData</strong></h4><p>For this cache policy, Apple’s documentation says: “This policy specifies that no existing cache data should be used to satisfy a URL load request.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*EF4u-nF4TSLCpelZn29Wxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*PkjmnuuSemwM99CgWtMriA.png" /></figure><p>No matter how we set Cache-Policy header or Etag, the server will be hit every second, and the latest asset will be returned. This policy should be handled with care to avoid overloading the server!</p><h4>Cache Policy #4: returnCacheDataDontLoad</h4><p>Apple describes the cache policy as: “If there is no existing data in the cache corresponding to a URL load request, no attempt is made to load the data from the originating source, and the load is considered to have failed. This constant specifies a behavior that is similar to an “offline” mode.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eqOivdm1N6CLIxWsstFs9Q.png" /></figure><p>And indeed, the results seen above are very similar to an offline mode. As you can see, our Express server was not hit by a request once!</p><h4><strong>Let’s hit our server using different cache policies at once.</strong></h4><p>Each policy needs to be directed to a unique endpoint. If the endpoints are the same, the cache will be overwritten every time we run a request with the policy URLRequest.CachePolicy.<strong>reloadIgnoringLocalCacheData</strong> !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uQwZ2XYM66csHn-397VMQA.png" /></figure><p>This is what happens if we hit the same endpoint using different caching policies:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n_nZI_wbvYeF0hJ2tuhIZw.png" /></figure><p>The URLRequest response is overwritten, and the server is only hit once by URLRequest.CachePolicy.<strong>returnCacheDataElseLoad </strong>and<strong> </strong>URLRequest.CachePolicy.<strong>useProtocolCachePolicy </strong>requests<strong>.</strong></p><h4>Summary</h4><p>In my opinion, we should use Apple’s caching capabilities, but some of the behaviors we analyzed above might not be so obvious after reading the documentation.</p><p>Below is the Swift code (OSX Command Line App):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b15a9521641e0d772fb9feda0f277e25/href">https://medium.com/media/b15a9521641e0d772fb9feda0f277e25/href</a></iframe><p>And here’s our Nodejs server code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c2524434da63e5e71f93afde6be4d14/href">https://medium.com/media/1c2524434da63e5e71f93afde6be4d14/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*U2nuSQNHqsHTI2MZ.png" /></figure><p><a href="https://medium.nextlevelswift.com/">Next Level Swift</a></p><p><em>We are always looking for talented and passionate Swift developers! Feel free to check out our writer&#39;s section and find out how you can share your knowledge with the Next Level Swift Community!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7c30a96b698" width="1" height="1" alt=""><hr><p><a href="https://medium.nextlevelswift.com/urlrequest-cache-policy-f7c30a96b698">Deep dive into Apple’s URLRequest Cache Policies</a> was originally published in <a href="https://medium.nextlevelswift.com/">Next Level Swift</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Assorted OSX / Linux commands cheat sheet]]></title>
            <link>https://boramaapps.medium.com/assorted-osx-linux-commands-cheat-sheet-bca12c6e244c?source=rss-6f4d571df888------2</link>
            <guid isPermaLink="false">https://medium.com/p/bca12c6e244c</guid>
            <category><![CDATA[vps]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[cheatsheet]]></category>
            <dc:creator><![CDATA[Borama Apps]]></dc:creator>
            <pubDate>Fri, 20 Mar 2020 21:03:08 GMT</pubDate>
            <atom:updated>2020-03-20T21:03:08.267Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Reset mysql root access:</strong></p><pre>sudo service mysql stop<br><em>sudo mysqld_safe —skip-grant-tables —skip-networking &amp;<br>mysql -u root</em></pre><p>In the mysql:</p><pre>use mysql;<br>update user set authentication_string=password(&#39;NEWPASSWORD&#39;) where user=&#39;root&#39;;<br>flush privileges;<br>quit</pre><p>Restart mysql:</p><pre><em>sudo service mysql restart</em></pre><p>In case of: mysqld_safe Directory ‘/var/run/mysqld’ for UNIX socket file don’t exists. error, create this directory and set ownership:</p><pre>mkdir -p /var/run/mysqld<br>chown mysql:mysql /var/run/mysqld</pre><p>Grant access to mysql from other host:</p><pre>GRANT ALL PRIVILEGES ON *.* TO &#39;root&#39;@&#39;%&#39; IDENTIFIED BY &#39;password&#39; WITH GRANT OPTION;<br>FLUSH PRIVILEGES;</pre><p><strong>Check for running server in local network:</strong></p><pre>for i in {2..255}; do echo $i; curl --connect-timeout 1 192.168.0.$i; done</pre><p><strong>Check which process uses port:</strong></p><pre>sudo lsof -i :8081</pre><p><strong>Send image via POST form request using CURL:</strong></p><pre>curl -X POST -F &#39;image=@/Users/me/image.jpg&#39; https://server/image</pre><p><strong>Multiple http requests reading each url from line in the file:</strong></p><pre>cat links | while read line; do curl -O $line; done</pre><p><strong>Monitor Nginx errors in real time:</strong></p><pre>tail -f /var/log/nginx/error.log</pre><p><strong>Rename git branch when on this branch:</strong></p><pre>git branch -m new-name</pre><p><strong>Add new emails to Postfix</strong></p><pre>sudo nano /etc/postfix/virtual<br>sudo postmap /etc/postfix/virtual<br>sudo systemctl restart postfix</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bca12c6e244c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue, Nuxt, Firebase, Google-Sign]]></title>
            <link>https://boramaapps.medium.com/vue-nuxt-firebase-google-sign-87671d7983cb?source=rss-6f4d571df888------2</link>
            <guid isPermaLink="false">https://medium.com/p/87671d7983cb</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[google-sign-in]]></category>
            <dc:creator><![CDATA[Borama Apps]]></dc:creator>
            <pubDate>Wed, 20 Nov 2019 04:38:15 GMT</pubDate>
            <atom:updated>2020-05-17T01:39:55.319Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Let’s create a new Vue / Nuxt app:</strong></p><pre>npx create-nuxt-app google-sign</pre><p>Enable Axios, choose Single Page App rendering mode. Add firebase to our Nuxt app:</p><pre>npm install firebase --save</pre><p>Create a firebase plugin, add new file ‘firebase.js’ inside /plugins and register it inside nuxt.config.js</p><p><strong>Next, create a Firebase project. Go to</strong></p><p><a href="https://console.firebase.google.com/u/0/">https://console.firebase.google.com</a></p><p>and create a new project, call it ‘google-sign’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*QgrUGxTZKJmh2cl9zaxThA.png" /></figure><p>Inside the Firebase project, go to Settings and add a new Web app. Call it ‘google-sign’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*nM8hfUZeQT7EIKNuwDvGNA.png" /></figure><p>Copy firebaseConfig and go to our Nuxt app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*Y82u-r86jBHJsWR0t9ipSg.png" /></figure><p>Open up /plugins/firebase.js and update the file with copied firebaseConfig:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*LtwYph6f5R9X8q8WXtBviQ.png" /><figcaption>Add firebase.js plugin to plugins inside nuxt.config.js</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76389e183e4c83820b24a2d04f4d43dc/href">https://medium.com/media/76389e183e4c83820b24a2d04f4d43dc/href</a></iframe><p>Next, open up index.vue inside /pages folder, clean all of the boilerplate, and add “created” hook:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13d9fb0e303b01a49b74d2db9e879600/href">https://medium.com/media/13d9fb0e303b01a49b74d2db9e879600/href</a></iframe><p>Open up firebase console and create Realtime Database, set the rules to:</p><pre>{<br>  &quot;rules&quot;: {<br>    &quot;.read&quot;: true,<br>    &quot;.write&quot;: true<br>  }<br>}</pre><p>Inside the database, add new record using Name “test” and Value “test”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*3fEDPnI6Re1m0fR_oCVxAA.png" /></figure><p>Copy its https link, and paste it into Chrome, adding .json to the end of the link like:</p><pre><a href="https://sign-9aee2.firebaseio.com/test.json">https://sign-11111.firebaseio.com/test.json</a></pre><p>You should be able to see “test” in the browser window.</p><p>Now let’s try to read it from our Vue app using Axios. Inside created hook in our index.vue add:</p><pre>created: async function() {<br>  const test = await this.$axios.$get(&#39;https://sign-<a href="https://sign-9aee2.firebaseio.com/test.json">11111</a>.firebaseio.com/test.json&#39;)<br>  console.log(test)<br>}</pre><p>The console output should show “test”.</p><p><strong>The system is working, now we need to protect our database!</strong></p><p>Set the rules to allow only authenticated users:</p><pre>{<br>  &quot;rules&quot;: {<br>    &quot;.read&quot;: &quot;auth.uid != null&quot;,<br>    &quot;.write&quot;: &quot;auth.uid != null&quot;<br>  }<br>}</pre><p>If we try to connect to the database we’ll get <strong>Error 401</strong>. We need to set up authentication.</p><p>In the Firebase go to Authentication / Sign-in method and select Google. Add your support email, if you like, you can change thProject public -facing name to whatever you like, Enable and Save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pfJ-RFdOouf3cpqsRsmjsw.png" /></figure><p>Let’s update the index.vue once again:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c47e0c6fa0ddcfc11808e0b89752c3d/href">https://medium.com/media/7c47e0c6fa0ddcfc11808e0b89752c3d/href</a></iframe><p>Reload our project and click “Sign With Redirect” it will go to google, but very quickly back to the project, if we enable “Preserve log” in the console we’ll see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*8qzxi-xXWDGu0FzyKT1Oiw.png" /></figure><p>This is because we need to add Authorized redirect URI inside our project in Google Api console. The same error will occur if you set Google Api console, but forget to Enable Google Sign-In method in Firebase.</p><p>Go to <a href="https://console.developers.google.com/apis">https://console.developers.google.com/apis</a>, select your project (ie. google-sign)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*61hEQheZqdr3N_e5OCsuTg.png" /></figure><p>Under OAuth 2.0 client Ids tap on “Web client (auto-created by Google Service)”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PStQYNjpoSmQutyC3x7g3w.png" /></figure><p>Add “http://localhost:3000” (or any other port your dev server is running) to Authorized redirect URIs. Of course you can add your production or development URIs for example <a href="https://borama.co/">https://borama.co</a> :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*JktnuP6f2RjznOZElU_foA.png" /></figure><p>Click save, refresh Vue project and now you will be redirected to Google SignIn. Log in with your email and you will be back at localhost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*xE3WcifCVgQuT0U6rnhaiQ.png" /></figure><p><strong>How can we now get the data from firebase? We need a idToken. Because we are now authenticated we should be able to get it!</strong></p><p>Update test method inside index.vue:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c89e9f99314e030498805c47f022ec1/href">https://medium.com/media/5c89e9f99314e030498805c47f022ec1/href</a></iframe><p>Click the “Test” button and in the browser console you will see “test”. Yeah!</p><p><strong>Now just add login with a popup like:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b77ab2bc7e907ece04743559fa223962/href">https://medium.com/media/b77ab2bc7e907ece04743559fa223962/href</a></iframe><p>Click “Sign With Pop Up” and the popup will open.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*dY2KZqgfsuFFg_KuHe9z2A.png" /></figure><p>There’s one gotcha when working with a firebase database. You can’t really control which email addresses are allowed inside the google auth section. You can protect your database by creating a whitelist of allowed users, and adding the rules inside “Rules” section. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e6806f03fc4159c9b33e10ef0fbf1b8/href">https://medium.com/media/7e6806f03fc4159c9b33e10ef0fbf1b8/href</a></iframe><p>In reality, you will want to replace hardcoded ‘borama’ with emails stored inside a protected database child.</p><p>Now with those settings, I can still sign in using google account, but If I use email not containing borama, I won’t be able to access the database.</p><p>Here’s a link to the official documentation:</p><p><a href="https://firebase.google.com/docs/auth/web/google-signin">Authenticate Using Google with JavaScript | Firebase Authentication</a></p><p>The final version of index.vue, with both Authentication with Redirect and with Popup working:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/813ce0a0c5491d75471f8f293a0fb192/href">https://medium.com/media/813ce0a0c5491d75471f8f293a0fb192/href</a></iframe><p><strong>That’s it!</strong></p><p>Follow on Twitter: <a href="https://twitter.com/boramaapps">https://twitter.com/boramaapps</a></p><p>Check my ios and android apps!</p><p><a href="https://borama.co/">Borama Apps</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87671d7983cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Synchronizing async code with DispatchGroup, DispatchSemaphore]]></title>
            <link>https://medium.com/better-programming/synchronizing-async-code-with-dispatchgroup-dispatchsemaphore-de814e485e82?source=rss-6f4d571df888------2</link>
            <guid isPermaLink="false">https://medium.com/p/de814e485e82</guid>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Borama Apps]]></dc:creator>
            <pubDate>Tue, 09 Jul 2019 22:21:21 GMT</pubDate>
            <atom:updated>2020-08-30T01:43:49.864Z</atom:updated>
            <content:encoded><![CDATA[<h3>Synchronizing Async Code</h3><h4>With DispatchGroup and DispatchSemaphore</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gSRcL5lAyFe09FWfuK8dmg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jetcityninja?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">oakie</a> on <a href="https://unsplash.com/search/photos/synchronized?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Let say you need to perform multiple network calls and need to wait for them to complete to aggregate results.</p><p>I think the simplest solution would be to use <strong>DispatchGroup </strong>(if the order of execution doesn’t matter) or <strong>DispatchSemaphore</strong>.</p><p>I will demonstrate both the problem and its solutions by using a function which will combine two async calls and then using a loop containing async calls.</p><p>Let’s create a command-line project.</p><p>Create a function which will convert Int to String after a pre-defined delay.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb4d1cc3773a6b465883bb0c7fef0500/href">https://medium.com/media/bb4d1cc3773a6b465883bb0c7fef0500/href</a></iframe><h3>The First Scenario Without a Loop</h3><p>Create a function which will combine two async calls:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4275d5941017658199d2f2b7fccb204/href">https://medium.com/media/c4275d5941017658199d2f2b7fccb204/href</a></iframe><p>When we run it, the output will be empty because completionHandler is called before the fetchData completion handlers are executed.</p><p>The first solution (without persisting the order of execution) is to use DispatchGroup:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ee94ffce54ebe9f973390cd90e1d959/href">https://medium.com/media/3ee94ffce54ebe9f973390cd90e1d959/href</a></iframe><p>If we run this function now, the output will be “10” because the second fetchData takes less time complete than the first fetchData. This could be what we want (when we don’t care about the order of execution), but we might want the second fetchData to be called after the first one completes.</p><p>Solution for this scenario is to use DispatchSemaphore:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/525ff0832f4d8c95388b901b08af339d/href">https://medium.com/media/525ff0832f4d8c95388b901b08af339d/href</a></iframe><p>Now when we call this function the output will always be “01” regardless of how long any of the fetchData functions take to finish.</p><p>It’s important to remember that we can’t use semaphore on the main thread because it will block it forever.</p><p>Also if we don’t care about the order, we can put both semaphore.wait() before completionHandler. This will work the same as when using DispatchGroup.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c4ba243d804ff3cb2487c4f36ea0997/href">https://medium.com/media/4c4ba243d804ff3cb2487c4f36ea0997/href</a></iframe><h3><strong>The Second Scenario Using a Loop</strong></h3><p>Call the fetchData function in the loop passing random delay time:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59bc1b53a710ea2a78038ec4330b44e7/href">https://medium.com/media/59bc1b53a710ea2a78038ec4330b44e7/href</a></iframe><p>If we execute this code, the output will be:</p><pre>text:</pre><p>This is because print(“text:”, text) is called before any of the fetchData calls returned callbacks.</p><p>Let’s add synchronization:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63a51d16e95d4aae6b48b7ede837a9ee/href">https://medium.com/media/63a51d16e95d4aae6b48b7ede837a9ee/href</a></iframe><p>The output now will be random, for example:</p><pre><strong>1 - 6 - 16 - 15 - 13 - 0 - 10 - 14 - 9 - 7 - 17 - 19 - 3 - 8 - 18 - 4 - 11 - 2 - 12 - 5 -</strong></pre><p>The reason is all of the fetchData functions inside the loop will be called simultaneously, and after all callbacks complete and send group.leave(), group.notify() will be executed.</p><p>Finally, add DispatchSemaphore to serialize the execution inside the loop:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60ff4082a9dc70db6f80038b7edd28d4/href">https://medium.com/media/60ff4082a9dc70db6f80038b7edd28d4/href</a></iframe><p>Now each fetchData function will wait for previous to finish before executing and the result is:</p><pre><strong>0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 -</strong></pre><p>To recap, we have two tools for synchronizing async functions, if we just want to wait for all of them to finish we’d use DispatchGroup, if we want them to finish and execute in the order we’d use DispatchSemahpore.</p><p>That’s it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de814e485e82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/synchronizing-async-code-with-dispatchgroup-dispatchsemaphore-de814e485e82">Synchronizing async code with DispatchGroup, DispatchSemaphore</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Move wordpress from local host to remote site using Nginx and Docker.]]></title>
            <link>https://boramaapps.medium.com/move-wordpress-from-local-host-to-remote-site-using-nginx-and-docker-d20f448fa7f0?source=rss-6f4d571df888------2</link>
            <guid isPermaLink="false">https://medium.com/p/d20f448fa7f0</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[phpmyadmin]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[wordpress]]></category>
            <dc:creator><![CDATA[Borama Apps]]></dc:creator>
            <pubDate>Tue, 18 Jun 2019 15:42:37 GMT</pubDate>
            <atom:updated>2019-06-20T01:08:33.935Z</atom:updated>
            <content:encoded><![CDATA[<h3>Move Wordpress site into Docker and publish it on remote site using Nginx.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lwUa8GOHXKeboKz5EYsc_Q.png" /></figure><p>After finishing our family blog from our journey through Sulawesi, we still haven’t decided where we will host it. I decided using docker to contain it and make it easy to switch hosts in the future.</p><p><strong>Backup both content and database.</strong></p><p>Connect to your host (for example via ssh).</p><p>Zip the folder containing wordpress wp-content directory. For example /var/www/html/wp-content:</p><pre>sudo tar -czf wp-content.tar.gz wp-content</pre><p>Export database, where wordpress is the name of wordpress database “add-drop-table” will drop tables when importing this backed up database into existing one:</p><pre>mysqldump wordpress --add-drop-table -uuser -ppassword | gzip  &gt; wordpress.sql.gz</pre><p><strong>Recreate Wordpress on the local machine.</strong></p><p>I created directory sulawesi, copied both wp-content.tar.gz and wordpress.sql.gz into that directory. For example from within this directory you can run scp:</p><pre>scp user@server:/home/user/wp-content.tar.gz .<br>scp user@server:/home/user/wordpress.sql.gz .</pre><p>Create wp-content and extract wp-content.tar.gz into that directory. Also extract wordpress.sql.gz</p><p>Create docker-compose.yml:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e1a59e38101142a542d7d3dcc1c8d88/href">https://medium.com/media/3e1a59e38101142a542d7d3dcc1c8d88/href</a></iframe><p>I’m using .env file for storing mysql credentials (use user / password from your original/old wordpress instance):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0132c6860ea31e08661ae447d4c3d492/href">https://medium.com/media/0132c6860ea31e08661ae447d4c3d492/href</a></iframe><p>I’ve added</p><pre>DOCKER_COMPOSE_YML_LOCATION: ${PWD}</pre><p>because later when debuggin my containers I can see which docker-compose.yml was used for particular conainer. For example:</p><pre>docker inspect wordpress</pre><p>Will show the docker-compose.yml location under Config / Env / DOCKER_COMPOSE_YML_LOCATION</p><p>In db container volumes,</p><pre>- ./wordpress.sql:/docker-entrypoint-initdb.d/init.sql</pre><p>loads backed up database content from original site, theoretically we could use ./:docker-entrypoint-initdb.d/ mapping directory containing .sql or even wp-content.tar.gz but I didn’t work for me. Only explicit mapping sql to init.sql worked.</p><pre>- db_data:/var/lib/mysql</pre><p>this will ensure database persistance, this is named volume and the location is somewhere inside docker system.</p><p>In wordpress conainer:</p><pre>volumes:</pre><pre>- ./wp-content:/var/www/html/wp-content</pre><p>maps extracted wp-content to conainer’s wp-content.</p><p>I like to run:</p><pre>docker-compose config</pre><p>To see if my paths and environment variables are set, this is the ouput of current docker-compose.yml:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*Dx_pFvJAoGpI7PYSFDzqBQ.png" /></figure><p>Let’s run our containers, first not in detached mode:</p><pre>docker-compose up</pre><p>Go to localhost:8000, in terminal we should see we are hitting wordpress conainer, but there’s error: This site can’t be reached, <strong>localhost</strong> refused to connect.</p><p>We need to fix base url inside database.</p><p>Go to localhost:8080 (port configured for phpmyadmin), login using wordpress/wordpress or what ever put inside .evn for WORDPRESS_DB_USER / WORDPRESS_DB_PASSWORD</p><p>Open wp_options and change siteurl and homeurl to <a href="http://0.0.0.0:8000/">http://0.0.0.0:8000</a></p><p>Go to localhost:8000 again, if you still can’t connect, restart docker client.</p><p><strong>Move the setup to remote server.</strong></p><p>Compress the whole directory containing docker-compose.yml, .env, wordpress.sql and wp-content subdirectory. Copy it to remote server (using scp or ftp), extract it, and move to that directory.</p><p>Run <strong>docker-compose up -d</strong>, set up Nginx by adding server block with locations for phpmyadmin and for wordpress:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/020da05bb2ebe0bd99bf55a5792930fe/href">https://medium.com/media/020da05bb2ebe0bd99bf55a5792930fe/href</a></iframe><p>Connect to phpmyadmin and update <strong>siteurl</strong> and <strong>home</strong> inside <strong>wp_options</strong> table to point to actual domain (in my case nasulawesi.me).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p-UvHjjOGYXa7elb3qx2YQ.png" /></figure><p>In order to be able to update wordpress content in host’s directory, we need to run docker as root:</p><pre>sudo docker-compose up -d</pre><p>Just as a side note, during the whole process I had to restart docker services both on my destkop and on my remote computers, because they sometimes didn’t catch the containers updates, even when using:</p><pre>docker-compose down --volumes</pre><p>That’s it!</p><p><a href="https://borama.co/">Please check my IOS and Android apps!</a></p><p>Follow me on <a href="https://twitter.com/boramaapps">twitter</a> :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d20f448fa7f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UICollectionView inside UIView in Swift using XIB]]></title>
            <link>https://boramaapps.medium.com/uicollectionview-inside-uiview-in-swift-using-xib-905f65c508f?source=rss-6f4d571df888------2</link>
            <guid isPermaLink="false">https://medium.com/p/905f65c508f</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Borama Apps]]></dc:creator>
            <pubDate>Thu, 30 May 2019 23:11:22 GMT</pubDate>
            <atom:updated>2019-05-30T23:11:22.191Z</atom:updated>
            <content:encoded><![CDATA[<p>This post shows how to use UICollectionView inside UIView with custom UICollectionView cells and interface builder, this is super basic example without any extras.</p><p>First Create new Single View App.</p><p>Create custom view using File… New / Cocoa Touch Class, call it CustomView and make sure it subclasses UIView</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*aeTi-CWceWgPKAAEKEX5Nw.png" /></figure><p>Next create CustomView.xib, open New File… and select View, call it CustomView</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*SeSWXpW_ZjJFJ2K488P_mA.png" /></figure><p>Open this new .xib file in Interface Builder and set it’s File’s Owner to CustomView, also I like to change Size from Inferred to Freeform and set it’s size roughly to how the view will be presented.</p><p>Next we will connect the xib to swift.</p><p>From CustomView.xib drag the view to CustomView.swift and call it contentView.</p><p>Next override both inits (with frame and coder) they are necessary for either instantiating this view programmatically or by Storyboard. Both inits will call function in which we’ll load the .xib and setup the contentView.</p><p>Add “<strong>@IBDesignable” </strong>over class definition to see the view inside Storyboard.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4794f8a4b1c8c423f5e6908e7be77e05/href">https://medium.com/media/4794f8a4b1c8c423f5e6908e7be77e05/href</a></iframe><p>Next open Main.storyboard and add this view by adding UIView and setting it’s Custom Class to CustomView. Set some constraints or use auto constraints feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V_wx9ImOmK5cMydRzN77Sg.png" /></figure><p>Because we set the class as “<strong>@IBDesignable” </strong>we can already see the red background in the Storyboard.</p><p>Create custom UICollectionViewCell with corresponding .xib, File New…, Cocoa Touch Class, call it CustomCell, subclass UICollectionViewCell and check also create XIB file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*K__BX7ZI-khEXE9sNO2Qng.png" /></figure><p>Open CustomCell.xib in Interface Builder and add Label to it. Center the label both horizontally and vertically.</p><p>Drag the label from .xib to swift. <strong>Make sure .xib’s File’s Owner is NSObject, not the CustomCell, also after creating the connection inside Connections Inspector make sure the label is connected with Custom Cell, not with File Owner (it can happen)</strong>. If that happened break the connection, and reconnect outlet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*3U_zR5aC9vzztNZAONzKDg.png" /></figure><p>Set the cell’s reusable identifier to CustomCell:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*wCI_alDKYoWIbCuqCh_FKg.png" /></figure><p>Now back inside the CustomView we need to add collection view and register CustomCell.</p><p>Open CustomView.xib and add UICollectionView, connect it with CustomView.swift, let’s call the outlet collectionView. Conform CustomView to UICollectionViewDataSource and probably you will want to conform also to UICollectionViewDelegate although in this post there are no interactions with this collection view so no need for it:)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5bkUTk1yXq3lS38EIq-S6Q.png" /></figure><p>Create function initCollectionView() and register CustomCell and set dataSource for collectionView:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc03ae5cc22e6f27cfe264254934d124/href">https://medium.com/media/dc03ae5cc22e6f27cfe264254934d124/href</a></iframe><p>Finally implement <strong>func</strong> <strong>collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int)</strong> and <strong>func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath)</strong> inside which we dequeue custom cell using it’s identifier “CustomCell” and we type cast it to CustomCell class.</p><p>Updated CustomView.swift:</p><p><a href="https://gist.github.com/standinga/726c31bd3ea866643d5d8520c3343ab3">https://gist.github.com/standinga/726c31bd3ea866643d5d8520c3343ab3</a></p><p>Run the project and enjoy super nice UI. It does look decent doesn’t it? :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*F-PnvWT4aCl6egfD60fYbg.png" /></figure><p>Here’s link for github project:</p><p><a href="https://github.com/standinga/UICollectionViewInUIView">standinga/UICollectionViewInUIView</a></p><p>That’s it!</p><p><a href="https://borama.co/">Please check my IOS and Android apps!</a></p><p>Follow me on <a href="https://twitter.com/boramaapps">twitter</a> :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=905f65c508f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>