<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Software Craftsmanship by Marcin Kliks</title>
    <description>How to make performant, usable and sexy software using Python, Swift and others.</description>
    <link>https://www.marcinkliks.plhttps://www.marcinkliks.pl/</link>
    <atom:link href="https://www.marcinkliks.plhttps://www.marcinkliks.pl/feed.xml" rel="self" type="application/rss+xml" />
    
      <item>
        <title>Tips for Software Engineering Managers in BigTech</title>
        <description>&lt;h2 id=&quot;dont-ask-for-permission-ask-for-forgiveness&quot;&gt;Don’t ask for permission; ask for forgiveness&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;If it’s a good idea, and it doesn’t break anything - do it. It’s faster to do it and learn from mistakes.&lt;/li&gt;
  &lt;li&gt;Systems are inflexible by design. But are the only way to drive the organization. If the system accepts it - do it. If the system is broken - ask me to change it. Not everything can be improved right away. Be patient.&lt;/li&gt;
  &lt;li&gt;I forgive people trying to do things and making mistakes. I don’t forgive avoiding things.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;release-early-release-often&quot;&gt;Release early release often&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Shipping early without getting feedback is stupidity. But shipping early just for listening to the customer’s feedback is the art of wisdom.&lt;/li&gt;
  &lt;li&gt;Be bold and ship an unpolished version; you are fighting with the market. Don’t criticize your colleges for shipping MVP.&lt;/li&gt;
  &lt;li&gt;Always share your proposals early to get initial feedback, before you invest more energy into finishing it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;focus-on-things-that-give-results&quot;&gt;Focus on things that give results&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Working software beats the best proposals.&lt;/li&gt;
  &lt;li&gt;Written proposal beats every meeting.&lt;/li&gt;
  &lt;li&gt;Building prototypes beats thinking, if it’s worth doing it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;meetings&quot;&gt;Meetings&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Review your calendar every month.&lt;/li&gt;
  &lt;li&gt;Avoid being at meetings only for “just in case” / &lt;a href=&quot;https://en.wikipedia.org/wiki/Fear_of_missing_out&quot;&gt;FOMO&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Leave meetings where you don’t contribute to.&lt;/li&gt;
  &lt;li&gt;Only attend the meetings with clear goals. Be brave to give polite feedback on meetings which are waste of time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;culture-and-strategy&quot;&gt;Culture and Strategy&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;The culture of people beats executive strategy every day.&lt;/li&gt;
  &lt;li&gt;If you want to know the culture of the company, listen to the jokes, it tells the truth under the surface.&lt;/li&gt;
  &lt;li&gt;The only way to change the culture is to empower good parts of it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;people-are-not-resources&quot;&gt;People are not resources&lt;/h2&gt;

&lt;p&gt;The best team is the effect of training, not recruitment.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Don’t assume you will just &lt;em&gt;get&lt;/em&gt; the best developers from the market. As a leader, your job is to develop and grow your team. Hire potential, and invest into people.&lt;/li&gt;
  &lt;li&gt;People will remember you for how you grew your team and what kind of teacher you have been. People remember managers, but they love great teachers.&lt;/li&gt;
  &lt;li&gt;Build a plan for the development of Junior, Mid, Senior, and Principal engineers. Most people don’t build plans not to specify points of failure.&lt;/li&gt;
  &lt;li&gt;If you want to make everyone happy, don’t become a leader. Good leaders make decisions that are good for the team in the long term, which can differ from individual goals.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;communication&quot;&gt;Communication&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Communication is such a crucial skill for the developer as the seven layers of the network stack are for microservices.&lt;/li&gt;
  &lt;li&gt;If you feel, that you’re good at communication, think again. Communication skills cover so many aspects of your job that it’s a never-ending skill to develop.&lt;/li&gt;
  &lt;li&gt;Invest in developing skills on how to do the best PR review, how to create good commit messages, take a course on how to write tech proposals, ADR, write concise documentation, make screencasts, and even the art of convincing management to  secure the budget.&lt;/li&gt;
  &lt;li&gt;Most of the “the product were great, but management has killed it” problems might come from not understanding how to communicate its features, progress, and problems.&lt;/li&gt;
  &lt;li&gt;Invest every year in building up your communication superpowers.&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Thu, 29 Dec 2022 00:00:00 +0000</pubDate>
        <link>https://www.marcinkliks.plhttps://www.marcinkliks.pl/2022/12/29/tips-for-software-eng-managers/</link>
        <guid isPermaLink="true">https://www.marcinkliks.plhttps://www.marcinkliks.pl/2022/12/29/tips-for-software-eng-managers/</guid>
      </item>
    
      <item>
        <title>Swift on Raspberry Pi 400</title>
        <description>&lt;p&gt;&lt;img src=&quot;/uploads/574678AA-1A52-4634-84F5-95595B09BCF8.jpeg&quot; alt=&quot;574678AA-1A52-4634-84F5-95595B09BCF8.jpeg&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Raspberry Pi 400 has sufficient power to run full-featured microservices written in Swift. Running Swift (together with MongoDB) on such a small gadget is serious fun!&lt;/p&gt;

&lt;p&gt;I’ve tested this setup on Raspberry PI 400 which has a quad core processor, 4 GB of RAM and a speedy USB 3.0 SSD, however the instructions below are not limited only to this device. &lt;br /&gt;
Even though base configuration was not overclocked, I’ve managed to run simple &lt;a href=&quot;http://vapor.codes&quot;&gt;Vapor-based microservice&lt;/a&gt;, and achieve over 10 000 req/sec on this little piece of silicon!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/uploads/pi-10k-24fa0e.png&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;installing-swift-on-rasperry-pi&quot;&gt;Installing Swift on Rasperry PI&lt;/h2&gt;

&lt;p&gt;If you want to use the latest Vapor 4, you need to upgrade Raspberry PI OS to 64 bits. Otherwise, this step may be skipped.&lt;/p&gt;

&lt;p&gt;Ideal setup, as of 01/2020 is:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Swift 5.3.1&lt;/li&gt;
  &lt;li&gt;MongoDB 4.9.0&lt;/li&gt;
  &lt;li&gt;Nginx&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For IDE we will use:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Visual Studio Code 1.52.1 (latest current version)&lt;/li&gt;
  &lt;li&gt;sourcekit-lsp trunk (revision:6eb17c9a7bc00bec83d57d2399ba9f5ab14d3bcc )&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;upgrading-to-rasperry-pi-os-64-bit&quot;&gt;Upgrading to Rasperry PI OS 64 bit&lt;/h2&gt;

&lt;p&gt;Swift ARM builds are available here: &lt;a href=&quot;https://packagecloud.io/swift-arm/release&quot;&gt;https://packagecloud.io/swift-arm/release&lt;/a&gt;. 
Unfortunatelly, the latest version for Rasperry PI OS (default distribution) is 5.1.3 and it’s not usable with the latest Vapor 4 version. We need to upgrade the operating system to 64 bits.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Install the beta version of Rasperry PI OS 64 bit &lt;a href=&quot;https://www.raspberrypi.org/forums/viewtopic.php?p=1668160&quot;&gt;here&lt;/a&gt; if you need the latest Swift.&lt;/li&gt;
  &lt;li&gt;Install swift package from packagecloud.io &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://packagecloud.io/swift-arm/release/packages/debian/buster/swiftlang_5.3.1-3-debian-buster_arm64.deb&lt;/code&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dpkg -i&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Swift REPL is not usable at the moment, but it’s not a big deal so don’t worry.&lt;/li&gt;
  &lt;li&gt;Swap file. Swift needs a lot of memory during the compilation, so let’s find a spare SSD drive, and create some fast swap files, at least 5 GB.
    &lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;swapoff &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;dd &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/dev/zero &lt;span class=&quot;nv&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/media/[yourssd]/swap &lt;span class=&quot;nv&quot;&gt;ibs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1M &lt;span class=&quot;nv&quot;&gt;obs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1M &lt;span class=&quot;nv&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;5000
mkswap /media/[yourssd]/swap
swapon /media/[yourssd]/swap
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;That’s it. Test if your code compiles. Vapor 4 should run just fine!
    &lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;swift package init &lt;span class=&quot;nt&quot;&gt;--type&lt;/span&gt; executable
swift build
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;ide-on-raspberry-pi-with-visual-studio-code-lsp-and-swift&quot;&gt;IDE on Raspberry PI with Visual Studio Code, LSP and Swift&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Install ARM64 DEB package from Visual Studio Code &lt;a href=&quot;https://code.visualstudio.com/download&quot;&gt;https://code.visualstudio.com/download&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;You need this package: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://github.com/apple/sourcekit-lsp&lt;/code&gt; to use the Auto-Completion functionality in Visual Studio Code, because version 5.3.1 is unusably slow. The new version is 10 times more performant. We will compile it from sources using this documentation &lt;a href=&quot;https://github.com/apple/sourcekit-lsp/blob/main/Documentation/Development.md&quot;&gt;here&lt;/a&gt;. 
This will work for arm64:&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;swift build -c release -Xcxx -I/usr/lib/swift -Xcxx -I/usr/lib/swift/Block
cp .build/aarch64-unknown-linux-gnu/release/sourcekit-lsp /usr/local/bin/sourcekit-lsp

apt-get install npm
cd Editors/vscode
npm run createDevPackage
code --install-extension ./out/sourcekit-lsp-vscode-dev.vsix
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;After installation, every feature should work well, including: autocompletion, fix-its, documentation, go to definition.
If not, it’s probably because of the internal card speed - see below how to improve the performance by a factor of 10.&lt;/p&gt;

&lt;h2 id=&quot;optimization&quot;&gt;Optimization&lt;/h2&gt;

&lt;p&gt;SD cards tend to be slow. I recommend to either boot from an SSD entirely, or boot from an SD card, but in this case move the essential data to faster drive. It makes a huge difference during development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Directories to move to external faster drive:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;~/.config/Code &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;Visual Studio Code&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
~/.cache  &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;various developmnt tasks&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
/tmp &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;e.g. lsp cache&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can tune your system for maximum performance:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;fs.inotify.max_user_watches=524288
cd /sys/devices/system/cpu
echo performance &amp;gt; cpu0/cpufreq/scaling_governor 
echo performance &amp;gt; cpu1/cpufreq/scaling_governor 
echo performance &amp;gt; cpu2/cpufreq/scaling_governor 
echo performance &amp;gt; cpu3/cpufreq/scaling_governor 
echo performance &amp;gt; cpu4/cpufreq/scaling_governor 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;mongodb-on-raspberry-pi&quot;&gt;MongoDB on Raspberry PI&lt;/h2&gt;

&lt;p&gt;Ok, this is an optional step. Chances are, your microservice needs a database, such as MongoDB. Yes, it works just fine, but you need to compile it from sources.&lt;/p&gt;

&lt;p&gt;You need at least 20 GB of free space for compilation. Compilation will take at least 5-10 hours.&lt;/p&gt;

&lt;p&gt;We will compile as usual using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://github.com/mongodb/mongo/blob/master/docs/building.md&lt;/code&gt;, but have to provide additional flag since there are problems with crc32 because of missing instructions. &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-30893&quot;&gt;More information here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using flag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--use-hardware-crc32=off&lt;/code&gt; will compile it fine. Full script should look similar to this:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone https://github.com/mongodb/mongo.git

python3 &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; vevn virtualenv
&lt;span class=&quot;nb&quot;&gt;source &lt;/span&gt;virtualenv/bin/activate

python3 buildscripts/scons.py install-mongod &lt;span class=&quot;nt&quot;&gt;--disable-warnings-as-errors&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--use-hardware-crc32&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;off

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Congratulations, after 5-10 hours, you will get the 4,2 GB binary file called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mongodb&lt;/code&gt;. It’s time to strip it to just ~40 MB with the instructions below:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root@raspberrypi:/media/pi/rpi/mongo# &lt;span class=&quot;nb&quot;&gt;ls &lt;/span&gt;build/install/bin/mongod
build/install/bin/mongod

root@raspberrypi:/media/pi/rpi/mongo# strip build/install/bin/mongod
root@raspberrypi:/media/pi/rpi/mongo# &lt;span class=&quot;nb&quot;&gt;cp &lt;/span&gt;build/install/bin/mongod /usr/local/bin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now it’s time to prepare a storage space for a database and logs. Use your external drive and mount it somewhere. E.g. create &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mongo-data&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mongo-logs&lt;/code&gt; directories, and use the following configuration files as examples.
I used the simplest configuration possible. I recommend changing the default user &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pi&lt;/code&gt;, for security reasons.&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root@raspberrypi:/media/pi/rpi/mongo# &lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /etc/systemd/system/mongodb.service 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-ini highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nn&quot;&gt;[Unit]&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;Description&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;MongoDB Database Server&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;Documentation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;https://docs.mongodb.org/manual&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;After&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;network-online.target&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;Wants&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;network-online.target&lt;/span&gt;

&lt;span class=&quot;nn&quot;&gt;[Service]&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;pi&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;Group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;adm&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#EnvironmentFile=-/etc/default/mongod
&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;ExecStart&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/bin/mongod --config /etc/mongod.conf&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;PIDFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/var/run/mongodb/mongod.pid&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# file size
&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;LimitFSIZE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;infinity&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# cpu time
&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;LimitCPU&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;infinity&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# virtual memory size
&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;LimitAS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;infinity&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# open files
&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;LimitNOFILE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;64000&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# processes/threads
&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;LimitNPROC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;64000&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# locked memory
&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;LimitMEMLOCK&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;infinity&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# total threads (user+kernel)
&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;TasksMax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;infinity&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;TasksAccounting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;false&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
&lt;/span&gt;
&lt;span class=&quot;nn&quot;&gt;[Install]&lt;/span&gt;
&lt;span class=&quot;py&quot;&gt;WantedBy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;multi-user.target&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And this is the counterpart &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/mongod.conf&lt;/code&gt; file.&lt;/p&gt;

&lt;div class=&quot;language-ini highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# mongod.conf
&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/
&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Where and how to store data.
&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;storage:&lt;/span&gt;
  &lt;span class=&quot;err&quot;&gt;dbPath:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;/media/&lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;[yourssd]&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;/mongo-data&lt;/span&gt;
  &lt;span class=&quot;err&quot;&gt;journal:&lt;/span&gt;
    &lt;span class=&quot;err&quot;&gt;enabled:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#  engine:
#  wiredTiger:
&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# where to write logging data.
&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;systemLog:&lt;/span&gt;
  &lt;span class=&quot;err&quot;&gt;destination:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;file&lt;/span&gt;
  &lt;span class=&quot;err&quot;&gt;logAppend:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;true&lt;/span&gt;
  &lt;span class=&quot;err&quot;&gt;path:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;/media/&lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;[yourssd]&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;/mongo-logs/mongo.log&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# network interfaces
&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;net:&lt;/span&gt;
  &lt;span class=&quot;err&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;27017&lt;/span&gt;
  &lt;span class=&quot;err&quot;&gt;bindIp:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;127.0.0.1&lt;/span&gt;


&lt;span class=&quot;c&quot;&gt;# how the process runs
&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;processManagement:&lt;/span&gt;
  &lt;span class=&quot;err&quot;&gt;timeZoneInfo:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;/usr/share/zoneinfo&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;#security:
&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#operationProfiling:
&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#replication:
&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#sharding:
&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;## Enterprise-Only Options:
&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#auditLog:
&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#snmp:
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, it’s time to run it!&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;systemctl daemon-reload
service mongodb start
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Check your logs directory for troubleshooting with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;journalctl -u mongodb.service&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Congratulations!&lt;/p&gt;

&lt;p&gt;I hope you will have as much fun as I did with this. Feel free to leave any comments or suggestions below. 
Thanks for trying it out!&lt;/p&gt;
</description>
        <pubDate>Tue, 19 Jan 2021 16:45:00 +0000</pubDate>
        <link>https://www.marcinkliks.plhttps://www.marcinkliks.pl/programming/2021/01/19/swift-services-with-mongo-on-raspberry-pi-400/</link>
        <guid isPermaLink="true">https://www.marcinkliks.plhttps://www.marcinkliks.pl/programming/2021/01/19/swift-services-with-mongo-on-raspberry-pi-400/</guid>
      </item>
    
      <item>
        <title>Arctic vault - say hello!</title>
        <description>&lt;p&gt;If you read this, Github probably already did “it”.&lt;/p&gt;

&lt;p&gt;Github is going to archive all, world-wide public github repositories in a secret “Vault” located somewhere in Arctic mountain. Today. Including this page.&lt;/p&gt;

&lt;p&gt;The process begins in 2 hours, on 2/02/2020. &lt;a href=&quot;https://archiveprogram.github.com&quot;&gt;More info&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It seems, this blog is going to be archived to, and will be stored underground for about 1000 years. 
Well, it’s great oportunity to write, something. Something that lasts.&lt;/p&gt;

&lt;h2 id=&quot;what-is-it-like-to-live-in-2020&quot;&gt;What is it like to live in 2020?&lt;/h2&gt;

&lt;p&gt;I think, I’m grateful to be living in 2020.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Living in 2020 is understanding much more than ever, but living in social “bubbles”.&lt;/li&gt;
  &lt;li&gt;Living in 2020 is to buy everything you’d really imagine, having free shipping worlwide.&lt;/li&gt;
  &lt;li&gt;Living in 2020 is having private chauffeur available everywhere (we used to call it “Uber”).&lt;/li&gt;
  &lt;li&gt;Living in 2020 is to have supercomputer with 20 sensors, just in your pocket(smartphone).&lt;/li&gt;
  &lt;li&gt;Sadly, living in 2020 is to forget about God, and avoiding taking responsibility.&lt;/li&gt;
  &lt;li&gt;Sadly, living in 2020 is giving privacy for stupid pictures.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;being-grateful&quot;&gt;Being grateful&lt;/h2&gt;

&lt;p&gt;I’d like to thank all previous ~ 10,000 generations of people, including my nearest family, to work on foundation for everything we have today.&lt;/p&gt;

&lt;p&gt;I’m grateful for:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;my wonderful family, wife, doughter&lt;/li&gt;
  &lt;li&gt;oportunity to live in a world of programming, and fantastic work experience&lt;/li&gt;
  &lt;li&gt;piece of mind, piece of soul&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See you in 1000 years!&lt;/p&gt;

</description>
        <pubDate>Sun, 02 Feb 2020 00:00:00 +0000</pubDate>
        <link>https://www.marcinkliks.plhttps://www.marcinkliks.pl/2020/02/02/arctic/</link>
        <guid isPermaLink="true">https://www.marcinkliks.plhttps://www.marcinkliks.pl/2020/02/02/arctic/</guid>
      </item>
    
      <item>
        <title>Anet A8 3D Printer - 1 year later</title>
        <description>&lt;h2 id=&quot;a-year-with-anet-a8-3d-printer&quot;&gt;A year with Anet A8 3D Printer&lt;/h2&gt;

&lt;p&gt;Today, you can buy 3dprinter just under 200$ (Anet A8 self assembly required in this case). This is price territory of generic “desktop printers”. I’ve used my 3D printer &lt;strong&gt;more&lt;/strong&gt; often than desktop printer! After 1 year, I’m really happy with the purchase, and don’t regret it. Some parts such as: filament heads, and bearings needed to be replaced, but it was easy to do, and the parts are ready available.&lt;/p&gt;

&lt;h2 id=&quot;how-i-used-my-anet-a8-printer-in-a-1-year&quot;&gt;How I used my Anet A8 printer in a 1 year&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_6584-kopia.jpg&quot; alt=&quot;IMG_6584-kopia.jpg&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;dishwasher&quot;&gt;Dishwasher&lt;/h3&gt;

&lt;p&gt;My IKEA dishwasher door broke one day. The problem was with one small plastic part, which is quite often material used by IKEA furniture. I decided to give my 3D printer a try.  Tinkercad was chosen as the simplest app to quickly prototype part. I had no previous 3D-modeling experience whatsoever.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_8047-kopia.jpg&quot; alt=&quot;IMG_8047-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_8039-kopia.jpg&quot; alt=&quot;IMG_8039-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_7933-kopia.jpg&quot; alt=&quot;IMG_7933-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_1895-kopia.jpg&quot; alt=&quot;IMG_1895-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_1890-kopia.jpg&quot; alt=&quot;IMG_1890-kopia.jpg&quot; /&gt;&lt;/p&gt;

&lt;p&gt;It took some time to measure the part but it was really quick and easy to print it out. I took 3 tries to improve it further to make it slightly bolder than original to not broke anymore.&lt;/p&gt;

&lt;h2 id=&quot;lifehacks&quot;&gt;Lifehacks&lt;/h2&gt;

&lt;p&gt;Small life hacks here and there. Bathroom improvements.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/54663018022__ACE20FC8-1EA1-4131-9089-979FF5A8F279-kopia.jpg&quot; alt=&quot;54663018022__ACE20FC8-1EA1-4131-9089-979FF5A8F279-kopia.jpg&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;boxes&quot;&gt;Boxes&lt;/h3&gt;

&lt;p&gt;I’ve used wood-based filament, quite expensive but worth it: https://3dreaktor.pl/filament-WOOD/Fiberlogy-FiberWood-750g-175&lt;/p&gt;

&lt;p&gt;I had to increase printing head diameter to 0.5, to not constanly get stuck. 
But it made the difference in overall outlook of the product! Looks like real wood!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_1512-kopia.jpg&quot; alt=&quot;IMG_1512-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_1816-kopia.jpg&quot; alt=&quot;IMG_1816-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_1828-kopia.jpg&quot; alt=&quot;IMG_1828-kopia.jpg&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;figures&quot;&gt;Figures&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_3046-kopia.jpg&quot; alt=&quot;IMG_3046-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_1869-kopia.jpg&quot; alt=&quot;IMG_1869-kopia.jpg&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;toys-for-my-daughter&quot;&gt;Toys for my daughter&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_3284-kopia.jpg&quot; alt=&quot;IMG_3284-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_1202-kopia.jpg&quot; alt=&quot;IMG_1202-kopia.jpg&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;printer-self-improvements--&quot;&gt;Printer self-improvements :-)&lt;/h2&gt;

&lt;h3 id=&quot;power-supply-cover&quot;&gt;Power supply cover&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_3885-kopia.jpg&quot; alt=&quot;IMG_3885-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_3889-kopia.jpg&quot; alt=&quot;IMG_3889-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_3895-kopia.jpg&quot; alt=&quot;IMG_3895-kopia.jpg&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;tools&quot;&gt;Tools&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_8272-kopia.jpg&quot; alt=&quot;IMG_8272-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_7966-kopia.jpeg&quot; alt=&quot;IMG_7966-kopia.jpeg&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;iphone-cover&quot;&gt;Iphone Cover&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_0257-kopia.jpg&quot; alt=&quot;IMG_0257-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_0244-kopia.jpg&quot; alt=&quot;IMG_0244-kopia.jpg&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;iphone-stand&quot;&gt;IPhone stand&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_1258-kopia.jpg&quot; alt=&quot;IMG_1258-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_1257-kopia.jpg&quot; alt=&quot;IMG_1257-kopia.jpg&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;toy-basketball&quot;&gt;Toy basketball&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_1369-kopia.jpg&quot; alt=&quot;IMG_1369-kopia.jpg&quot; /&gt;
&lt;img src=&quot;https://www.marcinkliks.pl/assets/IMG_1404-kopia.jpg&quot; alt=&quot;IMG_1404-kopia.jpg&quot; /&gt;&lt;/p&gt;
</description>
        <pubDate>Wed, 19 Dec 2018 00:00:00 +0000</pubDate>
        <link>https://www.marcinkliks.plhttps://www.marcinkliks.pl/2018/12/19/anet-a8-3d-printer/</link>
        <guid isPermaLink="true">https://www.marcinkliks.plhttps://www.marcinkliks.pl/2018/12/19/anet-a8-3d-printer/</guid>
      </item>
    
      <item>
        <title>Książki warte przeczytania</title>
        <description>&lt;style type=&quot;text/css&quot;&gt;
  .small-image {
    max-width: 100px; float: left; margin-left: 0px; margin-right: 20px; margin-bottom: 40px; 
  }
  
&lt;/style&gt;

&lt;h1 id=&quot;książki-warte-przeczytania--2018&quot;&gt;Książki warte przeczytania / 2018&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/books.jpeg&quot; alt=&quot;./assets/books.jpeg&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;12-rules-of-life--12-życiowych-zasad----j-peterson&quot;&gt;12 Rules of Life / 12 życiowych zasad -  J. Peterson&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/12rules.jpg&quot; alt=&quot;12rules.jpg&quot; class=&quot;small-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Dlaczego strukturami społecznymi ludzi rządzą te same zasady co społeczności … krabów?
W jaki sposób silny kręgosłup moralny pozwala odnieść sukces? 
Książka znakomitego profesora psychologii o 12 pięknych zasadach, które nie ułatwiają, ale na pewno nadają nowy sens życiu.&lt;/p&gt;
&lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;

&lt;h2 id=&quot;głaskologia&quot;&gt;Głaskologia&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/glaskologia.jpg&quot; alt=&quot;glaskologia.jpg&quot; class=&quot;small-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Książka - zaskakująco twarda, pomimo “miękkiego tytułu”. Każdy powinien ją przeczytać, ponieważ 65% pracowników nigdy nie usłyszało od swojego pracodawcy pochwały na temat wykonywania obowiązków zawodowych. Powoduje to spadek motywacji. W Polsce ten wskaźnik pewnie jest jeszcze wyższy. Gdyby każdy menedżer przeczytał tą książkę, pracowalibyśmy o połowę lepiej.&lt;/p&gt;

&lt;h2 id=&quot;siła-nawyku---charles-duhigg&quot;&gt;Siła nawyku - Charles Duhigg&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/sila-nawyku.jpg&quot; alt=&quot;sila-nawyku.jpg&quot; class=&quot;small-image&quot; /&gt;
Nawyki nami rządzą - jak sprawić by działałby na naszą korzyść? 
Kilka prostych tricków - “ustaw buty koło łóżka”, które skutecznie walczą z alter-ego.
Pozycja dość znana, ale polecam do niej wracać co pewien czas.&lt;/p&gt;

&lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;

&lt;h2 id=&quot;homo-deus---yuval-noah-harari&quot;&gt;Homo deus - Yuval Noah Harari&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/homo-deus.jpg&quot; alt=&quot;homo-deus.jpg&quot; class=&quot;small-image&quot; /&gt;
Futurystyczna acz ponura wizja przyszłości w której nie ma chorób i błędów, nie jednostka podejmuje decyzje, tylko “system” - co da doskonałą przyszłość nadludzi. Książka polecana przez Billa Gatesa, Zuckerberga ;-)&lt;/p&gt;
&lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;

&lt;h2 id=&quot;dlaczego-zalando---hagen-seidel&quot;&gt;Dlaczego Zalando? - Hagen Seidel&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/dlaczego-zalando.jpg&quot; alt=&quot;dlaczego-zalando.jpg&quot; class=&quot;small-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Ciekawa historia startupu, który nie boi się ekspansji i planowania długoterminowego zamiast szybkiego zarobku.&lt;/p&gt;
&lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;

&lt;h2 id=&quot;labirynty-scruma---jacek-wieczorek&quot;&gt;Labirynty Scruma - Jacek Wieczorek&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/labirynty-scruma.jpg&quot; alt=&quot;labirynty-scruma.jpg&quot; class=&quot;small-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Scruma znamy wszyscy - co można jeszcze wymyślić? Ano, jeśli uważasz, że twój Scrum (daily, retro, planning) działa dobrze, to przeczytaj książkę. Odczarujesz złudzenia i samego siebie. Książka bardziej skuteczna niż katechizm przed spowiedzią!&lt;/p&gt;
&lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;

&lt;h2 id=&quot;the-pyramid-principle---barbara-minto&quot;&gt;The pyramid principle - Barbara Minto&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/pyramid-principle.jpg&quot; alt=&quot;pyramid-principle.jpg&quot; class=&quot;small-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Jak precyzyjnie niczym laser wyrażać myśli na piśmie, aby docierać do odbiorców. Jeśli szykujesz pitch do CEO - nie możesz tej pozycji pominąć.&lt;/p&gt;
&lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;

&lt;h2 id=&quot;coders-at-work---peter-seibel&quot;&gt;Coders at work - Peter Seibel&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://www.marcinkliks.pl/assets/images.jpeg&quot; alt=&quot;images.jpeg&quot; class=&quot;small-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Okazuje się, że programista programiście nierówny. Nawet Ci najlepsi programiści programują zupełnie inaczej. Brendan Eich lubi programować w stylu eksploracyjnym, a twórca Linuksowego XSavera - pisze w niskopoziomowym C ciurkiem, od góry do dołu. Obaj są legandami. Wspaniałe wywiady z wieloma znakomitymi programistami, które inspirują i dodają nadzieji, że każdy może odnieść sukces.&lt;/p&gt;
</description>
        <pubDate>Mon, 17 Dec 2018 00:00:00 +0000</pubDate>
        <link>https://www.marcinkliks.plhttps://www.marcinkliks.pl/2018/12/17/read-books/</link>
        <guid isPermaLink="true">https://www.marcinkliks.plhttps://www.marcinkliks.pl/2018/12/17/read-books/</guid>
      </item>
    
      <item>
        <title>Swift 4 Cookbook - Linux &amp; MacOS, part 1</title>
        <description>&lt;p&gt;Swift is powerful, fast and safe programming language. From version 2 it’s open source, and officialy supported on Linux. Its native performance, type safety, interactive (REPL) playground and scripting posibility, is a joy to use.&lt;/p&gt;

&lt;p&gt;The main goal for Swift on Linux is to be compatible with Swift on macOS/ios/watchos, and there is an official Apple documentation for &lt;a href=&quot;https://developer.apple.com/documentation/foundation&quot;&gt;Foundation&lt;/a&gt;. Howerever, this quick cheat-sheet gives you quick glance what this language+standard library is capable of.&lt;/p&gt;

&lt;h3 id=&quot;setup&quot;&gt;Setup&lt;/h3&gt;

&lt;p&gt;There are 2 ways to install Swift 4 for server side applications:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Standard installation:&lt;/p&gt;

    &lt;p&gt;Download Swift 4.0 from: &lt;a href=&quot;https://swift.org/download/&quot;&gt;swift.org&lt;/a&gt; for your Ubuntu distribution, following &lt;a href=&quot;https://swift.org/download/#using-downloads&quot;&gt;manual&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;You can also use Docker instead, (it runs on all distros)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;docker run &lt;span class=&quot;nt&quot;&gt;--rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--privileged&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-ti&lt;/span&gt; swiftdocker/swift:latest /usr/bin/swift &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; /usr/lib/swift/clang/include/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;whats-so-special-about-swift-4-&quot;&gt;What’s so special about Swift 4 ?&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;expressive, high level language with generics&lt;/li&gt;
  &lt;li&gt;safe by design(type safety, &lt;a href=&quot;https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/OptionalChaining.html&quot;&gt;optionals&lt;/a&gt;, &lt;a href=&quot;https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/ErrorHandling.html#//apple_ref/doc/uid/TP40014097-CH42-ID508&quot;&gt;error handling&lt;/a&gt;, undefined behavior detection)&lt;/li&gt;
  &lt;li&gt;native code compilation with &lt;a href=&quot;http://www.marcinkliks.pl/2015/02/22/swift-vs-others/&quot;&gt;high&lt;/a&gt; &lt;a href=&quot;http://benchmarksgame.alioth.debian.org/u64q/swift.html&quot;&gt;runtime performance&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;seamless, zero cost C language interoperability without &lt;a href=&quot;https://golang.org/cmd/cgo/&quot;&gt;ha&lt;/a&gt;&lt;a href=&quot;http://cffi.readthedocs.io/en/latest/overview.html#purely-for-performance-api-level-out-of-line&quot;&gt;ck&lt;/a&gt;&lt;a href=&quot;https://stackoverflow.com/questions/7699020/what-makes-jni-calls-slow&quot;&gt;s&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;efficient memory management &lt;a href=&quot;https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html&quot;&gt;arc&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift/blob/master/docs/OwnershipManifesto.md&quot;&gt;ownership&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;functional paradigms &lt;a href=&quot;https://www.raywenderlich.com/114456/introduction-functional-programming-swift&quot;&gt;included&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;how-to-use-this-tutorial&quot;&gt;How to use this tutorial&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Make sure you read &lt;a href=&quot;https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html#//apple_ref/doc/uid/TP40014097-CH2-ID1&quot;&gt;this great intro to Swift 4&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;This tutorial is about using Foundation API’s, it’s not a language guide.&lt;/li&gt;
  &lt;li&gt;This tutorial doesn’t cover writing web app in swift, though - it’s coming soon!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To play with examples in this tutorial, you can use swift &lt;a href=&quot;https://pl.wikipedia.org/wiki/REPL&quot;&gt;REPL&lt;/a&gt;. You also compile the code with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swiftc [file.swift]&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;To run REPL:
    &lt;ol&gt;
      &lt;li&gt;On Mac - just type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Linux - type: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift -I /usr/lib/swift/clang/include/&lt;/code&gt;&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;You can also use XCode playground - fire up Xcode, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File -&amp;gt; New -&amp;gt; Playground&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href=&quot;https://swift.org/getting-started/#using-the-repl&quot;&gt;More capabilities of Swift REPL here&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;printing-text&quot;&gt;Printing text&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello world!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Hello&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;world&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
Hello&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;world!
&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 	
&lt;span class=&quot;kt&quot;&gt;Hello&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;world&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;one&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;two&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;three&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;one&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;two&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;three&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;one&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;two&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;three&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;separator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;one&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;two&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;three&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;one&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;two&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;three&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;separator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;one&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;two&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;three&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;and&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;printing-to-stderr&quot;&gt;Printing to stderr&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;FileHandle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;standardError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;printing-to-stdin&quot;&gt;Printing to stdin&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;FileHandle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;standardError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;FileHandle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;standardInput&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;FileHandle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;standardOutput&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;executing-shell-commands&quot;&gt;Executing shell commands&lt;/h3&gt;

&lt;h4 id=&quot;run-process-with-arguments-and-wait-for-completion&quot;&gt;Run process with arguments and wait for completion&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;	
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;launchPath&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/usr/bin/wc&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arguments&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;-l&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/etc/passwd&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;launch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;waitUntilExit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;suspend-and-resume-process-in-background&quot;&gt;Suspend and resume process in background&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;launchPath&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/bin/cat&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arguments&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/var/log/system.log&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;launch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;suspend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;resume&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;terminate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;monitor-process-running-in-background&quot;&gt;Monitor process running in background&lt;/h4&gt;

&lt;p&gt;This example prints system logs for 10 seconds, and then exits.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;launchPath&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/usr/bin/tail&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arguments&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;-f&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/var/log/system.log&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;launch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;elapsedSeconds&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isRunning&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;elapsedSeconds&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Running&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;elapsedSeconds&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;redirect-stdin--stdout&quot;&gt;Redirect stdin / stdout&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;launchPath&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/bin/cat&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arguments&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;-&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;pp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;standardInput&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pp&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;launch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fileHandleForWriting&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;test&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\u{4}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;waitUntilExit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;networking&quot;&gt;Networking&lt;/h3&gt;

&lt;h4 id=&quot;download-http-document&quot;&gt;Download HTTP document&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;downloadURL&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://www.google.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;contents&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;contentsOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;downloadURL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;encoding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;download-http-document-and-autodetectsniff-encoding&quot;&gt;Download HTTP document and autodetect(sniff) encoding&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;     
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Encoding&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Encoding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ascii&lt;/span&gt; 
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;https://www.ecma-inational.org/publications/files/ECMA-ST/Ecma-128.pdf&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;contentsOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
            &lt;span class=&quot;nv&quot;&gt;usedEncoding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;download-binary-file&quot;&gt;Download binary file&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;fileContents&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;contentsOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://filea.x&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;:  It uses RAM memory to store entire file in it, it can be handy for smaller files / quick scripts.&lt;/p&gt;

&lt;h4 id=&quot;download-in-partschunks&quot;&gt;Download in parts(chunks)&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Dispatch&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URLSessionConfiguration&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URLSession&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;configuration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;downloadTask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://google.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;resume&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;filesystem-operations&quot;&gt;Filesystem operations&lt;/h3&gt;

&lt;h4 id=&quot;read-binary-file&quot;&gt;Read binary file&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;binaryData&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;contentsOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;fileURLWithPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/tmp/a.x&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;read-text-file&quot;&gt;Read text file&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;textFile&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;contentsOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;fileURLWithPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/etc/passwd&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;write-to-text-file&quot;&gt;Write to text file&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;s&quot;&gt;&quot;hello world&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;toFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/etc/xxx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;atomically&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;encoding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;write-to-stderr&quot;&gt;Write to stderr&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;FileHandle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;standardError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;write-to-stdin&quot;&gt;Write to stdin&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;FileHandle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;standardError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;FileHandle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;standardInput&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;FileHandle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;standardOutput&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;read-data-in-chunks&quot;&gt;Read data in chunks&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FileHandle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;forReadingAtPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/etc/passwd&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;readData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ofLength&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// all: &lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;readDataToEndOfFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;check-if-file-is-readable&quot;&gt;Check if file is readable&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FileManager&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;isReadableFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;atPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/etc/fstab&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;remove-file&quot;&gt;Remove file&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;FileManager&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;removeItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;fileURLWithPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/tmp/x&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;copy-file&quot;&gt;Copy file&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;FileManager&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copyItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;atPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;from.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;toPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;to.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;copy-directory&quot;&gt;Copy directory&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;FileManager&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;copyItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;atPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/etc/&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;toPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/etc.backup&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;list-directories&quot;&gt;List directories&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Shallow list without folders&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FileManager&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;contentsOfDirectory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;atPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// deep list&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;  &lt;span class=&quot;kt&quot;&gt;FileManager&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;enumerator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;atPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/etc&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;  
  &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;recursively-list-files&quot;&gt;Recursively list files&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;FileManager&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subpathsOfDirectory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;atPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/root/&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;create-directory-with-permissions&quot;&gt;Create directory with permissions&lt;/h4&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;permission&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mo&quot;&gt;0o700&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSNumber&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;FileManager&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;createDirectory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;atPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/tmp/my/brand/new/directory&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
  &lt;span class=&quot;nv&quot;&gt;withIntermediateDirectories&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
  &lt;span class=&quot;nv&quot;&gt;attributes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;posixPermissions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;permission&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;coroutines--threads-&quot;&gt;Coroutines / threads /&lt;/h2&gt;

&lt;p&gt;Swift comes with LibDispatch which uses threads and queues for dealing with asynchronous tasks.&lt;/p&gt;

&lt;h3 id=&quot;concurrent-requests-example&quot;&gt;Concurrent requests example&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;        
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Dispatch&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URLSessionConfiguration&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URLSession&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;configuration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;downloadTask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://www.wp.pl&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;resume&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Started&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;dispatchMain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;scripting-with-swift&quot;&gt;Scripting with Swift&lt;/h2&gt;

&lt;p&gt;You can use Swift as a interpreted language, too with pure text files!&lt;/p&gt;

&lt;p&gt;Just create swift file:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;n&quot;&gt;touch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hello&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;chmod&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hello&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With contents:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    
&lt;span class=&quot;cp&quot;&gt;#!/usr/bin/xcrun swift&lt;/span&gt;
  
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, what&apos;s your name?&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;readLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;strippingNewline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Run it with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/tmp/hello&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Voila! You can execute &lt;em&gt;any&lt;/em&gt; of examples using this technique.&lt;/p&gt;
</description>
        <pubDate>Wed, 11 Oct 2017 00:00:00 +0000</pubDate>
        <link>https://www.marcinkliks.plhttps://www.marcinkliks.pl/2017/10/11/swift4-server-foundation-cookbook/</link>
        <guid isPermaLink="true">https://www.marcinkliks.plhttps://www.marcinkliks.pl/2017/10/11/swift4-server-foundation-cookbook/</guid>
      </item>
    
      <item>
        <title>Swift 3 on Linux tutorial - Zewo - part 2</title>
        <description>&lt;h1 id=&quot;swift-3-linux-tutorial---part-2&quot;&gt;Swift 3 Linux tutorial - part 2&lt;/h1&gt;

&lt;p&gt;In this tutorial we will continue exploring more advanced parts of Zewo framework, including:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;concurrency&lt;/li&gt;
  &lt;li&gt;JSON handling&lt;/li&gt;
  &lt;li&gt;communication via channels&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;coroutines&quot;&gt;Coroutines&lt;/h2&gt;

&lt;p&gt;Unlike Go, Swift 3 does not come with coroutines out of the box, but uses separate library called &lt;a href=&quot;https://github.com/VeniceX&quot;&gt;VeniceX&lt;/a&gt;. Worry no, the usage is quite similar to go, and performance is great, scaling up to milions coroutines on a single host.&lt;/p&gt;

&lt;p&gt;Zewo follows CSP model, similar to Golang &lt;a href=&quot;https://en.wikipedia.org/wiki/Communicating_sequential_processes&quot;&gt;read more model&lt;/a&gt; coroutines incorporting wonderful &lt;a href=&quot;http://libmill.org&quot;&gt;libmill&lt;/a&gt; C library.&lt;/p&gt;

&lt;h2 id=&quot;example-coroutines&quot;&gt;Example coroutines&lt;/h2&gt;

&lt;p&gt;This code runs in the “background” as a lightweight coroutine. Unlike threads, you can run literally milions of these on the modern hardware, it’s so performant.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Venice&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;co&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Spawned &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; coroutine! I&apos;m so asynchronous!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To comunicate with the coroutine, we use channels, for sending / recieving values of specific type(for example Int):&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Venice&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;channel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Channel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;co&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;nf&quot;&gt;nap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Waiting for the result...&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Got &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; !&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Run it and:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Waiting for the result...
Got Optional(1) !
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Keep in mind, that recieving a value from the channel is a &lt;em&gt;blocking operation&lt;/em&gt;. To check buffer for presence of data without blocking,
 you can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;select&lt;/code&gt; function described later on.&lt;/p&gt;

&lt;h2 id=&quot;diy---worker&quot;&gt;DIY - worker&lt;/h2&gt;

&lt;p&gt;In the first part of the tutorial, we’ve built synchronous http service which immediately returned a value. In this tutorial, we will try to make prime numbers web-service! Computing of prime numbers takes a lot time, and we don’t want to have API HTTP timeouts. That’s why we cannot do it synchronusly. We will defer computation tasks to the background instead.&lt;/p&gt;

&lt;p&gt;How to do it? Do we need some worker solution, similar to Python RQ, Celery, threads, Redis or something? The answer is - not at all! Zewo with Swift does the trick without any other components!&lt;/p&gt;

&lt;p&gt;Let’s begin with the endpoints:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/task/new&lt;/code&gt; endpoint will schedule long-running computation in the background. The only thing returned synchronusly is task id as a JSON. We handle POST requests here, thus “creating” task resource.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/task/[uid]&lt;/code&gt; - this endpoint will be used by the clients polling the result.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;the-code&quot;&gt;The code&lt;/h3&gt;

&lt;p&gt;File main.swift:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Axis&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTPServer&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;messages&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Channel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[:]&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;BasicRouter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;route&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;route&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/task/new&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; 
        &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;becomeBuffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;deadline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seconds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;content&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;JSONMapParser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;value&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;badRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Missing value&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;intValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;badRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; is not a number&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;taskId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UUID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;description&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;channel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Channel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;messages&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;taskId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;computedPrime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nextPrime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;intValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;computedPrime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Content-type&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try!&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;JSONMapSerializer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;serialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;taskId&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;taskId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)])&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;route&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/task/:taskid&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;taskid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pathParameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;taskid&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;internalServerError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;channel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;messages&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;taskid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;nv&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;notFound&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Routine not found&quot;&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Result: &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;messages&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;taskid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;otherwise&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Still computing.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;0.0.0.0&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8080&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;reusePort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;responder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Create file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;computation.swift&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Venice&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;/// Returns true if number is prime number, false otherwise&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isPrime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt; 
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;prime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;yield&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;prime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prime&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;/// Returns the first next prime number greater than given number&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nextPrime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;previousPrime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;currentCandidate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;previousPrime&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;found&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;found&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	    &lt;span class=&quot;n&quot;&gt;currentCandidate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
	    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isPrime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentCandidate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	        &lt;span class=&quot;n&quot;&gt;found&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;
	    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;currentCandidate&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Both files(main.swift, computation.swift) share common namespace, without a need for importing files each other.&lt;/p&gt;

&lt;p&gt;Now, compile the code and let’s try our computation.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; curl -XPOST  &quot;http://127.0.0.1:8080/task/new&quot; -d &apos;{&quot;value&quot;: &quot;198491329&quot;}&apos; -v

{&quot;taskId&quot;:&quot;7398EFF1-838A-495E-AB9C-AC7C5C73BE3&quot;}

&amp;gt; curl &quot;http://127.0.0.1:8080/task/7398EFF1-838A-495E-AB9C-AC7C5C73BE3&quot;

Still computing.

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[after a while]&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; curl &quot;http://127.0.0.1:8080/task/7398EFF1-838A-495E-AB9C-AC7C5C73BE3&quot;
Result: 198491369⏎                      
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;explanation&quot;&gt;Explanation&lt;/h2&gt;

&lt;p&gt;The essence of our program is the usage of this coroutine:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;n&quot;&gt;co&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;computedPrime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nextPrime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;intValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;computedPrime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;nextPrime() function tries to behave nice, yielding the control of program to other coroutines, with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;yield&lt;/code&gt; function. 
Without it, it would preempt entire CPU time for one coroutine.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;using guards to unpack Optionals makes a program really readable&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;we used select() function which doesn’t wait until channel is filled up, so we can always answer HTTP requests as fast as possible&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;Congratulations! You completed part 2 of the tutorial. Don’t miss part 3 with Filesystem functions!&lt;/p&gt;

</description>
        <pubDate>Sun, 04 Sep 2016 00:00:00 +0000</pubDate>
        <link>https://www.marcinkliks.plhttps://www.marcinkliks.pl/2016/09/04/swift-on-linux-tutorial-zewo-part-2/</link>
        <guid isPermaLink="true">https://www.marcinkliks.plhttps://www.marcinkliks.pl/2016/09/04/swift-on-linux-tutorial-zewo-part-2/</guid>
      </item>
    
      <item>
        <title>Swift 3 on Linux tutorial - Zewo - part1</title>
        <description>&lt;h1 id=&quot;swift-3-linux-tutorial---part-1&quot;&gt;Swift 3 Linux tutorial - part 1&lt;/h1&gt;

&lt;p&gt;This tutorial shows how to write HTTP micro-service with Swift on Linux, thanks to the powerful Zewo framework.&lt;/p&gt;

&lt;h2 id=&quot;zewo&quot;&gt;Zewo&lt;/h2&gt;

&lt;p&gt;Zewo is an extremely modular set of server side libraries for server side development. It includes everything that’s needed to 
write full featured microservices in Swift, as well as commandline applications, including:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;HTTP and WebSocket servers&lt;/li&gt;
  &lt;li&gt;HTTP/S clients&lt;/li&gt;
  &lt;li&gt;couroutines (library “Venice” based on libmill)&lt;/li&gt;
  &lt;li&gt;database drivers, and ORM mappers&lt;/li&gt;
  &lt;li&gt;templating engine(“Mustache”)&lt;/li&gt;
  &lt;li&gt;Zeromq, Redis support&lt;/li&gt;
  &lt;li&gt;dozen of helper libraries&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Beware - it’s neither stable, nor have documentation yet, but the Sources are really readable. The components are slick, boundaries well defined, but the real deal is - it’s really easy to play with, customize, hack something working quickly. Thanks to Swift generics and protocols it’s a joy to use.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;spm---swift-package-manager&quot;&gt;SPM - swift package manager.&lt;/h2&gt;

&lt;p&gt;SPM is official package manager for Swift, which is really simple and useful.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;It follows convention over configuration, so there is no need to configure directory paths, or versioning schema. 
SemVer is the &lt;em&gt;only&lt;/em&gt; versioning schema you can use, so there is a strict standard around packages to follow. An example could be: 0.1.2 version. 0 is the major version, 1 - the minor, and patch level - 2.&lt;/li&gt;
  &lt;li&gt;Packages are stored in the generic GIT repositories, so no central - hub, or packages index is needed. Just use generic http+git url for package location.&lt;/li&gt;
  &lt;li&gt;SPM is the part of swift distribution itself, so there is no need to install anything.&lt;/li&gt;
  &lt;li&gt;Some extra features:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;can compile c code, integrates with apt-get and homebrew&lt;/li&gt;
  &lt;li&gt;manifests are written in pure-swift, and are easly readable&lt;/li&gt;
  &lt;li&gt;can generate xcode project file (snapshot version needs workaround, because it has a bug)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;using-spm&quot;&gt;Using SPM&lt;/h3&gt;

&lt;p&gt;Overview:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;OVERVIEW: Perform operations on Swift packages

USAGE: swift package [command] [options]

COMMANDS:
  init [--type &amp;lt;type&amp;gt;]                   Initialize a new package
                                         (type: library|executable|system-module)
  fetch                                  Fetch package dependencies
  update                                 Update package dependencies
  generate-xcodeproj [--output &amp;lt;path&amp;gt;]   Generates an Xcode project
  show-dependencies [--format &amp;lt;format&amp;gt;]  Print the resolved dependency graph
                                         (format: text|dot|json)
  dump-package [--input &amp;lt;path&amp;gt;]          Print parsed Package.swift as JSON

OPTIONS:
  -C, --chdir &amp;lt;path&amp;gt;        Change working directory before any other operation
  --color &amp;lt;mode&amp;gt;            Specify color mode (auto|always|never)
  -v, --verbose             Increase verbosity of informational output
  --version                 Print the Swift Package Manager version
  -Xcc &amp;lt;flag&amp;gt;               Pass flag through to all C compiler invocations
  -Xlinker &amp;lt;flag&amp;gt;           Pass flag through to all linker invocations
  -Xswiftc &amp;lt;flag&amp;gt;           Pass flag through to all Swift compiler invocations

NOTE: Use `swift build` to build packages, and `swift test` to test packages
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;start-with-hello-world-app&quot;&gt;Start with “Hello world” app!&lt;/h2&gt;

&lt;p&gt;Enough theory! Now, let’s build simple HTTP app.&lt;/p&gt;

&lt;p&gt;Create your project dir:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; mkdir hello &amp;amp;&amp;amp; cd hello
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, let’s generate barebones of the package:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; swift package init --type executable

Creating executable package: hello
Creating Package.swift
Creating .gitignore
Creating Sources/
Creating Sources/main.swift
Creating Tests/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you need generic library, choose “–type library”.&lt;/p&gt;

&lt;p&gt;Sources dir is currently opinionated name of all Sources directory. At the same time, when swift compiler detecs main.swift file, it assumes, executable is desired. Let’s see how main.swift file looks in practice:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; cat Sources/main.swift
print(&quot;Hello, world!&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now build the hello world app -&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; swift build 

Compile Swift Module &apos;hello&apos; (1 sources)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hurray! Hello world app is ready. Output executable, with debug symbols is located here:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; ls .build/debug
  
ModuleCache       hello.build       hello.swiftdoc    hello.swiftmodule 	helloTests.xctest
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Run it:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; ./.build/debug/hello
Hello, world!

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When ready to release, you can compile it without debugging symbols(faster, and smaller executable)&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; swift build --configuration release
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;writing-http-server&quot;&gt;Writing HTTP server&lt;/h2&gt;

&lt;p&gt;We will use Zewo framework, which contains over 50+ reusable, server-side components such as HTTP Server, JSON handling, storage-drivers (mysql, postgres), posix functions and &lt;a href=&quot;https://github.com/Zewo&quot;&gt;much much more&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; cat Packages.swift

import PackageDescription

let package = Package(
        name: &quot;hello&quot;
)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We will use various Zewo components in separation. But remember:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Try to use the same version (0.7 for example) or Zewo modules used in your project. Mixing different versions of Zewo components might create a dependency hell.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will create simple http server app, using JSON, routers, and creating some files.&lt;/p&gt;

&lt;p&gt;Now, update your Package.swift file with:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;PackageDescription&lt;/span&gt;
	
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Package&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;hello&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;nv&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Package&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;https://github.com/Zewo/Axis.git&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;majorVersion&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;minor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Package&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;https://github.com/Zewo/HTTPServer.git&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;majorVersion&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;minor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  
    &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now let’s write full-featured http app with routing. We use only 2 modules from Zewo - HTTPServer and Router. We expose parametrized endpoint &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/hello/[whatever]&lt;/code&gt;  to demonstrate full - featured url parameters handling, rendering http response, and returning http status codes.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTPServer&lt;/span&gt;
    
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;BasicRouter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;route&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;route&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/hello/:name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pathParameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;internalServerError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Nice to meet you, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;responder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Read more about &lt;a href=&quot;https://github.com/Zewo/Router&quot;&gt;routing&lt;/a&gt; and &lt;a href=&quot;https://github.com/VeniceX/HTTPServer/blob/master/Source/Server.swift&quot;&gt;HTTP server&lt;/a&gt; for more details.&lt;/p&gt;

&lt;p&gt;To build your packages, type: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift build&lt;/code&gt;. Dependencies are downloaded into Packages directory, as a full-featured git repositories, checked out for given git tags.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ls Packages/
C7-0.8.1                      HTTPParser-0.7.4              POSIX-0.5.1                   
CHTTPParser-0.5.0             HTTPSerializer-0.7.2          POSIXRegex-0.7.0              
CLibvenice-0.5.0              HTTPServer-0.7.2              PathParameterMiddleware-0.7.0 
CURIParser-0.5.0              IP-0.7.0                      RegexRouteMatcher-0.7.0       
File-0.7.5                    JSON-0.9.0                    Router-0.7.2                  
HTTP-0.7.2                    MediaType-0.8.0               S4-0.8.0     

String-0.7.3
StructuredData-0.8.3
TCP-0.7.4
TrieRouteMatcher-0.7.1
URI-0.8.1
Venice-0.7.2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Tip: You can modify any of the Packages/ repository, and push it back to the repo. It simplifies development a lot.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now point your browser to: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://localhost:8080/hello/zewo&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Hurray, it’s your first Swift HTTP app with routing and status codes handling.&lt;/p&gt;

&lt;h2 id=&quot;packaging&quot;&gt;Packaging&lt;/h2&gt;

&lt;p&gt;To share your app/library with others, just push the repo somewhere (to the github for example) and make ordinary git tag (following the SemVer schema).&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git tag 0.1.0
git push origin master
git push origin --tags
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can use this repo in other projects with simple:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.Package(url: &quot;https://github.com/user/hello.git&quot;, majorVersion: 0, minor: 1)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can specify also patchLevel as an argument, but it’s not recommended. When ommited, SPM always uses the  latest version, which is backward compatible.&lt;/p&gt;

&lt;h2 id=&quot;tuning-performance&quot;&gt;Tuning performance&lt;/h2&gt;

&lt;p&gt;Zewo framework is very performant, it uses the same concurrency strategy as GO language, using &lt;a href=&quot;https://en.wikipedia.org/wiki/Communicating_sequential_processes&quot;&gt;CSP&lt;/a&gt; coroutines.&lt;/p&gt;

&lt;p&gt;But you can find, that by default, it uses only one core. You can change it very easily with ‘reusePort’ parameter. It informs operating system to balance incoming socket requests, around many application instances. Remember only to run as many processes as needed, operating system will take care of the rest. You can run multiple http servers and/or run multiple processes of our app with configuration below:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;reusePort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8080&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;responder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;startInBackground&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;reusePort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8080&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;responder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;startInBackground&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;reusePort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8080&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;responder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;startInBackground&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;reusePort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8080&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;responder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;part-2&quot;&gt;Part 2&lt;/h2&gt;

&lt;p&gt;Don’t miss part 2 of tutorial!
We will use files manipulation, coroutines, operations on strings, and JSON.&lt;/p&gt;

</description>
        <pubDate>Mon, 01 Aug 2016 00:00:00 +0000</pubDate>
        <link>https://www.marcinkliks.plhttps://www.marcinkliks.pl/2016/08/01/swift-on-linux-tutorial-zewo/</link>
        <guid isPermaLink="true">https://www.marcinkliks.plhttps://www.marcinkliks.pl/2016/08/01/swift-on-linux-tutorial-zewo/</guid>
      </item>
    
      <item>
        <title>Swift vs Go vs Python battle</title>
        <description>&lt;h2 id=&quot;sweet-spot&quot;&gt;Sweet spot&lt;/h2&gt;

&lt;p&gt;Swift is the new programming language brought to you by Apple last year. It brings a refreshing air of novelty to the world of C, Python, Ruby, Rust and Go. The language is neither as beautiful as Python nor as fast as raw C, and the compilation speed cannot compete with Go. But the motivation behind Swift was to &lt;strong&gt;hit the sweet spot between C, Python and Go&lt;/strong&gt;. I strongly recommend reading the Swift Book &lt;a href=&quot;https://dl.dropboxusercontent.com/u/20996794/Swift%20Programming%20Language.pdf&quot;&gt;for example here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Apple prepared a thorough comparison of Swift and Python during the presentation. Much as they are similar, they are different by two yet essential characteristic features:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;both languages share the same language simplicity (for example, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;print&lt;/code&gt; is the keyword, OOP programming is optional)&lt;/li&gt;
  &lt;li&gt;both are great interactive interpreters( &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift&lt;/code&gt; vs &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swiftc&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;both can be used for scripting purposes (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#!/usr/bin/xcrun swift&lt;/code&gt;)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;but the performance differs between these languages and&lt;/li&gt;
  &lt;li&gt;Swift is not Open Source yet. Booo!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://cloud.githubusercontent.com/assets/552398/6324247/b2d2f7cc-bb37-11e4-91b8-dc7c33b5fef3.jpg&quot; alt=&quot;wcdxk-2&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Technology underlying Swift is based on LLVM, which handles all of the data structures, all compiling and optimization tasks on its own. LLVM is used also by PyPy, CLang, and other languages as well.&lt;/p&gt;

&lt;h2 id=&quot;is-it-really-as-fast-as-advertised&quot;&gt;Is it really as fast as advertised?&lt;/h2&gt;

&lt;p&gt;Last week Swift 1.2 was released so I decided to write a small benchmark game for:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Swift 1.2&lt;/li&gt;
  &lt;li&gt;Google’s Go 1.4.2&lt;/li&gt;
  &lt;li&gt;CPython 2.7.9&lt;/li&gt;
  &lt;li&gt;PyPy 2.5.0 - Python 2.7.8&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It was delightfull to simultanously write the code for 4 platforms in multisplit code editor window :-)
The alghorithm is fairly easy - creating 1M array and filling it with the incremented integers(64 bit ints). Then, creating another array, which consits of sum of every 2 elements from the first array. De facto it tests memory read / write access time. Then comes the next step: summing up every 100th element of the array - it should be very difficult to inline it properly, but who knows what Swift can do ? :-&amp;gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Note: I haven’t used the list comprehensions, not to favor any language. I will prepare this variant later.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://cloud.githubusercontent.com/assets/552398/6321021/40071842-baef-11e4-8a9e-c825642ca15c.png&quot; alt=&quot;first&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;code-differences&quot;&gt;Code differences&lt;/h2&gt;

&lt;h1 id=&quot;go&quot;&gt;Go&lt;/h1&gt;
&lt;p&gt;As you can see, the Go code is the longest one, but not much longer that the others. The source code is fairly short whatsoever. But that mandatory &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package()&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt; functions requirement is enforced. The weird part of Go is that Rob Pike decided not to make &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Print&lt;/code&gt; a keyword, but rather a library function. That’s why you should import &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fmt&lt;/code&gt; module. Appart from that, array functions are quite limited in comparison to Python and Swift. By default, &lt;em&gt;Go’s arrays are not resizable - as in C&lt;/em&gt;. Go language provides &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;append&lt;/code&gt; keyword for resizing arrays but the creator of Go couldn’t make up his mind how to implement single vectors. For example, you can use &lt;a href=&quot;http://golang.org/doc/effective_go.html#slices&quot;&gt;Slices pattern&lt;/a&gt;. WTF. After 30 years language designers should provide &lt;em&gt;one&lt;/em&gt; efficient generics implementation! But let’s move on. The way we declare the variable is bizzare - inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for&lt;/code&gt; loops you declare local variable without &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var&lt;/code&gt;. On the other hand, outside the loop you can still use two options interchangeably, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a := 1&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var a = 1&lt;/code&gt;. As you can see, it is pretty incoherent.
The good part is that the &lt;em&gt;compiler is fast&lt;/em&gt; - it’s the fastest compiler I’ve ever seen. Basically, it feels like an interpreter(but it’s not interactive). You can even run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;go run&lt;/code&gt; to hide the compiling step.&lt;/p&gt;

&lt;h1 id=&quot;swift&quot;&gt;Swift&lt;/h1&gt;
&lt;p&gt;Swift has type inference everywhere as well, hence the short syntax for type definitions.
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;append()&lt;/code&gt; is a method, not a keyword, just like in Python. The thing I love is that an optional OOP is not enforced on you. 
No package, no module, not even main function required. Furthermore, adding a header &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#!/usr/bin/xcrun swift&lt;/code&gt; followed by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chmod +x test.swift&lt;/code&gt; allows us to run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;./test.swift&lt;/code&gt; without compilation, just like in Python. &lt;em&gt;Wow&lt;/em&gt;. 
What else? &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Println&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;print&lt;/code&gt; are keywords. Your fingers will appreciate it for sure. I really like the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Range&lt;/code&gt; operators, which are lazy evaluated, and handle custom iterations steps in performant manner. Arrays work as expected and live interpreter has nifty editing capabilities, which is so much better than in Python (multiline handling). 
Editing capabilities are even better thanks to excellent type inference.&lt;/p&gt;

&lt;h1 id=&quot;python&quot;&gt;Python&lt;/h1&gt;
&lt;p&gt;I really love Python, but the lack of optional typing, type inference, and compilation is definitely lacking here. 
But here is where the language shines - the source code is the shortest of all and the cleanest of many. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var y: Array&amp;lt;Int&amp;gt; = []&lt;/code&gt; looks really iffy in comparison to the simple &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;y = []&lt;/code&gt; in Python. But in Swift we can emulate that writing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var y : [Int] = []&lt;/code&gt;, which is slighty better on the eyes. I really love the Python clarity here. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;xrange&lt;/code&gt; operator is here with a similar purpose as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Range&amp;lt;Int&amp;gt;&lt;/code&gt; in Swift.&lt;/p&gt;

&lt;h2 id=&quot;performance&quot;&gt;Performance&lt;/h2&gt;

&lt;p&gt;I’ve run loop 30 times. The results are mixed. 
CPython required 35x more time to finish the benchmark. Yes, it was 35x slower than Swift! On the other hand, Swift and Go come so close in results that it doesn’t matter - but in this particular microbenchmark Swift was 60% faster than Go. 
It trully amazed me how performant &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PyPy&lt;/code&gt; was - more than 5x faster than generic CPython implementation. Wow.&lt;/p&gt;

&lt;p&gt;The run times for all implementations:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://cloud.githubusercontent.com/assets/552398/6321023/5160183c-baef-11e4-9deb-48cdd9689155.png&quot; alt=&quot;second&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Let’s put the results together:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://cloud.githubusercontent.com/assets/552398/6321026/6045d224-baef-11e4-9c42-75a8a8b36ed2.png&quot; alt=&quot;third&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In this particular test - Python is 34x slower than Swift.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusions&quot;&gt;Conclusions&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;It’s just one simple benchmark, real life is another story, BUT:&lt;/li&gt;
  &lt;li&gt;Swift performance looks like a good fit not only for scripting, but high computing purposes too.&lt;/li&gt;
  &lt;li&gt;I liked its type inference.&lt;/li&gt;
  &lt;li&gt;PyPy’s performance is better than expected. It’s just 6x slower than Swift, but also 6x faster than generic CPython. If it is so fast perhaps we should ask why it’s not the default Python interpreter ;-)&lt;/li&gt;
  &lt;li&gt;Swift being faster than Go is quite surprising because Go is &lt;em&gt;3 years ahead of Swift in public development&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;I can’t wait to see ![Chris Lattner][http://nondot.org/sabre/] open-source Swift.&lt;/li&gt;
  &lt;li&gt;Swift is so young (6 months) that it still has some nasty bugs and rough edges. I will write about it another day&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Sun, 22 Feb 2015 00:00:00 +0000</pubDate>
        <link>https://www.marcinkliks.plhttps://www.marcinkliks.pl/2015/02/22/swift-vs-others/</link>
        <guid isPermaLink="true">https://www.marcinkliks.plhttps://www.marcinkliks.pl/2015/02/22/swift-vs-others/</guid>
      </item>
    
      <item>
        <title>Detalizm popłaca</title>
        <description>&lt;p&gt;A więc nazywasz siebie web-developerem, programistą, webmasterem a może nawet inżynierem? Zapytam więc Ciebie - jak działa web browser? Co dzieje się przy wpisaniu w przeglądarkę wp.pl i wciśnięciu entera. Proste pytanie, skomplikowane odpowiedzi.&lt;/p&gt;

&lt;p&gt;Zazwyczaj programiści odpowiadają na dwa odrębne sposoby:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Pierwszy typ programisty “To proste. Przeglądarka sprawdza DNS, łączy się z serwerem i wyświetla stronę w formacie HTML”&lt;/li&gt;
  &lt;li&gt;Drugi typ programisty “To dość skomplikowane. HTML czy XHTML? Nawiązanie samego połączenia sieciowego to sporo pracy pod maską, nie mówiąc o headerach. O jakim żądaniu mówimy GET, PUT, czy POST? Czy mam wyjaśnić też cache?. Do tego wchodzi jeszcze parser… jaka przeglądarka? Czy strona była wcześniej odwiedzona? Czy mam też omówić jak Javascript działa? Layout engine? Multiprocesowość? Czy w grę wchodzi Websockets ?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Często spotykam się z argumentem, że po to technologia została stworzona, abyśmy nie musieli zastanawiać się jak działa stack pod spodem. Po 11 latach zabawy z kodem uważam jednak, że:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Kariera każdego dobrego programisty przypomina proces obierania cebuli&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Pokrótce opiszę dlaczego.&lt;/p&gt;

&lt;p&gt;Wszyscy zaczynamy podobnie. Zaczyna się od fascynacji programowaniem, obiektowością, bazami danych, grafiką. Wszystko wydaje się takie przemyślane i spójne - myślisz sobie, “ten świat naprawdę jest zbudowany na ramionach olbrzymów”. Następnie fascynacja ładnie opisanymi i zrozumiałymi design patternami. Chcąc jednak robić więcej zaczynasz poznawać detale działania frameworków i zasad ich funkcjonowania. Niepokoi Cię myśl, że pod maską frameworków ktoś ukrywa coś ciekawego, użyte biblioteki ograniczają i krępują ruchy.&lt;/p&gt;

&lt;h2 id=&quot;virtual-machine--language-internals&quot;&gt;Virtual Machine / Language internals&lt;/h2&gt;

&lt;p&gt;Zaczynasz dostrzegać minusy języka programowania w którym byłeś zakochany. Niekompletne lambdy w Pythonie? Threading którego nikt nie chce używać, bo jest broken by design? Widzisz czego Twój język X mógłby nauczyć się od języka Y. Jednak trwasz dalej i wykorzystujesz idiomy dla przejrzystości i kruczki implementacji żeby wycisnąć jeszcze trochę wydajności po czym …&lt;/p&gt;

&lt;h2 id=&quot;db&quot;&gt;DB&lt;/h2&gt;

&lt;p&gt;Twoja firma, twój serwis szybko zyskuje popularność i przestaje się skalować. Co robisz? Zaczynasz pozbywać się abstrakcji. “Obierasz cebulę” z pierwszej napotkanej warstwy - zapewne warstwy ORM i skupiasz się na mikrooptymalizacjach zapytań SQL. Debugujesz outputy z ORM-ów, zaczynasz tune’ować bazę (in memory) a później wręcz optymalizować JOIN-y w zmaterializowanych widokach. W dyskusjach z kolegami przestajesz śmiać się(śmiałeś sie?) z gołych zapytań. Zmieniasz ENGINE’y bazy danych i dowiadujesz się dlaczego InnoDB nie potrafi defragmentować się online. Romans z PostresSQL też masz już zaliczony, miało być pięknie, a jednak limity zapisów dały &lt;a href=&quot;https://eng.uber.com/mysql-migration/&quot;&gt;w kość&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;middleware-and-cache&quot;&gt;Middleware and Cache&lt;/h2&gt;

&lt;p&gt;Porzucasz mikrooptymalizacje zapytań i obierasz kolejną warstwę - tym razem bierzesz pod lupę template’y i rezygnujesz z dynamicznych zapytań dla każdego request’a . Poznajesz Varnisha, ale żeby to osiągnąć obierasz kolejną warstwę - Middleware i zgłębiasz tajniki HTTP. Czujesz wiatr w skrzydłach - wreszcie wiesz co dzieje się pod spodem. Czujesz, że przez wiele lat miałeś na oczach opaskę i nie widziałeś “całej maszynerii” pod spodem.&lt;/p&gt;

&lt;h2 id=&quot;nosql&quot;&gt;NoSQL&lt;/h2&gt;

&lt;p&gt;Po przestudiowaniu co tak naprawdę robi JOIN w różnych engine’ach bazy danych rozumiesz, dlaczego wybierasz Cassandrę, Redisa i flat files w niektórych przypadkach.&lt;/p&gt;

&lt;h2 id=&quot;tcpip&quot;&gt;TCP/IP&lt;/h2&gt;

&lt;p&gt;Czujesz ukontentowanie aż do pewnego popołudnia traffic rośnie i osiągasz limity otwartych połączeń w kernelu linuksa, lub limit otwartych plików. Zdejmujesz kolejną warstwę abstrakcji i odkrywasz jak działa stos tcp/ip i &lt;a href=&quot;https://wiki.chipp.ch/twiki/pub/CmsTier3/NodeTypeFileServerHPDL380G7/ols2009-pages-169-1842.pdf&quot;&gt;interrupts coalescencing&lt;/a&gt;
WOW.&lt;/p&gt;

&lt;h2 id=&quot;frontend&quot;&gt;Frontend&lt;/h2&gt;

&lt;p&gt;Przeglądarka - końcówka naszej podróży. Wydaje się prosta - ma po prostu ma wyrenderować formularz, stronę.&lt;/p&gt;

&lt;p&gt;Czy wiesz, że przeglądarka Chrome składa się z 3 razy większej ilości linii kodu niż np Linux? (16 mln LOC,  gdy jądro Linuxa zawiera tylko blisko 5 mln) To naprawdę skomplikowane bestie. Jeśli kiedyś zastanawiałeś się, dlaczego scrollowanie przeglądarki “klatkuje” tzn że jeszcze nie wiesz jak tak naprawdę działa scrolling i jak &lt;a href=&quot;http://www.html5rocks.com/en/tutorials/speed/html5/&quot;&gt;zarządzać FPS w przeglądarce&lt;/a&gt;. Zaciekawiony oglądasz &lt;a href=&quot;https://www.youtube.com/watch?v=2xm2IjniJOk&quot;&gt;przeglądarkę internetową w ukrytej kamerze&lt;/a&gt; i cieszysz się że od dziś rozumiesz już trochę więcej.&lt;/p&gt;

&lt;h2 id=&quot;profit&quot;&gt;PROFIT&lt;/h2&gt;

&lt;p&gt;Najlepsi inżynierowie decydująć się na funkcje biblioteczne dokładnie wiedzą co “kupują”. Obecnie próg wejścia w pisanie aplikacji jest coraz niższy. Frameworków JavaScriptowych jest obecnie tak dużo(blisko 1500), że &lt;a href=&quot;http://jster.net&quot;&gt;powstała nawet strona do ich skatalogowania pod kątem filozoficznym - liberal vs opiniated&lt;/a&gt;. Jeśli jako frontendowiec nadal jesteś uzależniony od JQuery to może powinieneś przeczytać &lt;a href=&quot;http://youmightnotneedjquery.com&quot;&gt;to&lt;/a&gt; - just in case.&lt;/p&gt;

&lt;p&gt;Dlatego moja obserwacja jest następująca: aby rozwijać się jako programista należy drążyć detale do gołej blachy, nie dać się rozleniwiać istniejącym warstwom abstrakcji. Czy TCP/IP jest idealny? Dlaczego Google pracuje zatem na QUIC? Jeśli będziesz w stanie utrzymać swoją dziecięcą ciekawość świata, a przez to zaczniesz rozumieć abstrakcje których używać - to w efekcie - usmażysz &lt;a href=&quot;https://www.youtube.com/watch?v=khtLkmpM28I&amp;amp;spfreload=10&quot;&gt;Smaczny Software&lt;/a&gt;&lt;/p&gt;

</description>
        <pubDate>Fri, 02 Jan 2015 00:00:00 +0000</pubDate>
        <link>https://www.marcinkliks.plhttps://www.marcinkliks.pl/2015/01/02/settle/</link>
        <guid isPermaLink="true">https://www.marcinkliks.plhttps://www.marcinkliks.pl/2015/01/02/settle/</guid>
      </item>
    
  </channel>
</rss>
