<?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[Technology of Me - Medium]]></title>
        <description><![CDATA[Everything About Technology and Computer Science - Medium]]></description>
        <link>https://medium.com/technology-of-me?source=rss----b72425d3b28e---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Technology of Me - Medium</title>
            <link>https://medium.com/technology-of-me?source=rss----b72425d3b28e---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 12:10:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/technology-of-me" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Taking Concurrency to the Next Level: Concurrent Calls and TaskGroups]]></title>
            <link>https://medium.com/technology-of-me/taking-concurrency-to-the-next-level-concurrent-calls-and-taskgroups-c8a874c095f7?source=rss----b72425d3b28e---4</link>
            <guid isPermaLink="false">https://medium.com/p/c8a874c095f7</guid>
            <category><![CDATA[swift-concurrency]]></category>
            <category><![CDATA[asyncawait]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Gungor Basa]]></dc:creator>
            <pubDate>Sun, 22 Sep 2024 12:39:24 GMT</pubDate>
            <atom:updated>2024-09-22T12:39:24.244Z</atom:updated>
            <content:encoded><![CDATA[<p>Summary of the post, so you don’t have to read everything if you’re in a hurry.</p><p><strong>Key Concepts:</strong><br><strong>1. Concurrency vs. Parallelism:</strong><br>Concurrency is about handling multiple tasks at once, but they don’t necessarily run simultaneously. Parallelism involves running tasks at the same time.</p><p><strong>2. Sequential Execution:</strong><br>Running tasks one after the other leads to slow and inefficient performance, especially when tasks are long or depend on external resources like network requests.</p><p><strong>3. async let:</strong><br>A concurrency tool that allows you to run a fixed, small number of asynchronous tasks concurrently, improving performance by reducing the total execution time.</p><p><strong>4. TaskGroup:</strong><br>A more flexible concurrency tool for handling a dynamic or large number of tasks, where tasks can be added and managed at runtime.</p><p><strong>5. Task Scheduling: </strong><br>Swift’s automatic task scheduling optimizes the order in which tasks are executed based on system resources like CPU availability.</p><p><strong>Benefits:</strong><br><strong>1. Improved Performance:</strong><br>Concurrency can drastically reduce the overall execution time compared to sequential task handling.</p><p><strong>2. Efficient Task Management:</strong><br>async let is great for predictable, small sets of tasks, while `TaskGroup` handles dynamic, unpredictable workloads with ease.</p><p><strong>3. Flexibility:</strong><br>TaskGroup allows for dynamic task creation, making it a superior choice when dealing with unknown or varying numbers of tasks.</p><p><strong>4. Optimized Task Execution: </strong><br>Swift automatically manages task scheduling to ensure efficient use of system resources, leading to faster completion times.</p><p>In my previous post, I introduced the basics of async/await and how it effectively solves the infamous callback hell, simplifying asynchronous programming in Swift. If you haven’t read it yet, I highly recommend starting <a href="https://gungorbasa.com/basics-of-async-await-in-swift-a-new-era-of-asynchronous-programming-6bf851ce18ac">there</a>, as it lays the foundation for understanding Swift’s modern concurrency model.</p><p>Today, we’ll take the next step and dive into <strong>task groups</strong> and the concept of concurrent asynchronous calls. I’ll show you how to structure your code to perform multiple asynchronous tasks concurrently. As an important side note, I want to clarify: we’re talking about <strong>concurrency</strong>, not <strong>parallelism</strong> — there’s a subtle but crucial difference. Concurrency is about dealing with multiple tasks at once, but it doesn’t necessarily mean they’re all running at the same time (parallel). In Swift, task groups allow you to perform asynchronous work concurrently, in a clean and manageable way, while Swift takes care of optimizing task execution under the hood.</p><p>Imagine a scenario where you need to download multiple files from a server. In real-world applications, this could involve fetching essential assets like images, documents, or other large resources that your app relies on. Handling these downloads sequentially would result in a slow, inefficient process that degrades the overall user experience.</p><p>To focus solely on the structure of handling these tasks and to avoid introducing external factors like network latency or server response times, we’ll simplify our example. Instead of making actual network requests, we’ll use the sleep function to simulate file downloads. This allows us to replicate the time it takes to complete each download without worrying about external variables.</p><pre>func networking(delay: Int, id: Int) async throws -&gt; Int {<br>    print(&quot;Task id=\(id) which takes \(delay)seconds started.&quot;)<br>    <br>    let seconds: UInt64 = 1_000_000_000<br>    try await Task.sleep(nanoseconds: UInt64(delay) * seconds)<br>    <br>    print(&quot;Task with \(id) which takes \(delay)seconds ended.&quot;)<br>    <br>    return delay<br>}</pre><p>In this code, networking(delay:id:) simulates a file download where each task takes a certain amount of time. Now, given the above function, let’s look at how slow the process can be when we handle these downloads one by one in a sequence.</p><pre>let delays = [3, 1, 5]<br><br>func downloadFilesSequentially() async throws {<br>    let startTime = CFAbsoluteTimeGetCurrent()<br>    <br>    for (index, delay) in delays.enumerated() {<br>        _ = try await networking(delay: delay, id: index)<br>    }<br>    <br>    print(&quot;downloadFilesSequentially -&gt; \(CFAbsoluteTimeGetCurrent() - startTime)seconds&quot;)<br>}</pre><p>Now, let’s take a look at the console and observe the results:</p><pre>Task id=0 which takes 3seconds started.<br>Task with 0 which takes 3seconds ended.<br>Task id=1 which takes 1seconds started.<br>Task with 1 which takes 1seconds ended.<br>Task id=2 which takes 5seconds started.<br>Task with 2 which takes 5seconds ended.<br>downloadFilesSequentially -&gt; 9.600003957748413seconds</pre><p>As you can see, each task runs sequentially in the order it was started, and the total time is the sum of the individual task durations, plus a small overhead. Regardless of how long or short each task is, they all execute one after the other, resulting in a total time of around 9.6 seconds for just three tasks.</p><p>That’s quite a lot of time — almost 10 seconds! You wouldn’t want your users to wait that long when these tasks could be completed in nearly half the time. Let’s use some concurrency techniques to speed this up.</p><p>One of the simplest ways to achieve concurrency in Swift is by using async let. This allows you to start multiple asynchronous tasks concurrently and wait for their results. Instead of running the tasks one after another, you can execute them concurrently and significantly reduce the total execution time.</p><p>async let is especially useful when you have a small, limited number of tasks you want to run concurrently. Here’s how we can modify our example to use async let:</p><pre>func download3FilesConcurrently() async throws {<br>    let startTime = CFAbsoluteTimeGetCurrent()<br>    <br>    async let first = networking(delay: delays[0], id: 1)<br>    async let second = networking(delay: delays[1], id: 2)<br>    async let third = networking(delay: delays[2], id: 3)<br>    <br>    _ = try await [first, second, third]<br>    <br>    print(&quot;download3FilesConcurrently -&gt; \(CFAbsoluteTimeGetCurrent() - startTime)seconds&quot;)<br>}</pre><p>Let’s look at the console results one more time:</p><pre>Task id=1 which takes 3seconds started.<br>Task id=2 which takes 1seconds started.<br>Task id=3 which takes 5seconds started.<br>Task with 2 which takes 1seconds ended.<br>Task with 1 which takes 3seconds ended.<br>Task with 3 which takes 5seconds ended.<br>downloadFirst3FilesConcurrently -&gt; 5.170604944229126seconds</pre><p>With the introduction of async let, the total execution time is reduced by almost half. Instead of running each task sequentially, all tasks are started concurrently. Notice how all tasks begin at the same time and then finish based on their individual durations. Given that we have 3 available cores, the operation completes in just a little more than the time of the longest task. The overall time for all tasks to finish is around 5.17 seconds, demonstrating the efficiency of concurrency with multiple cores.</p><p>As I mentioned earlier, async let is great when you have a small, fixed number of tasks. However, when the number of tasks is unknown or large, TaskGroup becomes a much better choice. Let’s use the exact times we used for async let example so that we can compare.</p><p>Now, let’s take a look at how we can achieve very similar results using <strong>TaskGroup</strong>:</p><pre>func downloadFilesConcurrently() async throws {<br>    let startTime = CFAbsoluteTimeGetCurrent()<br>    <br>    try await withThrowingTaskGroup(of: Int.self) { [weak self] group in<br>        guard let self else { return }<br>        for (id, delay) in delays.enumerated() {<br>            group.addTask {<br>                try await self.networking(delay: delay, id: id)<br>            }<br>        }<br>        <br>        for try await delay in group {<br>            // Now you can start using your results<br>            _ = delay<br>        }<br>    }<br>    print(&quot;downloadFilesConcurrently -&gt; \(CFAbsoluteTimeGetCurrent() - startTime)seconds&quot;)<br>}</pre><p>Let’s check the console output:</p><pre>Task id=1 which takes 1seconds started.<br>Task id=0 which takes 3seconds started.<br>Task id=2 which takes 5seconds started.<br>Task with 1 which takes 1seconds ended.<br>Task with 0 which takes 3seconds ended.<br>Task with 2 which takes 5seconds ended.<br>downloadFilesConcurrently -&gt; 5.174337029457092seconds</pre><p>One key aspect to highlight is how Swift’s concurrency model automatically manages task scheduling to optimize performance. Tasks can start in a non-sequential order based on system resources, such as available CPU cores, ensuring efficient execution.</p><p>For instance, in our <strong>TaskGroup</strong> results, <strong>Task id=1</strong> started first, despite being added after <strong>Task id=0</strong>. This illustrates that <strong>tasks within a task group execute concurrently and can be scheduled in any order.</strong></p><p>As you can see, the results are nearly identical to the <strong>async let</strong> example, with a total execution time of around <strong>5.17 seconds</strong>. Both methods initiate tasks concurrently, allowing them to run in parallel when possible, with the overall completion time dictated by the longest task.</p><p>So, why opt for <strong>TaskGroup</strong> if the results are so similar to <strong>async let</strong>? The primary advantage of <strong>TaskGroup</strong> becomes evident when dealing with a dynamic or large number of tasks. While <strong>async let</strong> works well for a small, fixed set of tasks, <strong>TaskGroup</strong> offers greater flexibility by enabling you to add and manage tasks dynamically at runtime. This makes it the superior choice for scenarios where the number of tasks is uncertain or can vary based on user input or other factors.</p><h3><strong>In Short:</strong></h3><p>Swift’s concurrency model, with features like async let and TaskGroup, provides powerful tools to handle asynchronous tasks in a clean and efficient way. Using these features can significantly improve performance compared to sequential execution. While async let is ideal for situations with a small, fixed number of tasks, TaskGroup offers the flexibility to dynamically manage and scale tasks when the workload is unknown or variable.</p><p>Both methods highlight the strengths of Swift’s automatic task scheduling, ensuring tasks are executed concurrently for optimal performance. By knowing when to use async let for simpler cases and TaskGroup for more complex, dynamic scenarios, you can fully harness Swift&#39;s modern concurrency capabilities to write faster, more efficient code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8a874c095f7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technology-of-me/taking-concurrency-to-the-next-level-concurrent-calls-and-taskgroups-c8a874c095f7">Taking Concurrency to the Next Level: Concurrent Calls and TaskGroups</a> was originally published in <a href="https://medium.com/technology-of-me">Technology of Me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting the User’s Location on iOS — The Faster Way]]></title>
            <link>https://medium.com/technology-of-me/getting-the-users-location-on-ios-the-faster-way-6f0562436641?source=rss----b72425d3b28e---4</link>
            <guid isPermaLink="false">https://medium.com/p/6f0562436641</guid>
            <category><![CDATA[core-location]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[cllocationmanager]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Gungor Basa]]></dc:creator>
            <pubDate>Tue, 10 Sep 2024 19:46:50 GMT</pubDate>
            <atom:updated>2024-09-10T19:46:50.378Z</atom:updated>
            <content:encoded><![CDATA[<h3>Getting the User’s Location on iOS — The Faster Way</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*PFY2qwUKRMSufUeebYgdcA.jpeg" /><figcaption>Let’s find that user on the map!</figcaption></figure><p><strong>Recently at work, our product team raised concerns about how long it was taking to retrieve the user’s location. On our vast, magical world map, the process was dragging, and we were taking our sweet time to determine where users were.</strong></p><p>Curious, I started digging into the code. Everything seemed fine at first glance. We were using the requestLocation() method, which, according to the documentation, is designed to provide a single location fix and then stop. It seemed like the perfect choice since we only needed one precise location.</p><p>On the simulator, the method worked fast, so no red flags there. But when I tested it on a real device, things got weird — it was taking an <strong>absurdly long time</strong> to return the location. Naturally, this piqued my curiosity, and I decided to measure just how long it was actually taking. To do that, I created a simple test app.</p><p>Here’s the code for the test app:</p><pre>import Foundation<br>import CoreLocation<br><br>final class ViewModel: NSObject, ObservableObject {<br>    private lazy var manager: CLLocationManager = {<br>        let manager = CLLocationManager()<br>        manager.desiredAccuracy = kCLLocationAccuracyBest<br>        manager.delegate = self<br>        return manager<br>    }()<br>    <br>    @Published var location: CLLocation = .init()<br>    @Published var timePassed: Double = 0<br>    <br>    private var locationRequestTime: Double = 0<br>    <br>    func request() {<br>        manager.requestWhenInUseAuthorization()<br>    }<br>}<br><br>extension ViewModel: CLLocationManagerDelegate {<br>    public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {<br>        switch status {<br>        case .authorizedAlways, .authorizedWhenInUse:<br>            locationRequestTime = CFAbsoluteTimeGetCurrent()<br>            manager.requestLocation()<br>            print(&quot;Authorized!&quot;)<br>        case .denied, .restricted:<br>            print(&quot;Denied!&quot;)<br>        case .notDetermined:<br>            manager.requestWhenInUseAuthorization()<br>        @unknown default:<br>            break<br>        }<br>    }<br>    <br>    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {<br>        guard let location = locations.first else { return }<br>        timePassed = CFAbsoluteTimeGetCurrent() - locationRequestTime<br>        <br>        prettyPrint(location: location, tag: &quot;Locations.first&quot;)<br>    }<br>    <br>    func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error) {<br>        print(error.localizedDescription)<br>    }<br>    <br>    private func prettyPrint(location: CLLocation, tag: String) {<br>        print(&quot;----------------------------------------&quot;)<br>        print(&quot;Tag: \(tag)&quot;)<br>        print(&quot;Vertical Accuracy: \(location.verticalAccuracy)&quot;)<br>        print(&quot;Horizontal Accuracy: \(location.horizontalAccuracy)&quot;)<br>        print(&quot;Speed Accuracy: \(location.speedAccuracy)&quot;)<br>        print(&quot;Course Accuracy: \(location.courseAccuracy)&quot;)<br>        print(&quot;----------------------------------------&quot;)<br>    }<br>}</pre><pre>import SwiftUI<br><br>struct ContentView: View {<br>    @StateObject var viewModel = ViewModel()<br>    <br>    var body: some View {<br>        VStack {<br>            Text(&quot;\(viewModel.timePassed)&quot;)<br>            Text(&quot;\(viewModel.location)&quot;)<br>            <br>            Image(systemName: &quot;globe&quot;)<br>                .imageScale(.large)<br>                .foregroundStyle(.tint)<br>            Text(&quot;Hello, world!&quot;)<br>        }<br>        .padding()<br>        .onAppear {<br>            viewModel.request()<br>        }<br>    }<br>}</pre><p><strong>Based on what I saw, I could hardly believe my eyes.</strong> It was taking around <strong>10 seconds</strong> on a real device to get the user’s location using the requestLocation() method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*Gr5hVOBEM5c5yImXAc3myQ.png" /></figure><p>After seeing those results, I knew there had to be a better way. After some research, I decided to try a different approach: <strong>startUpdatingLocation()</strong>.</p><p>Unlike requestLocation(), which gives you a single location and then stops, startUpdatingLocation() continuously updates the location until you manually stop it. At first, this might sound like an overkill if you only need one location fix, but I was curious to see how it compared.</p><p>To mimic the behavior of requestLocation(), I planned to simply stop the location updates as soon as I got the first result. Here’s the code change for the new method:</p><pre>func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {<br>    switch status {<br>    case .authorizedAlways, .authorizedWhenInUse:<br>        locationRequestTime = CFAbsoluteTimeGetCurrent()<br>        manager.startUpdatingLocation()<br>        print(&quot;Authorized!&quot;)<br>    case .denied, .restricted:<br>        print(&quot;Denied!&quot;)<br>    case .notDetermined:<br>        manager.requestWhenInUseAuthorization()<br>    @unknown default:<br>        break<br>    }<br>}<br><br>func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {<br>    guard let location = locations.first else { return }<br>    timePassed = CFAbsoluteTimeGetCurrent() - locationRequestTime<br>    <br>    prettyPrint(location: location, tag: &quot;Locations.first&quot;)<br>    manager.stopUpdatingLocation()<br>}</pre><p>When I ran the new code, my jaw practically dropped. The startUpdatingLocation() method was about <strong>600 times faster</strong> than our original approach! It returned the location almost instantly, which was a <strong>huge</strong> improvement over the 10-second delay we were seeing before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*AIEe841wkB4j5Yq4YmY5AA.png" /></figure><p>Here are the accuracy results for both methods.</p><pre>requestLocation:<br><br>Vertical Accuracy: 3.0<br>Horizontal Accuracy: 19.471317809500263<br>Speed Accuracy: -1.0<br>Course Accuracy: -1.0<br><br>startUpdatingLocation:<br><br>Vertical Accuracy: 3.0<br>Horizontal Accuracy: 19.63992458714842<br>Speed Accuracy: -1.0<br>Course Accuracy: -1.0</pre><p>As you can see, the accuracy values are almost identical. So, not only is startUpdatingLocation() significantly faster, but it’s just as precise as requestLocation().</p><h3>Wrapping It Up</h3><p>In our quest to optimize location retrieval, we uncovered a significant performance boost by switching from requestLocation() to startUpdatingLocation(). Initially, requestLocation() took around 10 seconds on a real device, which was surprisingly slow. However, by using startUpdatingLocation() and stopping updates after receiving the first result, we achieved a staggering improvement without loosing accuracy—location updates became about <strong>600 times faster</strong>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f0562436641" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technology-of-me/getting-the-users-location-on-ios-the-faster-way-6f0562436641">Getting the User’s Location on iOS — The Faster Way</a> was originally published in <a href="https://medium.com/technology-of-me">Technology of Me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basics of Async/Await in Swift: A New Era of Asynchronous Programming]]></title>
            <link>https://medium.com/technology-of-me/basics-of-async-await-in-swift-a-new-era-of-asynchronous-programming-6bf851ce18ac?source=rss----b72425d3b28e---4</link>
            <guid isPermaLink="false">https://medium.com/p/6bf851ce18ac</guid>
            <category><![CDATA[asyncawait]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-concurrency]]></category>
            <dc:creator><![CDATA[Gungor Basa]]></dc:creator>
            <pubDate>Wed, 14 Aug 2024 07:26:45 GMT</pubDate>
            <atom:updated>2024-08-14T08:00:39.281Z</atom:updated>
            <content:encoded><![CDATA[<p>Handling asynchronous context in Swift has been challenging for years, but with the introduction of async/await in Swift 5.5 (2021), things have changed. The promise of async/await is to allow developers to write safer, more intuitive code, a.k.a making our lives easier. Swift 6 takes this goal even further and tries to make the process safer than the original async/await. In this post, I&#39;ll explore how async/await works, its benefits, and how it transforms the way we write asynchronous code.</p><p>But first, let’s remember the way we have been writing asynchronous code all these years, and let’s see what are the problems with it.</p><h4><strong>Grand Central Dispatch(GCD) — The Traditional Way</strong></h4><p>Before async/await, asynchronous programming in Swift often relied on callbacks, completion handlers, and Grand Central Dispatch (GCD). While these tools were effective, they often led to code that was hard to read, maintain, and debug. Additionally, managing references with weak and unowned keywords can add complexity and lead to potential issues.</p><pre>func fetchData(completion: @escaping (Result&lt;Data, Error&gt;) -&gt; Void) {<br>    DispatchQueue.global().async {<br>        // Making a network call<br>        guard let data: Data = ... else { return completion(.failure(NetworkError.notFound)) }<br>        completion(.success(data))<br>    }<br>}<br><br>fetchData { result in<br>    switch result {<br>    case .success(let success):<br>        print(&quot;Successfully Fetch Data&quot;)<br>    case .failure(let error):<br>        print(&quot;Failed to Fetch Data \(error.localizedDescription)&quot;)<br>    }<br>}</pre><p>I can hear many of you saying, “It’s not that bad. It’s okay, and it looks familiar. We like our way.” However, in real-world scenarios, code is rarely that simple. Often, we find ourselves writing more complex code where multiple asynchronous calls need to be chained together, leading to what is commonly known as Callback Hell.</p><h4><strong>From Callback Hell to </strong><strong>async/await Simplicity</strong></h4><p>Let’s consider a scenario where we first fetch the data, then parse it, and finally save it to disk.</p><pre>// Method signatures<br>func fetchData(completion: @escaping (Result&lt;Data, Error&gt;) -&gt; Void)<br>func parseData(_ data: Data, completion: @escaping (Result&lt;String, Error&gt;) -&gt; Void)<br>func saveData(_ parsedResult: String, completion: @escaping (Result&lt;Bool, Error&gt;) -&gt; Void)<br><br>fetchData { [weak self] result in<br>    switch result {<br>    case .success(let data):<br>        self?.parseData(data) { parseResult in<br>            switch parseResult {<br>            case .success(let parsedString):<br>                self?.saveData(parsedString) { saveResult in<br>                    switch saveResult {<br>                    case .success:<br>                        print(&quot;Successfully Saved Parsed String&quot;)<br>                    case .failure(let error):<br>                        print(&quot;Failed to Save Parsed String \(error.localizedDescription)&quot;)<br>                    }<br>                }<br>            case .failure(let error):<br>                print(&quot;Failed to parse data!&quot;)<br>            }<br>        }<br>    case .failure(let error):<br>        print(&quot;Failed to Fetch Data \(error.localizedDescription)&quot;)<br>    }<br>}</pre><p>How about now? Still like your traditional method? I didn’t think so. This code is very hard to read and debug, and it’s only three levels deep. What if you needed more?</p><h4><strong>Simplicity of async/await Code</strong></h4><p>With async/await, your method definitions become much cleaner and more readable:</p><pre>func fetchData() async throws -&gt; Data { fatalError() }<br>func parseData(_ data: Data) async throws -&gt; String { fatalError() }<br>func saveData(_ parsedResult: String) async throws -&gt; Bool { fatalError() }</pre><p>Now, let’s see how it transforms the callback hell:</p><pre>let data = try await fetchData()<br>let parsedString = try await parseData(data)<br>let isSaved = try await saveData(parsedString)</pre><p>Isn’t it beautiful? No more callback hell — just straightforward, easily readable code.</p><p>On top of it, it is very easy to handle errors as well. Just wrap it up with a do/catch block and Voila! 🪄🪄🪄</p><p>Your new code looks like this ⬇️</p><pre>do {<br>    let data = try await fetchData()<br>    let parsedString = try await parseData(data)<br>    let isSaved = try await saveData(parsedString)<br>} catch {<br>    // Handle your error<br>}</pre><p><strong>Using </strong><strong>Task to Manage Asynchronous Context</strong><br>How do we call these async functions? Can we directly call it from our synchronous code? The answer is unfortunately NO! Don’t worry, though — it’s easy to solve. Simply wrap it in a Task.</p><pre>Task {<br>    do {<br>        let data = try await fetchData()<br>        let parsedString = try await parseData(data)<br>        let isSaved = try await saveData(parsedString)<br>    } catch {<br>        // Handle your error<br>    }<br>}</pre><p>With above code block ⬆️, your code will run in an asynchronous context, allowing you to perform concurrent work without blocking the thread that initiated the task.</p><p>Let’s go over some of the keywords we used for our example;</p><p>Task: It allows you to run asynchronous code from within a synchronous context, effectively bridging the gap between traditional synchronous code and the new asynchronous model.</p><p>try: Used to call a function that might throw an error. When using try in combination with async/await, you&#39;re signaling that the asynchronous function you&#39;re calling could fail, and you need to handle that failure appropriately. If an error is thrown, it will be caught in a catch block.</p><p>async: Marks a function as asynchronous, meaning it can be suspended and resumed later. This type of function can only be called from an asynchronous context. When a function is marked with async, it allows you to use the await keyword within that function to wait for asynchronous tasks to complete without blocking the current thread.</p><p>await: Pauses the execution of the function until the asynchronous operation completes. Due to the nature of the new concurrency model, tasks can be suspended and resumed later. When you use await, you essentially tell Swift to wait for an asynchronous operation to finish before moving on to the next line of code, making the code look and behave like synchronous code.</p><p>In conclusion; async/await in Swift is a powerful tool that brings simplicity and clarity to asynchronous programming. By making asynchronous code look and behave like synchronous code, it reduces the cognitive load on developers and makes codebases easier to maintain.</p><p>This is all for today. I will continue to write about Swift and Swift Concurrency. I’ll link all other concurrency-related posts below. Stay tuned for more on Swift!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bf851ce18ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technology-of-me/basics-of-async-await-in-swift-a-new-era-of-asynchronous-programming-6bf851ce18ac">Basics of Async/Await in Swift: A New Era of Asynchronous Programming</a> was originally published in <a href="https://medium.com/technology-of-me">Technology of Me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Anaconda Python Tutorial]]></title>
            <link>https://medium.com/technology-of-me/anaconda-python-tutorial-971e2cd9ef9c?source=rss----b72425d3b28e---4</link>
            <guid isPermaLink="false">https://medium.com/p/971e2cd9ef9c</guid>
            <category><![CDATA[udacity-nanodegree]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[virtual-environment]]></category>
            <category><![CDATA[udacity]]></category>
            <category><![CDATA[anaconda]]></category>
            <dc:creator><![CDATA[Gungor Basa]]></dc:creator>
            <pubDate>Wed, 28 Oct 2020 19:20:45 GMT</pubDate>
            <atom:updated>2020-10-28T19:21:25.178Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*fRnWUPSf7CKq5CClznvrzg.png" /></figure><blockquote>It’s a new dawn, it’s a new day, it’s a new life for me<br>Ouh<br>And I’m feeling good</blockquote><p>Lately, I have been having major changes in my life. Quitted my job, moved from Berlin to my home country, worked on very interesting projects and found another remote iOS developer job at a SF based startup. As it wasn’t enough, today I got enrolled to Udacity Deep Learning Nanodegree Program. Hooraayyyyyyy 👊💪🍾</p><p>As a part of the program, I had to refresh my knowledge about Anaconda. It’s very easy to install. Go to the <a href="https://www.anaconda.com/products/individual">website</a>, and download appropriate version and install it.</p><p><strong>Create New Virtual Environment with </strong><strong>Python3</strong></p><pre>conda create -n env_name python=3</pre><p><strong>Start Using Specific Virtual Environment</strong></p><pre>conda activate env_name</pre><p><strong>Stop Using An Environment</strong></p><pre>conda deactivate</pre><p><strong>Remove Existing Virtual Environment</strong></p><pre>conda env remove -n env_name</pre><p><strong>Install A Package</strong></p><pre>conda install package_name</pre><p><strong>Remove A Package</strong></p><pre>conda remove package_name</pre><p>Now that, you know most widely used commands, let’s shift the gear and learn how to export and import environments to use it in our later. This will be useful if we share our codebase with others.</p><p><strong>Exporting An Environment</strong></p><pre>conda env export &gt; environment.yaml</pre><p>This command will create a file named `environment.yaml` which contains all installed conda packages with installed versions.</p><p>On top of conda, we might be also using pip to install some of our pacakages. If we do that, it would be good to export/import it as well.</p><pre>pip freeze &gt; requirements.txt</pre><p><strong>Importing An Environment</strong></p><pre>conda env create -f environment.yaml</pre><p>Now, lets import pip environment as well.</p><pre>pip install -r requirements.txt</pre><p>Hope, this little tutorial is helpful for you peeps. 😉 See ya! 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=971e2cd9ef9c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technology-of-me/anaconda-python-tutorial-971e2cd9ef9c">Anaconda Python Tutorial</a> was originally published in <a href="https://medium.com/technology-of-me">Technology of Me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intelligent Agents: Agent Programs & Main Type of Agents]]></title>
            <link>https://medium.com/technology-of-me/intelligent-agents-agent-programs-main-type-of-agents-58395d3c1733?source=rss----b72425d3b28e---4</link>
            <guid isPermaLink="false">https://medium.com/p/58395d3c1733</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[intelligent-agent]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Gungor Basa]]></dc:creator>
            <pubDate>Sun, 10 Jun 2018 14:39:58 GMT</pubDate>
            <atom:updated>2018-06-10T14:39:57.957Z</atom:updated>
            <content:encoded><![CDATA[<p>In my previous post, I mentioned about agent programs. In this post, I will get into more details. To quick recap, an agent program is a real implementation of an agent function. In other words, it implements an agent function which maps percepts to actions.</p><p>Despite the agent function can hold all history of percepts, an agent program can only take one input (current input) at a time cause there is nothing available at the time. (Think about it, an agent program takes snapshots of the environment. Even though it takes multiple snapshots at the same time, they will be identical.) However, they may hold state inside of the program. Let’s deep dive.</p><p>There are four basic types of agent programs. These almost embody the all intelligent agent systems.</p><ol><li><strong>Simple Reflex Agents</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*i9TYnjWAIwYyMfieYeo9tg.png" /></figure><p>This is the simplest type of all four. This type of agents are admirably simple but they have very limited intelligence. Their actions are based on the current percept. They only looks at the current state and decides what to do. Neither they hold nor consider any part of the history during their decision process.</p><p>In some cases like smart thermostats, this type of agent might be useful, however, in most cases its not. Especially, if the environment is partially observable, it might be the recipe of a disaster 🤔 As I said, they have very limited intelligence. Their intelligence is only based on the given static table. No learning capacity. Below is a pseudo code for a simple reflex agent.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b6d13e22599e266a124d2bdbae2f776/href">https://medium.com/media/3b6d13e22599e266a124d2bdbae2f776/href</a></iframe><p>Simple reflex agent holds a static table for rules. It gets a percept as an input and returns an action. First, based on the input tries to understand the state of the environment. Then in the static table, finds the corresponding rule to this state. At last, returns the action of the rule.</p><p>2. <strong>Model-based Reflex Agents</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*13QqkSf5S5UOfwvEW38vQA.png" /></figure><p>This type of agents is little bit more complicated than the reflex based agents. A model based agent holds an internal state based on the percept history. This internal state helps agent to handle a partially observable environment. It consider both internal state and current percept to take an action. Also, each step it updates the internal state.</p><p>Updating internal state requires two kinds of knowledge.</p><ol><li>Agent needs to know how the world evolves independently from the agent.</li><li>How the agent’s actions affect the environment.</li></ol><p>Both of these knowledge is embedded to the agent’s program and they help agent to understand how the world works. Implementation of this, is called the model of the world and the agent that uses this model to decide what action to take called model based agent.<br>A model based reflex agent takes the current percept and combine it with the internal state, model, and most recent action’s effect then decides about what action to take. Below is a pseudo code for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40e7caf0bc3dde99195efd80645a82b6/href">https://medium.com/media/40e7caf0bc3dde99195efd80645a82b6/href</a></iframe><p><strong>P.S.</strong> It is rarely possible to determine exact state of a partially observable environment.</p><p>3. <strong>Goal-Based Agents</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*0uS4soaK0pM-s2zZzTR8kA.png" /></figure><p>For some tasks, its not always enough to know how the world works. In some cases, its desirable to define a <strong>goal</strong> information to describe a desirable situations. A goal-based agent combines model-based agent’s model with a goal. To reach its goal. it often uses <strong>Search</strong> and <strong>Planning</strong> algorithms.</p><p>Goal based agents usually less efficient but more flexible than reflex-based agents. A goal based-agent can suit itself based on the environment. For example, a goal-based agent can adapt its behavior based on the sensor data.</p><p>4. <strong>Utility-Based Agents</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*U5N-SVJ3NBMriUJYbSJfIA.png" /></figure><p>Goal-Based agents seems pretty cool and seems like we don’t need another one. Is that so? No, no no no. That’s not correct. If we look at the goal based agents, we see they select the action based on the goal. End result is we achieve our goal and we are happy 🤗🤠👻. But how happy are we? Just imagine that, we want to go from point A to point B. There are 2 paths. One is 10-miles long and the other is 100. Unfortunately, our goal based agent may or may not choose the path 2(100 miles long). At the end whichever path we take, we will reach our destination but how happy will we be if we take the longer path? Probably, not so much. That’s the problem for goal-based agents. They don’t consider the journey 😞. How do we fix this? Well we try to fix this with <strong>Utility-Based Agents</strong> 😀</p><p>With Utility-Based agents we use utility function which is essentially an internationalization of the performance measurement (It kinda defines how happy will we be if we choose this path). Also, if there are multiple goals(yes, you heard me right. Might be multiple goals.) and these goals conflicts in some cases, utility function specifies the appropriate tradeoff. Also, if non of these goals can be achieved with certainty, utility may provide likelihood of success.</p><p>Technically speaking, a rational utility based agent chooses its action to maximize the performance.</p><p><strong>P.S.</strong> There is actually one really important type of agents. Its learning agents. I decide to go over that in another post 😉 At the end of the day, learning is important.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58395d3c1733" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technology-of-me/intelligent-agents-agent-programs-main-type-of-agents-58395d3c1733">Intelligent Agents: Agent Programs &amp; Main Type of Agents</a> was originally published in <a href="https://medium.com/technology-of-me">Technology of Me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intelligent Agents]]></title>
            <link>https://medium.com/technology-of-me/intelligent-agents-dc5901daba7d?source=rss----b72425d3b28e---4</link>
            <guid isPermaLink="false">https://medium.com/p/dc5901daba7d</guid>
            <category><![CDATA[intelligent-agent]]></category>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Gungor Basa]]></dc:creator>
            <pubDate>Sat, 28 Apr 2018 20:22:03 GMT</pubDate>
            <atom:updated>2018-04-28T21:52:13.237Z</atom:updated>
            <content:encoded><![CDATA[<p>We call anything as an agent that can perceive its environment through sensors and acts upon an environment using its actuators. They direct their activity to achieve their goals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7EdPs38H8fZOu-6pcWBrZA.png" /><figcaption>An agent interact its environment through its sensors and actuators</figcaption></figure><p>We use the term <strong>percept</strong> to refer agent’s perception at any given time through its sensors. A <strong>percept sequence</strong> is the whole history of whatever the agent perceived from the environment. Based on the whole history or a perceived input, agent decides about what to do. However, it will never act on anything it hasn’t perceived.</p><p>As you may remember from the definition, agents perceive the environment and act with their actuators. But we haven’t said how they decide how to act. In other words, what is the behavior of an agent given a percept sequence. <strong>For a simple agent</strong> the answer is agent function(There are more advanced agents but lets start with this one). <strong>Agent function</strong> maps any given percept sequence to an action. Its like a huge table(might as well infinite) that any possible percept sequence has an act. Since the table may get infinitely large, we put a bound on the length of percept sequence we are really interested in.</p><p>A simple agent program can be defined mathematically as an agent function. In other words, for our simple agent an <strong>agent program</strong> implements the agent function. Keep in mind, agent function is an abstract mathematical definition, however an agent program is a concrete implementation which runs on some systems.</p><p>Everything seems pretty cool by now. But seriously, how does an agent act? How do we fill this infinitely large table? The answer is, an agent should act rationally :) I am not kidding by the way. It should. It is a good behavior. It should be as rational as possible so that we call it a <strong>rational agent</strong>(Please, don’t ask me, if there is an irrational one :) probably, yes. A bad one).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3rDcZTqWLrIB7C-zKo276w.jpeg" /><figcaption>Pink Panther An Irrational Agent :)</figcaption></figure><p>A rational agent is one that does the right thing at the right time. Conceptually, every entry of our agent table is filled out correctly. But, still how do we decide that. Doing a good job seems like an objective concept. Let me explain a little bit more. An agent perceives the environment and it generates a sequence of actions. This sequence of actions have effect on the environment state. If this state is desirable, that means the agent performed well. This is captured by a <strong>performance measure</strong> that evaluates any given sequence of environment states. Given percept sequence and agent’s builtin knowledge, a rational agent tries to maximize its performance measure. This performance measure changes based on the nature of the problem. However, as a general rule, its better to design this performance measurement based on the environment state, not according to one thinks how an agent performs(By the way, even though it seems like an easy task to design a performance measure, it is not).</p><p>Any given time concept of rationality depends on four things.</p><ol><li>The performance measure</li><li>The agent’s prior knowledge</li><li>Capability of agent(Actions that agent can perform).</li><li>The agent’s percept sequence to date</li></ol><p>All these four things bring us to the official definition of a rational agent. Finally, we can define it :)</p><blockquote><strong>For each possible percept sequence, a rational agent should select an action that is expected to maximize its performance measure, given the evidence provided by the percept sequence and whatever builtin knowledge that the agent has.</strong></blockquote><p>One important thing to remember, a rational agent in one environment might be irrational in the other one.</p><p>Also, a rational agent should be autonomous. After some sufficient time, autonomous agent’s behavior might be independent of its prior knowledge. This is learning.</p><p>This is the end of today’s blog post. Wait for the next one :) Peace out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc5901daba7d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technology-of-me/intelligent-agents-dc5901daba7d">Intelligent Agents</a> was originally published in <a href="https://medium.com/technology-of-me">Technology of Me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is AI?]]></title>
            <link>https://medium.com/technology-of-me/what-is-ai-9114d2d7e5f4?source=rss----b72425d3b28e---4</link>
            <guid isPermaLink="false">https://medium.com/p/9114d2d7e5f4</guid>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[smart-agents]]></category>
            <dc:creator><![CDATA[Gungor Basa]]></dc:creator>
            <pubDate>Mon, 23 Apr 2018 12:25:15 GMT</pubDate>
            <atom:updated>2018-04-23T12:25:14.671Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PPuylyZuVtbyEBukW2yGAA.jpeg" /><figcaption>A Scene From <strong>“The Imitation Game”</strong></figcaption></figure><p>Lately, I had some spare time in hand and decided to study AI. To do that, started to read <strong>Artificial Intelligence A Modern Approach</strong> from Stuart Russell and Peter Norvig. I have to say that it is a good book to study for intelligence agents and AI. In this AI series, I will try to explain what I learned from this book. Anyway, let’s cut the chase and get started.</p><p>What is AI? It’s not that easy to define what AI is. There is no one absolute definition for it. In fact, there are four general approaches to decide about intelligence of the machine. In other words, artificial intelligence.</p><ol><li><strong>Turing Approach (Acting Humanly)</strong></li></ol><blockquote>The art of creating machines that perform functions that require intelligence when performed by people.</blockquote><blockquote>Kurzweil</blockquote><p>Turing proposed a test called “The Imitation Game” to settle the argument about machine intelligence. In the test, there are three rooms. In one room, there is a contestant, in other one there is a machine and in the last one there is a judge. Judge’s job is to decide which one is human and which one is the machine. Judge asks questions to decide. Turing says that if the judge cannot decide which one is human and which one is machine, machine has to be smart/intelligent. In other words, we say that the machine/system acted like a human.</p><p>To be able to pass this test, machine needs to have natural language processing, knowledge representation, automated reasoning, and machine learning capabilities.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FsXx-PpEBR7k%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DsXx-PpEBR7k&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FsXx-PpEBR7k%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4225afa1d942f8c826e723853a33692f/href">https://medium.com/media/4225afa1d942f8c826e723853a33692f/href</a></iframe><p>2. <strong>The Cognitive Modeling Approach (Thinking Humanly)</strong></p><blockquote>[The automation of] activities that we associate with human thinking, activities such as decision-making, problem solving, learning…</blockquote><blockquote>Bellman</blockquote><p>This approach says that if a machine can think like a human, it must have intelligence. But, how can we determine how human thinks? In cognitive science there are three methods: through introspection, through psychological experiments, and through brain imaging. “Once we have the theory of mind in hand, it is possible to express this theory as a computer program. If the computer’s input-output behavior matches with human behavior, we can say that some of the program’s mechanisms could also be operating in humans as well.” Since, humans have intelligence, machine might as well.</p><p>3. <strong>The “Laws of Thought” Approach (Thinking Rationally)</strong></p><blockquote>The study of computations that make it possible to perceive, reason, and act.</blockquote><blockquote>Winston</blockquote><p>Logicians developed a precise notations for statements about all kinds of objects in the world and relations among them. In theory, any solvable problem which can be represented in logical notations can be solved by a machine. Logicist tradition hope to create a machine to solve such problems to create an intelligence machine. This approach is a direct line through mathematics and philosophy to modern AI.</p><p>However, there are multiple problems about this approach. Not all intelligent behavior is mediated by logical reasoning. Also, it is extremely hard to encode some uncertain information. Lastly, in practice its intractable.</p><p>4. <strong>The Rational Agent Approach (Acting Rationally)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mq53MkUghYbUgk9q8B96Bw.jpeg" /><figcaption>My favorite computer agent :)</figcaption></figure><p>This is the actual meat of the book. We will learn together about rational agents in depth with this series. What is rational agent? Let me start by defining what agent is though. Then we will come back to rational agent. An agent operates automatically, stays around for a long time, adapts to situations, creates and pursue goals. I feel like its kind of a human virus. A rational agent is an agent that pursues the best outcome. Given available information tries to maximize the goal achievement. It seems like a pretty.</p><p>To do all of these above, a rational agent might use laws of thought as well. In the end, logical reasoning is a good way to solve problems. However, in some situations there is no provable correct thing to do so it may not be the best way, so rational agents takes a different approach. Think about this, as a reflex action. If there is a hot stove in the room and touch it accidentally, you will immediately stop touching the stove. This is a reflex and so fast. Its a lot better than thinking about what is a rational thing to do. Just do the action. Just a reflex. So rational agent takes this reflex action.</p><p>There are two clear advantages of rational agents over other approaches. First, its more general than thinking rationally. Its only a way to implement rational agents. There is a lot more thing for rational agents. Also, rational agents is more amenable to scientific development than approaches based on human behaviors.</p><p>Hope you guys enjoyed this post. Following posts are on their way. Stay tuned. Peace out.</p><p>P.S. I am open for any comment and recommendations. If I missed some points or some parts need more explanation, please let me know.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9114d2d7e5f4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technology-of-me/what-is-ai-9114d2d7e5f4">What is AI?</a> was originally published in <a href="https://medium.com/technology-of-me">Technology of Me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Starting Udacity Self Driving Car Nanodegree with Docker]]></title>
            <link>https://medium.com/technology-of-me/starting-udacity-self-driving-car-nanodegree-with-docker-8d26e0a1a110?source=rss----b72425d3b28e---4</link>
            <guid isPermaLink="false">https://medium.com/p/8d26e0a1a110</guid>
            <category><![CDATA[sdcnd]]></category>
            <category><![CDATA[udacity]]></category>
            <category><![CDATA[autonomous-cars]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <dc:creator><![CDATA[Gungor Basa]]></dc:creator>
            <pubDate>Sat, 18 Mar 2017 20:40:50 GMT</pubDate>
            <atom:updated>2017-03-18T20:42:47.313Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*P7sm4N6KHGabbtIPUYs4dw.png" /></figure><p>I just realized there are still a lot of people having problem with Docker and starter kit for Self Driving Car Nanodegree program. In this post, I will give you a step by step guide.</p><p>For this post, I assume you have successfully install Docker to your local machine. If you haven’t, please go to <a href="https://www.docker.com/community-edition">https://www.docker.com/community-edition</a> and pick a compatible version for your OS.</p><p>Let’s start the actual part;</p><p>First, we need to pick the project we want to work on. I assume if you are here, you need Project-1. So, let’s clone Project-1 repo to our local and change our directory into the folder. If you want to work on a different project, please clone that project.</p><pre>git clone <a href="https://github.com/udacity/CarND-LaneLines-P1.git">https://github.com/udacity/CarND-LaneLines-P1.git</a><br>cd CarND-LaneLines-P1</pre><p>Now, lets download the Docker image for Self Driving Car Starting Kit.</p><pre>docker pull udacity/carnd-term1-starter-kit</pre><p>Now, everything is almost good to go. Last step is running Docker image with ipython notebook. Based on your OS, one of below commands should work.</p><pre>docker run -it -p 8888:8888 -v `pwd`:/src udacity/carnd-term1-starter-kit</pre><p>or</p><pre>docker run -it -p 8888:8888 -v ${pwd}:/src udacity/carnd-term1-starter-kit</pre><p>Above command mount your current directory to the“src” in your vm and starts running ipython notebook on Docker. Your output should be something like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SuOYIOWn5RzATDlHbJPjiQ.png" /></figure><p>As a last step, please open your browser and type the address provided in your command line. (It will be something similar to above output, but it is different. Directly copy it from your terminal and paste it to your browser)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d26e0a1a110" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technology-of-me/starting-udacity-self-driving-car-nanodegree-with-docker-8d26e0a1a110">Starting Udacity Self Driving Car Nanodegree with Docker</a> was originally published in <a href="https://medium.com/technology-of-me">Technology of Me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift3 — Memory Leaks]]></title>
            <link>https://medium.com/technology-of-me/swift3-memory-leaks-135967a2fcea?source=rss----b72425d3b28e---4</link>
            <guid isPermaLink="false">https://medium.com/p/135967a2fcea</guid>
            <category><![CDATA[cars]]></category>
            <category><![CDATA[memory-leak]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Gungor Basa]]></dc:creator>
            <pubDate>Sat, 25 Feb 2017 08:07:06 GMT</pubDate>
            <atom:updated>2017-02-25T08:07:05.822Z</atom:updated>
            <content:encoded><![CDATA[<p>If you recently started(last 2–3 years) iOS development, you probably don’t know that developers had to do memory management for iOS 4 and earlier versions. With iOS 5 automatic reference counting (ARC) came out and saved us from this burden. ARC is a compiler feature which, makes memory management process automatic.</p><p>Whenever you create a new instance of a class, ARC allocates required memory. As long as you have a strong reference in your program ARC does not deallocate memory. Once it realizes no one needs it (no active/strong reference left) ARC deallocates the memory.</p><p>On the paper and most of the time implementation ARC works great and help you write code without thinking about memory management. Look at the code below. It is a simple class which has init and deinit functions. ARC calls init when it creates an instance of a class and calls deinit when deallocates memory for created instance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb1b64a59c282bc36d746c25aafdb13e/href">https://medium.com/media/cb1b64a59c282bc36d746c25aafdb13e/href</a></iframe><p>Lets create a book instance and then deallocate it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d617e64665374acc20eedac2ee72308/href">https://medium.com/media/7d617e64665374acc20eedac2ee72308/href</a></iframe><p>However, after you create your instance, if you assign the same Book to different variables (if you create more than 1 strong reference), ARC deallocates the instance after no one points it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0a425095ce0720fc989122ed4430929/href">https://medium.com/media/d0a425095ce0720fc989122ed4430929/href</a></iframe><p>Above is the basic explanation of how ARC works. <strong>In short, as long as program has 1 strong reference to an object, ARC does not deallocate the created memory.</strong></p><p>Let’s move forward with our example. I would like to create one more class named Author and I will add one Author type variable in Book class. Also, each Author class has a Book variable named mostFamousBook. Below is our classes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d997e84f53961b509bcb7a0d4eb7197/href">https://medium.com/media/2d997e84f53961b509bcb7a0d4eb7197/href</a></iframe><p>Now, lets run below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0464b22d79b5e27d88fecb530b87fc0/href">https://medium.com/media/e0464b22d79b5e27d88fecb530b87fc0/href</a></iframe><p>Here we have a <strong>strong reference cycle</strong> in our code. ARC will never be able to deallocate memory allocated for book and jkrowling instances.</p><p>You may need to have such a relationship in your code. Is that mean we will have a memory leak? Of course, <strong>NO</strong>. How can we solve this problem? All you need to do is using a keyword <strong>weak</strong> while defining your variable (Another way is using <strong>unowned</strong> keyword). If you use weak, it will not cause a runtime error. If you use unowned and the object we are referring to is deallocated, it will cause a run time error. Below is the example for weak keyword.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7277067bd5252fbb496fd5000cfee366/href">https://medium.com/media/7277067bd5252fbb496fd5000cfee366/href</a></iframe><p>Let’s use unowned now. To be able to use, unowned we need to use let keyword to define mostFamousBook. This requires us to update init method as well (Since we cannot change it after initialization).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bc07260462444758c771a977a5c3e81/href">https://medium.com/media/1bc07260462444758c771a977a5c3e81/href</a></iframe><p>Be careful using unowned though, if you try to reach mostFamousBook after you deinitialize book, you will get a runtime error (Look at the above code).</p><p>Hope this post clarifies the memory management on iOS little bit better.</p><p><strong>References:</strong></p><p><a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html">https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=135967a2fcea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technology-of-me/swift3-memory-leaks-135967a2fcea">Swift3 — Memory Leaks</a> was originally published in <a href="https://medium.com/technology-of-me">Technology of Me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep Learning on iOS — Part1]]></title>
            <link>https://medium.com/technology-of-me/deep-learning-on-ios-part1-57a2a3849124?source=rss----b72425d3b28e---4</link>
            <guid isPermaLink="false">https://medium.com/p/57a2a3849124</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Gungor Basa]]></dc:creator>
            <pubDate>Wed, 12 Oct 2016 22:44:16 GMT</pubDate>
            <atom:updated>2016-10-16T19:18:38.823Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="torch_ios" src="https://cdn-images-1.medium.com/max/472/0*FrNMROIKNGGjLGXm.png" /></figure><p>Deep Learning (DL) is the new era of Machine Learning. With Deep Learning (CNN, RNN, LSTM etc.) scientists had great success on object detection, natural language processing, and many other areas last couple years. Apple, Google, Microsoft and many big companies improved their products with this technology.</p><p>There are couple different libraries for DL for iOS platform. This blog post’s topic is one of the most famous ones, Torch. Let’s get hands dirty now.</p><p>To be able to continue, you should have Brew package manager If you haven’t installed it to your computer, install it with below command.</p><pre>$ /usr/bin/ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;</pre><p>Now, we have Brew in our computer. It is time to install Torch on our Macs. Open your terminal and type below commands. These commands help you to install Torch automatically (painless way :).</p><pre>$ git clone <a href="https://github.com/torch/distro.git">https://github.com/torch/distro.git</a> ~/torch --recursive<br>$ cd ~/torch; bash install-deps;<br>$ ./install.sh<br>$ source ~/.bashrc</pre><p>During the install phase installer may ask you;</p><pre>Do you want to automatically prepend the Torch install location to PATH and LD_LIBRARY_PATH in your /Users/&lt;username&gt;/.zshrc? (yes / no)</pre><p>If you are using zshrc shell, type yes, if you are not using like me, type no and enter. To be able to complete the install, we should add the library to to path. I prefer bash for my terminal, so I do below step. If you are using, something different than zshrc or bash, please find appropriate commands to add Torch install location to Path. For bash terminal open ~/.bash_profile,</p><pre>$ vim ~/.bash_profile</pre><p>and add below line to end of the file</p><pre>. /Users/&lt;username&gt;/torch/install/bin/torch-active</pre><p>Now based on your terminal type, source our terminal to refresh environment variables.</p><pre>$ source ~/.bash_profile</pre><p>If we do everything correctly, Torch should be installed to your OSx. To test, type “th” command into your terminal.</p><figure><img alt="Screenshot 2016-07-03 00.19.30" src="https://cdn-images-1.medium.com/max/300/0*30lL2LMsgkRhe593.png" /></figure><p>If you see above prompt, congratulations you have Torch on your computer. Now, it is time to learn how to use it as iOS library. (To exit type “os.exit()”)</p><pre>$ git clone <a href="https://github.com/clementfarabet/torch-ios.git">https://github.com/clementfarabet/torch-ios.git</a> ~/torch_ios --recursive<br>$ cd ~/torch_ios<br>$ ./generate_ios_framework</pre><p>Above commands will build all Torch libraries as static library for iOS and put it into “~/torch_ios/framework” directory. Now we are ready to use Torch in iOS environment.</p><p><strong>Resources:</strong></p><ul><li><a href="http://torch.ch/docs/getting-started.html">Torch | Getting started with Torch</a></li><li><a href="https://github.com/clementfarabet/torch-ios">clementfarabet/torch-ios</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57a2a3849124" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technology-of-me/deep-learning-on-ios-part1-57a2a3849124">Deep Learning on iOS — Part1</a> was originally published in <a href="https://medium.com/technology-of-me">Technology of Me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>