<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ilya Shaisultanov on Medium]]></title>
        <description><![CDATA[Stories by Ilya Shaisultanov on Medium]]></description>
        <link>https://medium.com/@diversario?source=rss-aa942f4faa2e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*N2kkSo7XrKYUtw9Vb8wypg.png</url>
            <title>Stories by Ilya Shaisultanov on Medium</title>
            <link>https://medium.com/@diversario?source=rss-aa942f4faa2e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:23:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@diversario/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Interesting Graphs]]></title>
            <link>https://medium.com/@diversario/interesting-graphs-b1332ad79246?source=rss-aa942f4faa2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1332ad79246</guid>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Ilya Shaisultanov]]></dc:creator>
            <pubDate>Mon, 24 Jun 2019 03:24:10 GMT</pubDate>
            <atom:updated>2019-06-24T03:24:10.747Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been playing with <a href="https://prometheus.io/">Prometheus</a>, and the moment I set up a <a href="https://github.com/linuxacademy/content-kubernetes-prometheus-env/blob/master/grafana/dashboard/Kubernetes%20All%20Nodes.json">Grafana dashboard</a> I was immediately disappointed with flat, boring graphs from an empty cluster.</p><p>So, I figured — even though I don’t have real workloads — I can fake it! I used <a href="https://manpages.ubuntu.com/manpages/artful/man1/stress-ng.1.html">stress-ng</a> to exercise CPU, memory, IO, and network to simulate a busy Kubernetes cluster.</p><p>Goodbye flat lines:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXBksptFUUDlX-4lbnePrQ.png" /></figure><p>Hello intersting graphs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8QpzGO-5PGWrGstGM8rI7Q.png" /></figure><p>While not terribly useful IRL, it could make for a nicer screenshot in a presentation, or just spice up your learning experience.</p><p>Naturally, <a href="https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#resource-requests-and-limits-of-pod-and-container">CPU/memory limit</a> on the Kubernetes deployment should be set to avoid accidentally overwhelming your cluster.</p><p>The <a href="https://github.com/diversario/interesting-graphs">source</a> and the <a href="https://cloud.docker.com/u/diversario/repository/docker/diversario/interesting-graphs">Docker image</a> are both public, of course.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1332ad79246" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SpriteKit Physics Simulation]]></title>
            <link>https://medium.com/@diversario/what-i-learned-about-spritekit-part-i-c0a42dbe370f?source=rss-aa942f4faa2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0a42dbe370f</guid>
            <category><![CDATA[spritekit]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Ilya Shaisultanov]]></dc:creator>
            <pubDate>Sat, 14 May 2016 04:48:32 GMT</pubDate>
            <atom:updated>2016-05-14T20:47:03.285Z</atom:updated>
            <content:encoded><![CDATA[<p>I got into SpriteKit wanting to make a 2D game. A very simple game, in fact — you could play it with one finger 👆! I watched the WWDC SpriteKit demo and it seemed to suite my simple needs perfectly.</p><p>I’m sure pretty much any developer who made or tried to make a game is <em>very</em> familiar with the issues I ran into but for me — all this was new and unexpected.</p><h3>Physics</h3><p>Using physics simulation for collisions, contact detection and so on sounds like a great idea in theory and seems like a timesaver. That is, until you try to make things work the way you want.</p><h4>Collisions</h4><p>In my game, I decided to use collision detection to make player interact with obstacles in a realistic way. The idea was: player lands on an obstacle and in a collision handler I attach the player to that obstacle so it appears as if the player is sitting on the obstacle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*e0E0qnn0TWrCf0Ic2KHZyA.png" /></figure><p>It is such a simple want. Or so I thought, until I realized that this is never going to happen if I rely purely on collision detection.</p><p>SpriteKit physics engine (and many other game engines) performs collision detection at fixed intervals or steps. By default, SpriteKit performs collision detection once per frame. Say we have something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/192/1*aVj0eu7iMYlxR69uYlzP3w.png" /></figure><p>At low speeds, collision detection works well. However, if you have a fast moving physics body collisions aren’t registered as expected:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/192/1*NFx1AKpR9YasSsgWVKzGrg.png" /></figure><p>Between frames 2 and 3 the smaller body moved inside the larger one and at that point collision was detected. SpriteKit documentation informs us that</p><blockquote>If two bodies in a collision do not perform precise collision detection, and one passes completely through the other in a single frame, no collision is detected.</blockquote><p>I guess I should be using precise collision detection?.. Let’s try that!</p><h4>Precise Collision Detection</h4><p>Physics bodies have a property <a href="https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKPhysicsBody_Ref/index.html#//apple_ref/occ/instp/SKPhysicsBody/usesPreciseCollisionDetection">usePreciseCollisionDetection</a>:</p><blockquote>If this property is set to true on either body, the simulation performs a more precise and more expensive calculation to detect these collisions. This property should be set to true on small, fast moving bodies.</blockquote><p>This seemed to be exactly what I needed. I set it to true and ran the game. There was an improvement, but not a major one — player was getting stuck in obstacles here and there and collisions weren’t consistent.</p><p>After implementing a terrible hack I sort of got around that – it was good enough for me to continue onto other pieces of the game. But I got immediately blocked by a bizarre and unexplainable bug: when testing for <strong><em>contact</em></strong> (not collision) between player and a hazard player would get stuck in place for about a second <em>only while being attached to an obstacle (</em>it’s kind of hard to explain clearly without a video, which I don’t have).</p><p>In other words, if you sit on a moving platform and you hit a hazard — you’ll be stuck in place for a bit while the platform moves under you. I asked about this twice (<a href="https://forums.developer.apple.com/message/116547#116547">here</a> and <a href="https://forums.developer.apple.com/message/118420#118420">there</a>) on Apple developer forums but got no reply.</p><p>I resorted to another workaround which worked well but I couldn’t find an explanation for the bug I saw. About a week ago, I stumbled on a solution: disable precise collisions (so simple, why didn’t I disable them earlier? I don’t know). I’m fairly sure this is why bodies were getting stuck.</p><p>I found that if you have physics bodies connected via <a href="https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKPhysicsJoint_Ref/index.html#//apple_ref/swift/cl/c:objc(cs)SKPhysicsJoint">joint</a> and at least one of the bodies uses precise collision detection, then <strong><em>contact</em></strong> detection incurs a massive performance penalty. Curiously, if there is no joint this does not happen. This might be due to the fact that two bodies in a joint are treated as one and the larger, combined physics body then uses precise collision detection. I don’t know for sure.</p><p>In the end, I was able to achieve the desired behavior by using contact detection only, without precise collision detection, and implementing an algorithm that adjusts player position to appear in the correct spot once contact happens:</p><pre>onContact:<br>  get player position<br>  get platform position<br>  calculate distance between player and platform edge<br>  move player to platform edge</pre><p>As far as workarounds go, this wasn’t that hard and this actually works 🙌</p><h4>Physics and screen size</h4><p>In my game, player can jump. Jumping is done by applying an <a href="https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKPhysicsBody_Ref/#//apple_ref/occ/instm/SKPhysicsBody/applyImpulse:">impulse</a> to the player in appropriate direction. Physics, including gravity, takes care of the rest. I was testing the gameplay on iPhone 4 simulator – I figured, I would target the smallest device and the game would naturally scale to the rest of them.</p><p><strong>Wrong.</strong></p><p>The very first thing I noticed when running the same code on an iPhone 6 Plus is how player wasn’t able to jump as high or as far as I expected. After doing some research, I came across a host of similar issues reported by developers using SpriteKit. Turns out, forces don’t automatically adjust to all screen sizes.</p><p>SpriteKit physics operates in metric units. Physics bodies have properties like mass and density defined in kilograms and used in simulation. How does this relate to screen size? Somewhere behind the scenes metric units are translated into screen pixels – for example, when a body is moving as a result of applying an impulse to it.</p><p>An impulse <strong><em>I</em></strong> applied to a body of mass <strong><em>M</em></strong> will move the body by <strong><em>X</em></strong> pixels, on any screen. Performing this on iPhone 4 might move the body across the screen but only 2/3 of the way on an iPhone 6 Plus. So how can we make these forces consistent?</p><p>Apple dev forums have several threads like <a href="https://forums.developer.apple.com/message/79553#79553">this</a> and <a href="https://forums.developer.apple.com/message/89572#89572">this</a> where developers are sharing experience about making forces scale to screen. As far as I can tell, the current consensus is that 150px equal to 1m. In theory, this should allow you to find a multiplier that you can apply to all forces. In practice, I have this code to calculate an impulse multiplier that launches player across the screen in a parabolic curve:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5a5b8364df53fa3482b611eb93ec0a0/href">https://medium.com/media/c5a5b8364df53fa3482b611eb93ec0a0/href</a></iframe><p>This takes player from one side of the screen and lands it on the opposite side at (hopefully) the same <strong><em>x</em></strong> coordinate.</p><p>SCREEN_SCALE value is also used as a multiplier for player mass and world gravity. You <strong><em>must</em></strong> scale all forces to achieve consistency.</p><p>I can honestly say that this is one the most ridiculous thing I had to do to make something work that <em>should already be working</em>. I understand that always scaling physics to fit the screen is undesirable (i.e., if you want iPad version to display larger area) but I feel like this should be a setting, not a magic number that you have to dig up on the internet.</p><p>In its current state, physics in my game is used sparingly and a lot of things are faked. It is a great learning experience, though, and it applies to a lot (if not all) of games out there that use physics simulation:</p><h3>Megan Fox on Twitter</h3><p>Is it just me, or do a lot of folks who jump straight into the industry via Unity 3D never seem to grasp how much of AAA games are faked?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0a42dbe370f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple gesture recognition]]></title>
            <link>https://medium.com/@diversario/simple-gesture-recognition-9365555e3d3?source=rss-aa942f4faa2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9365555e3d3</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Ilya Shaisultanov]]></dc:creator>
            <pubDate>Sat, 14 May 2016 02:29:37 GMT</pubDate>
            <atom:updated>2016-05-14T02:30:44.523Z</atom:updated>
            <content:encoded><![CDATA[<p>You can easily add gesture recognition to your app either by dragging and dropping a recognizer onto your storyboard or entirely through code.</p><h3>Using storyboard</h3><p>Let’s say we have an image on our storyboard and we want to know when the user taps it. To accomplish this we need to add a tap gesture recognizer to our image view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*g6HJGzdC8aH0cCOunYOhSA.gif" /><figcaption>Add the recognizer</figcaption></figure><p>Make sure you drop it on the image itself, not on the view around it.</p><p>Almost done! Create an @IBAction for your new gesture recognizer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NZTWoTQTqTZCkUXwAM-STg.gif" /><figcaption>Create @IBAction</figcaption></figure><p>Now, the last and a <strong>very important</strong> part (which I keep forgetting to do myself): enable “User Interactions Enabled” on your image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/0*CYlAnT5u-EgNI4LP.png" /></figure><p>And we’re in business!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/0*896ySmor_G_XB-Yr.gif" /><figcaption>🎉</figcaption></figure><h3>Recognizers using only code</h3><p>Storyboards are great but sometimes you can’t achieve what you want with them (or you don’t like them).</p><p>Adding a gesture recognizer from code is fairly easy. Let’s do the same thing we did in the previous section.</p><p>Here’s all the code that you need to do that is here, commented.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8117d21bf6b589e4f82decb71ffb4f01/href">https://medium.com/media/8117d21bf6b589e4f82decb71ffb4f01/href</a></iframe><p>It works just like the previous example!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9365555e3d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Passing data between view controllers]]></title>
            <link>https://medium.com/@diversario/passing-data-between-view-controllers-7d118857051?source=rss-aa942f4faa2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d118857051</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[segue]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Ilya Shaisultanov]]></dc:creator>
            <pubDate>Sat, 23 Jan 2016 03:07:54 GMT</pubDate>
            <atom:updated>2016-01-23T03:07:54.916Z</atom:updated>
            <content:encoded><![CDATA[<p>The first time I tried to use a table view this problem came up almost immediately: how do I tell the detail view which cell I tapped on? As it turned out, there are several ways of doing this and it doesn’t matter if you’re using a table view or a simple button.</p><h4>Storyboard segues</h4><p>This is an easy and straightforward way of passing data around using hooks provided by the SDK.</p><p>We’ll be using two methods that UIViewController provides to work with segues: <strong>performSegueWithIdentifier:id:sender</strong> and <strong>prepareForSegue:segue:sender</strong>. But first, we need to create the segue itself (duh 😉):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*SXSXRiiXfc-4yrnPne3gMA.gif" /><figcaption>Creating a manual segue</figcaption></figure><p>All you need to do is drag from your source view controller into the destination one; make sure to start dragging from the yellow circle icon at in the header of the view controller. Select <strong>Show</strong> or <strong>Show Detail</strong> as segue type. The difference between the two is how they’re presented: <strong>Show</strong> will slide up from the bottom of the screen while <strong>Show Detail</strong> will slide from the right to left. You should see an arrow with a circle on it appear between the two view controllers.</p><p>Once the segue is created you need to give it an identifier. Select the segue on the storyboard and go to the Attributes Inspector - Identifier:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*UGye8789Lqu5PNr8jcPr8A.png" /><figcaption>Segue Identifier</figcaption></figure><p>We got our segue! Now, the fun part.</p><p>What we’re going to do is write some code to run just before the destination view controller becomes active and we’ll initialize a member on it with the data we want it to have. Of course, for this to work we need to have the appropriate member on the destination controller:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59cf0a305c07926743d95767d21e71a5/href">https://medium.com/media/59cf0a305c07926743d95767d21e71a5/href</a></iframe><p>Now, let’s go to our source view controller and set up the two methods we saw in the beginning. In this code we want to transition to the destination view controller when a user taps a cell in a table view:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05ca5270ff2a8f3b647286cadf0520fc/href">https://medium.com/media/05ca5270ff2a8f3b647286cadf0520fc/href</a></iframe><p>We call <strong>performSegueWithIdentifier</strong> in the <strong>tableView</strong> function because it is called when user taps a cell — this can, of course, be any other function — and within it we kick off our segue. The confusingly-named <strong>sender</strong> parameter is how we can pass data along with the segue. Before the segue actually runs the <strong>prepareForSegue</strong> method is called, giving us access to the destination controller (DestVC). All we have to do now is set the data on the controller!</p><h4>Instantiating a view controller by its identifier</h4><p>A variation of the first method, this one does not require a segue. The main idea is the same: set data on the destination view controller before it’s loaded. The difference is in the way get the controller.</p><p>First, we need to give our destination view controller a storyboard ID:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*XLtMX6S1vjQyWhEu4l5DGw.png" /><figcaption>Storyboard ID</figcaption></figure><p>Then, just like in the previous method, we add some code to the function from which we want to do the segue:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51927d1494982ea15942580e4b54a04b/href">https://medium.com/media/51927d1494982ea15942580e4b54a04b/href</a></iframe><p><strong>DestVC</strong> should, of course, have a member for us to set.</p><h4>Using a shared state</h4><p>This is probably my least favorite way of passing data around — globally-accessible mutable state seems like an accident waiting to happen. However, if for some reason the other two methods aren’t applicable to your case then go ahead and use a global object.</p><p>The idea is to have a class (or service) with a static member which stores the piece of data that needs to be passed around. The first view assigns a value to the member and the second view reads it.</p><p>The class to hold the data can look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8008fe01b76cf2b277646fa0bbaf1b6/href">https://medium.com/media/f8008fe01b76cf2b277646fa0bbaf1b6/href</a></iframe><p>Imagine how easy it is to screw this up.</p><p>Using this is easy as well — I will leave that for you to figure it out. Just be careful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d118857051" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automatic font size in UILabel]]></title>
            <link>https://medium.com/@diversario/automatic-font-size-in-uilabel-645549bec79a?source=rss-aa942f4faa2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/645549bec79a</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[labels]]></category>
            <dc:creator><![CDATA[Ilya Shaisultanov]]></dc:creator>
            <pubDate>Sun, 17 Jan 2016 01:29:27 GMT</pubDate>
            <atom:updated>2016-01-17T01:31:22.346Z</atom:updated>
            <content:encoded><![CDATA[<p>When you use a label (<strong>UILabel</strong>) to display a variable amount of text sometimes you want it to increase or decrease the font size to either fit more text or fill the label with a short snippet.</p><p>You can achieve this by using the <strong>Autoshrink</strong> label property:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*ulGB_4faYNGE7MruYOR1dg.gif" /></figure><p>Here, my 60pt font label is allowed to decrease its font size down to 10pt when the content does not fit into it. And it works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*aHv4qMypmEepIXgqmOOI8g.gif" /></figure><p>Easy! 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=645549bec79a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>