<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <atom:link href="http://kmikael.com/feed.xml" rel="self" type="application/rss+xml" />
    <title>Mikael Konutgan</title>
    <link>http://kmikael.com</link>
    <description>Thoughts on programming, Unix and technology</description>
    
      <item>
        <title>OS X Tutorial: A Menu Bar App</title>
        <link>http://kmikael.com/2015/05/05/os-x-tutorial-a-menu-bar-app/</link>
        <guid isPermaLink="true">http://kmikael.com/2015/05/05/os-x-tutorial-a-menu-bar-app/</guid>
        <pubDate>Tue, 05 May 2015 00:00:00 +0200</pubDate>
        <description>&lt;p&gt;&lt;a href=&quot;/2013/07/01/simple-menu-bar-apps-for-os-x/&quot;&gt;My post about making Simple Menu Bar Apps for OS X&lt;/a&gt; has been one of the most viewed pages on my site since I wrote it back almost 2 years ago. It was never a complete tutorial to begin with, more of a few tips and tricks of how to do it well and a link to an example app I had written.&lt;/p&gt;

&lt;p&gt;Since then, Apple has released Yosemite, which changes the way the menu bar APIs work and makes showing custom views in a popover in place of a simple menu much easier. Also, as you probbaly know, we have a &lt;a href=&quot;https://developer.apple.com/swift/&quot;&gt;brand new language&lt;/a&gt; to write OS X apps with.&lt;/p&gt;

&lt;p&gt;My tutorial was due an update, so I pitched the idea of writing a complete menu bar app for OS X tutorial to Ray, &lt;a href=&quot;http://www.raywenderlich.com/u/kmikael&quot;&gt;for whom I have been updating tutorials for iOS 8 and Swift&lt;/a&gt; and he liked it.&lt;/p&gt;

&lt;p&gt;Check out the tutorial at &lt;a href=&quot;http://www.raywenderlich.com/98178/os-x-tutorial-menus-popovers-menu-bar-apps&quot;&gt;raywenderlich.com&lt;/a&gt;. I show you how to build a complete menu bar app that shows inspiratinal quotes in a popover.&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>Modeling Shapes in Swift</title>
        <link>http://kmikael.com/2014/08/09/modeling-shapes-in-swift/</link>
        <guid isPermaLink="true">http://kmikael.com/2014/08/09/modeling-shapes-in-swift/</guid>
        <pubDate>Sat, 09 Aug 2014 14:21:21 +0200</pubDate>
        <description>&lt;p&gt;A few friends and I were talking about functional programming vs. object oriented programming the other day and I decided to illustrate the concepts in Swift using a simple and classic example. Consider a shape model. There will be different shapes and we want to calculate each shape’s perimeter and area.&lt;/p&gt;

&lt;p&gt;An object oriented programmer might write it like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;let pi = 3.14159265358979323846264338327950288

class Shape {
    func perimeter() -&amp;gt; Double {
        return 0.0
    }

    func area() -&amp;gt; Double {
        return 0.0
    }
}

class Circle: Shape {
    let radius: Double

    init(radius: Double) {
        self.radius = radius
    }

    override func perimeter() -&amp;gt; Double {
        return 2.0 * pi * radius
    }

    override func area() -&amp;gt; Double {
        return pi * radius * radius
    }
}

class Rect: Shape {
    let width: Double
    let height: Double

    init(width: Double, height: Double) {
        self.width = width
        self.height = height
    }

    override func perimeter() -&amp;gt; Double {
        return 2.0 * (width + height)
    }

    override func area() -&amp;gt; Double {
        return width * height
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And then use it like so:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;let shapes = [
    Circle(radius: 1.0),
    Rect(width: 3.0, height: 4.0)
]

let perimeters = shapes.map { shape in shape.perimeter() }
let areas = shapes.map { shape in shape.area() }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Shape&lt;/code&gt; is an abstract superclass which declares the methods that subclasses should override.&lt;/p&gt;

&lt;p&gt;To add a new shape, we simply create a new class and then implement each of &lt;code class=&quot;highlighter-rouge&quot;&gt;Shape&lt;/code&gt;’s methods. To add a new computation, we first add a method to &lt;code class=&quot;highlighter-rouge&quot;&gt;Shape&lt;/code&gt;, returning a default value, followed by implementing the method appropriately in each subclass.&lt;/p&gt;

&lt;p&gt;In Swift, a very similar solution would be to use a protocol instead of an abstract superclass. This has the advantage that any existing class can be made into a shape and we can mix and match classes and structs if need arises. What we lose is the ability to have methods in the superclass that use the subclass methods to perform additional work, as Swift protocols cannot have default implementations.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;let pi = 3.14159265358979323846264338327950288

protocol Shape {
    func surface() -&amp;gt; Double
    func area() -&amp;gt; Double
}

class Circle: Shape {
    let radius: Double

    init(radius: Double) {
        self.radius = radius
    }

    func surface() -&amp;gt; Double {
        return 2.0 * pi * radius
    }

    func area() -&amp;gt; Double {
        return pi * radius * radius
    }
}

class Rect: Shape {
    let width: Double
    let height: Double

    init(width: Double, height: Double) {
        self.width = width
        self.height = height
    }

    func surface() -&amp;gt; Double {
        return 2.0 * (width + height)
    }

    func area() -&amp;gt; Double {
        return width * height
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A functional programmer might solve the problem like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;let pi = 3.14159265358979323846264338327950288

enum Shape {
    case Circle(Double)
    case Rect(Double, Double)
}

func perimeter(shape: Shape) -&amp;gt; Double {
    switch shape {
    case let .Circle(r):
        return 2.0 * pi * r
    case let .Rect(width, height):
        return 2.0 * (width + height)
    }
}

func area(shape: Shape) -&amp;gt; Double {
    switch shape {
    case let .Circle(r):
        return pi * r * r
    case let .Rect(width, height):
        return width * height
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And then use the constructs like so:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;let shapes = [
    Shape.Circle(1.0),
    Shape.Rect(3.0, 4.0)
]

let perimeters = shapes.map { shape in perimeter(shape) }
let areas = shapes.map { shape in area(shape) }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here, we use an &lt;a href=&quot;http://en.wikipedia.org/wiki/Algebraic_data_type&quot;&gt;algebraic data type&lt;/a&gt;. Then in each function, we pattern match on the shape, returning the appropriate value.&lt;/p&gt;

&lt;p&gt;In this case, to add a new shape, we simply add a new case to the &lt;code class=&quot;highlighter-rouge&quot;&gt;Shape&lt;/code&gt; enum and then add a case for that new shape to each function. To add a new computation, we add a new function, pattern match on the shape and return the appropriate value.&lt;/p&gt;

&lt;p&gt;Additionally, Swift allows &lt;code class=&quot;highlighter-rouge&quot;&gt;enum&lt;/code&gt;’s to have methods so it gives us the convenience of defining all the computations in a single context while keeping the code in a functional style.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;let pi = 3.14159265358979323846264338327950288

enum Shape {
    case Circle(Double)
    case Rect(Double, Double)

    func perimeter() -&amp;gt; Double {
        switch self {
        case let Circle(r):
            return 2.0 * pi * r
        case let Rect(width, height):
            return 2.0 * (width + height)
        }
    }

    func area() -&amp;gt; Double {
        switch self {
        case let Circle(r):
            return pi * r * r
        case let Rect(width, height):
            return width * height
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is basically the same as the functional example, but instead of having top level functions, all computations are nicely inside the &lt;code class=&quot;highlighter-rouge&quot;&gt;Shape&lt;/code&gt; enum. And the usage is exactly the same as the object oriented case:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;let shapes = [
    Shape.Circle(1.0),
    Shape.Rect(3.0, 4.0)
]

let perimeters = shapes.map { shape in shape.perimeter() }
let areas = shapes.map { shape in shape.area() }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The main disadvantage of this setup is that it’s now very difficult and inelegant to have specific functions that only operate on a specific shape. In the object-oriented style, we could just add methods to the &lt;code class=&quot;highlighter-rouge&quot;&gt;Circle&lt;/code&gt; class for example, and in the functional case we could write functions that take a &lt;code class=&quot;highlighter-rouge&quot;&gt;Circle&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Like most things there is no correct answer here. It’s really nice that Swift provides many options.&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>Swift Type Conversions</title>
        <link>http://kmikael.com/2014/06/22/swift-type-conversions/</link>
        <guid isPermaLink="true">http://kmikael.com/2014/06/22/swift-type-conversions/</guid>
        <pubDate>Sun, 22 Jun 2014 19:54:17 +0200</pubDate>
        <description>&lt;p&gt;In Swift, the native &lt;code class=&quot;highlighter-rouge&quot;&gt;String&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;Array&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;Dictionary&lt;/code&gt; types are implicitly bridged to the &lt;code class=&quot;highlighter-rouge&quot;&gt;Foundation&lt;/code&gt; classes &lt;code class=&quot;highlighter-rouge&quot;&gt;NSString&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;NSArray&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;NSDictionary&lt;/code&gt;. In practice, this means that any Cocoa API we call that takes a &lt;code class=&quot;highlighter-rouge&quot;&gt;Foundation&lt;/code&gt; class can take the corresponding Swift type (I don’t say class here, because in Swift, &lt;code class=&quot;highlighter-rouge&quot;&gt;String&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;Array&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;Dictionary&lt;/code&gt; are structs).&lt;/p&gt;

&lt;p&gt;It turns out that like many other things in Swift, this isn’t some language magic that only Apple gets to use. We can also build such implicit bridges, thanks to an undocumented Swift feature: The &lt;code class=&quot;highlighter-rouge&quot;&gt;__conversion&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Let’s say we want to build a &lt;code class=&quot;highlighter-rouge&quot;&gt;Point&lt;/code&gt; structure. We will be using it in a context that doesn’t involve Core Graphics, Sprite Kit or a similar framework that already uses &lt;code class=&quot;highlighter-rouge&quot;&gt;CGPoint&lt;/code&gt;. In addition, we want to build the struct in a modern way using new features idioms like generics and tuples. But, we also want to use our new struct with Core Graphics APIs sometimes so we can take advantage of all the convenience functions we implemented (This is a contrived example, because points are so simple, but bear with me).&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;struct Point {
    let x: Double, y: Double
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Let’s define the implicit bridging in an extension:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;extension Point {
    func __conversion() -&amp;gt; CGPoint {
        return CGPoint(x: x, y: y)
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now it’s possible to pass a &lt;code class=&quot;highlighter-rouge&quot;&gt;Point&lt;/code&gt; to any method or function that takes a &lt;code class=&quot;highlighter-rouge&quot;&gt;CGPoint&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;let p = Point(x: 1.0, y: 1.0)
CGPointApplyAffineTransform(p, CGAffineTransformMakeRotation(M_PI))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The extension can even be defined in a different file in the context where we want to use &lt;code class=&quot;highlighter-rouge&quot;&gt;Point&lt;/code&gt; as a &lt;code class=&quot;highlighter-rouge&quot;&gt;CGPoint&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We can also overload the &lt;code class=&quot;highlighter-rouge&quot;&gt;__conversion&lt;/code&gt; function and define many different conversions. Here’s one that destructures &lt;code class=&quot;highlighter-rouge&quot;&gt;Point&lt;/code&gt; into a &lt;code class=&quot;highlighter-rouge&quot;&gt;(Double, Double)&lt;/code&gt; tuple.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;extension Point {
    func __conversion() -&amp;gt; (Double, Double) {
        return (x, y)
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now this works!&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;let (x, y) = p
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I believe this will come in handy, especially when we start writing more and more Swift and we want to isolate non-Swift and/or legacy API calls and classes.&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>BOOL</title>
        <link>http://kmikael.com/2013/11/13/bool/</link>
        <guid isPermaLink="true">http://kmikael.com/2013/11/13/bool/</guid>
        <pubDate>Wed, 13 Nov 2013 23:03:41 +0200</pubDate>
        <description>&lt;p&gt;I recently bought the &lt;a href=&quot;https://gumroad.com/l/nshipster&quot;&gt;NSHipster book&lt;/a&gt; and was rereading &lt;a href=&quot;http://nshipster.com/bool/&quot;&gt;BOOL / bool / Boolean / NSCFBoolean&lt;/a&gt; and noticed the part where &lt;a href=&quot;https://twitter.com/mattt&quot;&gt;Mattt&lt;/a&gt; explains how comparing with &lt;code class=&quot;highlighter-rouge&quot;&gt;YES&lt;/code&gt; can be dangerous, because &lt;code class=&quot;highlighter-rouge&quot;&gt;BOOL&lt;/code&gt; is a &lt;code class=&quot;highlighter-rouge&quot;&gt;typedef&lt;/code&gt; of &lt;code class=&quot;highlighter-rouge&quot;&gt;signed char&lt;/code&gt;. I remembered that on 64-bit devices &lt;code class=&quot;highlighter-rouge&quot;&gt;BOOL&lt;/code&gt; is actually a &lt;code class=&quot;highlighter-rouge&quot;&gt;typedef&lt;/code&gt; of &lt;code class=&quot;highlighter-rouge&quot;&gt;bool&lt;/code&gt;, the native (as of C99) boolean type.&lt;/p&gt;

&lt;p&gt;The intersting thing is that the native &lt;code class=&quot;highlighter-rouge&quot;&gt;bool&lt;/code&gt; type is safe, safe in the sence that a variable typed as &lt;code class=&quot;highlighter-rouge&quot;&gt;bool&lt;/code&gt; can only ever have the values &lt;code class=&quot;highlighter-rouge&quot;&gt;0&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;1&lt;/code&gt;. So&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;BOOL value = 5;
NSLog(@&quot;%d&quot;, value);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;prints &lt;code class=&quot;highlighter-rouge&quot;&gt;5&lt;/code&gt; on all iPhone’s except for the iPhone 5s, where it prints &lt;code class=&quot;highlighter-rouge&quot;&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Also e.g. &lt;code class=&quot;highlighter-rouge&quot;&gt;(BOOL)5&lt;/code&gt; is &lt;code class=&quot;highlighter-rouge&quot;&gt;1&lt;/code&gt; on 64-bit devices, getting rid of the awkward &lt;code class=&quot;highlighter-rouge&quot;&gt;!!&lt;/code&gt; pattern to safely cast other types into booleans.&lt;/p&gt;

&lt;p&gt;Even so, you probably shouldn’t compare boolean expressions with &lt;code class=&quot;highlighter-rouge&quot;&gt;YES&lt;/code&gt;, but at least you will get the expected result on 64-bit devices going forward, as functions or methods returning &lt;code class=&quot;highlighter-rouge&quot;&gt;BOOL&lt;/code&gt; will always return &lt;code class=&quot;highlighter-rouge&quot;&gt;0&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;1&lt;/code&gt;.&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>Making Simple Menu Bar Apps for OS X</title>
        <link>http://kmikael.com/2013/07/01/simple-menu-bar-apps-for-os-x/</link>
        <guid isPermaLink="true">http://kmikael.com/2013/07/01/simple-menu-bar-apps-for-os-x/</guid>
        <pubDate>Mon, 01 Jul 2013 15:01:17 +0200</pubDate>
        <description>&lt;p&gt;&lt;strong&gt;Update 05 May 2015:&lt;/strong&gt; I have written &lt;a href=&quot;/2015/05/05/os-x-tutorial-a-menu-bar-app/&quot;&gt;an updated, more in depth tutorial&lt;/a&gt; on how to make a menu bar app on OS X 10.10 Yosemite and with Swift.&lt;/p&gt;

&lt;p&gt;It’s pretty easy to make a simple menu bar app on OS X. The main thing you need to do is to create an &lt;code class=&quot;highlighter-rouge&quot;&gt;NSStatusItem&lt;/code&gt; instance variable in your app delegate. To do this, you ask &lt;code class=&quot;highlighter-rouge&quot;&gt;[NSStatusBar systemStatusBar]&lt;/code&gt; to create one for you, providing a &lt;code class=&quot;highlighter-rouge&quot;&gt;length&lt;/code&gt;. In almost every case you will want to use &lt;code class=&quot;highlighter-rouge&quot;&gt;NSVariableStatusItemLength&lt;/code&gt; instead of some fixed &lt;code class=&quot;highlighter-rouge&quot;&gt;float&lt;/code&gt; value. Once you have an &lt;code class=&quot;highlighter-rouge&quot;&gt;NSStatusItem&lt;/code&gt;, you can configure it using it’s properties. I used some of the most relevant ones below:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-objective-c&quot; data-lang=&quot;objective-c&quot;&gt;@interface KMAppDelegate : NSObject &amp;lt;NSApplicationDelegate&amp;gt;

@property (strong, nonatomic) NSStatusItem *statusItem;
    
@end&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-objective-c&quot; data-lang=&quot;objective-c&quot;&gt;_statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];

// The text that will be shown in the menu bar
_statusItem.title = @&quot;&quot;;

// The image that will be shown in the menu bar, a 16x16 black png works best
_statusItem.image = [NSImage imageNamed:@&quot;feedbin-logo&quot;];

// The highlighted image, use a white version of the normal image
_statusItem.alternateImage = [NSImage imageNamed:@&quot;feedbin-logo-alt&quot;];

// The image gets a blue background when the item is selected
_statusItem.highlightMode = YES;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Next, you will want something to happen when the status item is clicked. You have a few options here: You can have a menu be shown, you can configure a target-action pair and use the status item like a button or you can have a custom view be shown. See &lt;a href=&quot;https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSStatusItem_Class/Reference/Reference.html&quot;&gt;the documentation&lt;/a&gt; for all the details. Here, we use a simple menu and attach it to the status item.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-objective-c&quot; data-lang=&quot;objective-c&quot;&gt;NSMenu *menu = [[NSMenu alloc] init];
[menu addItemWithTitle:@&quot;Open Feedbin&quot; action:@selector(openFeedbin:) keyEquivalent:@&quot;&quot;];
[menu addItemWithTitle:@&quot;Refresh&quot; action:@selector(getUnreadEntries:) keyEquivalent:@&quot;&quot;];

if ([[[KMFeedbinCredentialStorage sharedCredentialStorage] credential] hasPassword]) {
    [menu addItemWithTitle:@&quot;Log Out&quot; action:@selector(logOut:) keyEquivalent:@&quot;&quot;];
} else {
    [menu addItemWithTitle:@&quot;Log In&quot; action:@selector(logIn:) keyEquivalent:@&quot;&quot;];
}

[menu addItem:[NSMenuItem separatorItem]]; // A thin grey line
[menu addItemWithTitle:@&quot;Quit Feedbin Notifier&quot; action:@selector(terminate:) keyEquivalent:@&quot;&quot;];
_statusItem.menu = menu;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The rest is all up to you. You can pretty much set up a simple app that connects to a web service and shows some information in an hour or two.&lt;/p&gt;

&lt;p&gt;Note that you will probably want to have the app not show up in the dock. To do this you need to set the &lt;code class=&quot;highlighter-rouge&quot;&gt;LSUIElement&lt;/code&gt; key to &lt;code class=&quot;highlighter-rouge&quot;&gt;YES&lt;/code&gt; in your &lt;code class=&quot;highlighter-rouge&quot;&gt;Info.plist&lt;/code&gt; configuration file. You should see &lt;em&gt;Application is agent (UIElement)&lt;/em&gt; set to &lt;em&gt;YES&lt;/em&gt; if you have done it correctly.&lt;/p&gt;

&lt;p&gt;The sample code I used is an app I wrote to show me the number of unread RSS items in my &lt;a href=&quot;https://feedbin.me&quot;&gt;Feedbin&lt;/a&gt; account. You can check it out &lt;a href=&quot;https://github.com/kmikael/FeedbinNotifier&quot;&gt;on GithHub&lt;/a&gt;. It pretty much creates a status item in the app delegate and then refreshes the unread count every two minutes using an &lt;code class=&quot;highlighter-rouge&quot;&gt;NSTimer&lt;/code&gt;. Before that, it asks the user to log in and then saves the user’s password in the system keychain, so there are a few helper classes in addition to the app delegate. The whole app is comprised of a mere 202 lines of Objective-C code according to &lt;a href=&quot;http://cloc.sourceforge.net&quot;&gt;cloc&lt;/a&gt;.&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>Creating Static Sites in Ruby with Rack</title>
        <link>http://kmikael.com/2013/05/28/creating-static-sites-in-ruby-with-rack/</link>
        <guid isPermaLink="true">http://kmikael.com/2013/05/28/creating-static-sites-in-ruby-with-rack/</guid>
        <pubDate>Tue, 28 May 2013 18:12:45 +0200</pubDate>
        <description>&lt;p&gt;There is a guide for creating static sites with rack &lt;a href=&quot;https://devcenter.heroku.com/articles/static-sites-ruby&quot;&gt;on the heroku dev center&lt;/a&gt;, it works ok, but it has a few problems. After creating a few static sites and deploying them to heroku and taking different approaches each time, some simple, some complex, I decided to investigate the issue.&lt;/p&gt;

&lt;p&gt;Here is the code that you might find in a lot of places around the web, including the aforementioned article:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Rack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Static&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
  &lt;span class=&quot;ss&quot;&gt;:urls&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;s2&quot;&gt;&quot;/images&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/js&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/css&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;ss&quot;&gt;:root&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;public&quot;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;lambda&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;env&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;mi&quot;&gt;200&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;s1&quot;&gt;'Content-Type'&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'text/html'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
      &lt;span class=&quot;s1&quot;&gt;'Cache-Control'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'public, max-age=86400'&lt;/span&gt; 
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'public/index.html'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;RDONLY&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;/figure&gt;

&lt;p&gt;Firstly, &lt;code class=&quot;highlighter-rouge&quot;&gt;urls&lt;/code&gt; can get pretty long and you mostly want to serve all files in &lt;code class=&quot;highlighter-rouge&quot;&gt;public&lt;/code&gt; anyway, but the main issue is that all requests that don’t correspond to a file will take you to &lt;code class=&quot;highlighter-rouge&quot;&gt;index.html&lt;/code&gt;, the home page. Also, you don’t really want &lt;code class=&quot;highlighter-rouge&quot;&gt;.html&lt;/code&gt; displaying in your urls and using &lt;code class=&quot;highlighter-rouge&quot;&gt;File.open&lt;/code&gt; in the body doesn’t take advantage of all the headers that &lt;code class=&quot;highlighter-rouge&quot;&gt;Rack::Static&lt;/code&gt; and threfore &lt;code class=&quot;highlighter-rouge&quot;&gt;Rack::File&lt;/code&gt; will set for you.&lt;/p&gt;

&lt;p&gt;Here’s my approach. I use &lt;code class=&quot;highlighter-rouge&quot;&gt;Rack::Static&lt;/code&gt; like so:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Rack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Static&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;ss&quot;&gt;:urls&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Dir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/*&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&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;fn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;gsub&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)},&lt;/span&gt;
  &lt;span class=&quot;ss&quot;&gt;:root&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;ss&quot;&gt;:index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'index.html'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;ss&quot;&gt;:header_rules&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;ss&quot;&gt;:all&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;s1&quot;&gt;'Cache-Control'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'public, max-age=3600'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}]]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;We get all the files in &lt;code class=&quot;highlighter-rouge&quot;&gt;root&lt;/code&gt;, set an &lt;code class=&quot;highlighter-rouge&quot;&gt;index&lt;/code&gt;, which will serve e.g. &lt;code class=&quot;highlighter-rouge&quot;&gt;about/index.html&lt;/code&gt; when you get &lt;code class=&quot;highlighter-rouge&quot;&gt;about/&lt;/code&gt; (so it also takes care of serving &lt;code class=&quot;highlighter-rouge&quot;&gt;/index.html&lt;/code&gt; when we get &lt;code class=&quot;highlighter-rouge&quot;&gt;'/'&lt;/code&gt;, the root) and set the &lt;code class=&quot;highlighter-rouge&quot;&gt;'Cache-Control'&lt;/code&gt; header to an hour for all files.&lt;/p&gt;

&lt;p&gt;After this we need to run a &lt;code class=&quot;highlighter-rouge&quot;&gt;rack&lt;/code&gt; app. We should probably return a &lt;code class=&quot;highlighter-rouge&quot;&gt;404&lt;/code&gt; page now, as none of the files will have been matched.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;headers&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;s1&quot;&gt;'Content-Type'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'text/html'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Content-Length'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'9'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;lambda&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;env&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;mi&quot;&gt;404&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&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;s1&quot;&gt;'Not Found'&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;/figure&gt;

&lt;p&gt;I refactored this code into a tiny gem, so I can use it directly in all my projects. I called it &lt;a href=&quot;https://github.com/kmikael/vienna&quot;&gt;vienna&lt;/a&gt;. Now you can create a static site on heroku by putting these two lines into your &lt;code class=&quot;highlighter-rouge&quot;&gt;config.ru&lt;/code&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'vienna'&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Vienna&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;(And I won’t have to write any more &lt;code class=&quot;highlighter-rouge&quot;&gt;Rack::Static&lt;/code&gt; code again.)&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;vienna&lt;/code&gt; will also serve a &lt;code class=&quot;highlighter-rouge&quot;&gt;404.html&lt;/code&gt; if it exists, instead of just returning &lt;code class=&quot;highlighter-rouge&quot;&gt;'Not Found'&lt;/code&gt; when a file isn’t found. &lt;a href=&quot;https://github.com/kmikael/vienna/blob/master/lib/vienna.rb&quot;&gt;Check out the source&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.pinbrowser.co&quot;&gt;pinbrowser.co&lt;/a&gt; runs on &lt;code class=&quot;highlighter-rouge&quot;&gt;vienna&lt;/code&gt; now and I’ve also tested this site that is powered by &lt;code class=&quot;highlighter-rouge&quot;&gt;Jekyll&lt;/code&gt; with &lt;code class=&quot;highlighter-rouge&quot;&gt;vienna&lt;/code&gt;, even though I’m hosting it on GitHub Pages instead of heroku. it works great.&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>Hello, Jekyll</title>
        <link>http://kmikael.com/2013/05/24/hello-jekyll/</link>
        <guid isPermaLink="true">http://kmikael.com/2013/05/24/hello-jekyll/</guid>
        <pubDate>Fri, 24 May 2013 14:52:10 +0200</pubDate>
        <description>&lt;p&gt;I’m launching this site today. It’s a static site built with &lt;a href=&quot;http://jekyllrb.com&quot;&gt;Jekyll&lt;/a&gt; and the color scheme and choice of fonts has been havily inspired by &lt;a href=&quot;https://github.com/orderedlist/minimal&quot;&gt;orderedlist’s minimal theme&lt;/a&gt;. I’m not going to talk about building a site with Jekyll, because the newly launched &lt;a href=&quot;http://jekyllrb.com&quot;&gt;official site&lt;/a&gt; does an excellent job at that, but I am going to talk about a few problems I had along the way and a few things you can do to improve your Jekyll workflow.&lt;/p&gt;

&lt;h2 id=&quot;use-a-rakefile&quot;&gt;Use a Rakefile&lt;/h2&gt;

&lt;p&gt;It gets boring to type &lt;code class=&quot;highlighter-rouge&quot;&gt;jekyll serve --watch&lt;/code&gt; and to create new files named &lt;code class=&quot;highlighter-rouge&quot;&gt;2013-05-24-hello-jekyll.md&lt;/code&gt; really fast. A few &lt;code class=&quot;highlighter-rouge&quot;&gt;rake&lt;/code&gt; tasks can significantly speed things up. This is what mine looks like:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:default&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;ss&quot;&gt;:serve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;desc&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Build and watch the site'&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:build&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;system&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'jekyll build --watch'&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;desc&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Serve and watch the site'&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:serve&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;system&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'jekyll serve --watch'&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;desc&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Create a new post'&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:post&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;date&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;new&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;title&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;STDIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;gets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;chomp&lt;/span&gt;
  
  &lt;span class=&quot;n&quot;&gt;content&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;gsub&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/^ +/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
    ---
    layout: post
    date: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;strftime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'%Y-%m-%d %H:%M:%S'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
    title: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
    ---
    
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;  EOS&lt;/span&gt;
  
  &lt;span class=&quot;n&quot;&gt;datef&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;strftime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'%Y-%m-%d'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;titlef&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;downcase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;gsub&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;' '&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'-'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;_posts/&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;datef&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;titlef&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.md&quot;&lt;/span&gt;
  
  &lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;write&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;content&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;use-rdiscount-or-redcarpet&quot;&gt;Use rdiscount or redcarpet&lt;/h2&gt;

&lt;p&gt;The default markdown parser &lt;code class=&quot;highlighter-rouge&quot;&gt;maruku&lt;/code&gt; works fine most of the time but I’ve run into a few problems like getting an &lt;code class=&quot;highlighter-rouge&quot;&gt;REXML could not parse this XML/HTML&lt;/code&gt; error when I try to highlight Objective-C code. Switch to &lt;code class=&quot;highlighter-rouge&quot;&gt;rdiscount&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;redcarpet&lt;/code&gt; and the error goes away. Just add &lt;code class=&quot;highlighter-rouge&quot;&gt;markdown: redcarpet&lt;/code&gt; to your cofiguration file.&lt;/p&gt;

&lt;h2 id=&quot;pretty-permalinks&quot;&gt;Pretty Permalinks&lt;/h2&gt;

&lt;p&gt;Add &lt;code class=&quot;highlighter-rouge&quot;&gt;permalink: pretty&lt;/code&gt; to your configuration file if you want posts to be served from &lt;code class=&quot;highlighter-rouge&quot;&gt;/2013/05/24/hello-jekyll/&lt;/code&gt; instead of &lt;code class=&quot;highlighter-rouge&quot;&gt;/2013/05/24/hello-jekyll.html&lt;/code&gt;. This also affects pages, so &lt;code class=&quot;highlighter-rouge&quot;&gt;about.html&lt;/code&gt; will be available at &lt;code class=&quot;highlighter-rouge&quot;&gt;/about/&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;using-pow&quot;&gt;Using Pow&lt;/h2&gt;

&lt;p&gt;If you want to use the &lt;code class=&quot;highlighter-rouge&quot;&gt;rack&lt;/code&gt; server &lt;a href=&quot;http://pow.cx&quot;&gt;pow&lt;/a&gt;, build your site into &lt;code class=&quot;highlighter-rouge&quot;&gt;public&lt;/code&gt; instead of &lt;code class=&quot;highlighter-rouge&quot;&gt;_site&lt;/code&gt;, because &lt;code class=&quot;highlighter-rouge&quot;&gt;pow&lt;/code&gt; automatically serves everything in &lt;code class=&quot;highlighter-rouge&quot;&gt;public&lt;/code&gt; as static assets.&lt;/p&gt;

&lt;h2 id=&quot;an-rss-feed&quot;&gt;An RSS Feed&lt;/h2&gt;

&lt;p&gt;You’ll probably want to have an RSS feed for your site, I’ve described how I built one &lt;a href=&quot;/2013/05/23/adding-an-rss-feed-to-a-jekyll-site/&quot;&gt;in a seperate post&lt;/a&gt;.&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>Adding An RSS Feed to a Jekyll Site</title>
        <link>http://kmikael.com/2013/05/23/adding-an-rss-feed-to-a-jekyll-site/</link>
        <guid isPermaLink="true">http://kmikael.com/2013/05/23/adding-an-rss-feed-to-a-jekyll-site/</guid>
        <pubDate>Thu, 23 May 2013 00:00:00 +0200</pubDate>
        <description>&lt;p&gt;Adding an RSS 2.0 feed to a Jekyll site is actually pretty simple.&lt;/p&gt;

&lt;p&gt;First the required &lt;em&gt;header&lt;/em&gt; and &lt;em&gt;footer&lt;/em&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;rss&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;version=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;2.0&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xmlns:atom=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.w3.org/2005/Atom&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;channel&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;atom:link&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;href=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{{ site.url }}/feed.xml&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;rel=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;self&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;application/rss+xml&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;{{ site.name }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;link&amp;gt;&lt;/span&gt;{{ site.url }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/link&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;description&amp;gt;&lt;/span&gt;{{ site.description }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/channel&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/rss&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Don’t forget to add a &lt;em&gt;name&lt;/em&gt;, &lt;em&gt;url&lt;/em&gt; and &lt;em&gt;description&lt;/em&gt; to your configuration file.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot; data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;na&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://kmikael.com&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Mikael Konutgan&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Thoughts&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;programming,&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Unix&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;and&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;technology'&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;We’ve got our XML boilerplate and then in the &lt;code class=&quot;highlighter-rouge&quot;&gt;channel&lt;/code&gt; we need to add a &lt;code class=&quot;highlighter-rouge&quot;&gt;title&lt;/code&gt;, a &lt;code class=&quot;highlighter-rouge&quot;&gt;link&lt;/code&gt; and a &lt;code class=&quot;highlighter-rouge&quot;&gt;description&lt;/code&gt;. The &lt;code class=&quot;highlighter-rouge&quot;&gt;channel&lt;/code&gt; elements also has &lt;a href=&quot;http://feed2.w3.org/docs/rss2.html#optionalChannelElements&quot;&gt;a few optional elements&lt;/a&gt;, which I haven’t included here.&lt;/p&gt;

&lt;p&gt;The next step is to add the &lt;code class=&quot;highlighter-rouge&quot;&gt;item&lt;/code&gt;’s. We iterate over the 20 latest posts and add them. Each &lt;code class=&quot;highlighter-rouge&quot;&gt;item&lt;/code&gt; has a &lt;code class=&quot;highlighter-rouge&quot;&gt;title&lt;/code&gt;, a &lt;code class=&quot;highlighter-rouge&quot;&gt;link&lt;/code&gt; a &lt;code class=&quot;highlighter-rouge&quot;&gt;guid&lt;/code&gt; (globally unique identifier), a &lt;code class=&quot;highlighter-rouge&quot;&gt;pupDate&lt;/code&gt; and a &lt;code class=&quot;highlighter-rouge&quot;&gt;description&lt;/code&gt;. The &lt;code class=&quot;highlighter-rouge&quot;&gt;guid&lt;/code&gt; can be any string, here I just set it to the link of the post. &lt;a href=&quot;http://feed2.w3.org/docs/rss2.html#ltguidgtSubelementOfLtitemgt&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;isPermaLink=&quot;true&quot;&lt;/code&gt; tells feed readers that they can assume the &lt;code class=&quot;highlighter-rouge&quot;&gt;guid&lt;/code&gt; is a permalink&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Actually non of these are required, it’s the most minimal approach that makes sense in my opinion. &lt;a href=&quot;http://feed2.w3.org/docs/rss2.html#hrelementsOfLtitemgt&quot;&gt;To quote the spec&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;An item may also be complete in itself, if so, the description contains the text (entity-encoded HTML is allowed), and the link and title may be omitted. All elements of an item are optional, however at least one of title or description must be present.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We use the &lt;code class=&quot;highlighter-rouge&quot;&gt;date_to_rfc822&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;xml_escape&lt;/code&gt; filters Jekyll adds to Liquid to comply with &lt;a href=&quot;http://feed2.w3.org/docs/rss2.html#ltpubdategtSubelementOfLtitemgt&quot;&gt;the specification&lt;/a&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;{% for post in site.posts limit:20 %}
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;item&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;{{ post.title }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;link&amp;gt;&lt;/span&gt;{{ site.url }}{{ post.url }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/link&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;guid&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;isPermaLink=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;{{ site.url }}{{ post.url }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/guid&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;pubDate&amp;gt;&lt;/span&gt;{{ post.date | date_to_rfc822 }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/pubDate&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;description&amp;gt;&lt;/span&gt;{{ post.content | xml_escape }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/item&amp;gt;&lt;/span&gt;
{% endfor %}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;After we add the YAML front-matter, so Liquid will process our file, the end result looks like this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;---
layout: nil
---

&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;rss&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;version=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;2.0&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;channel&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Mikael Konutgan&lt;span class=&quot;nt&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;link&amp;gt;&lt;/span&gt;{{ site.url }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/link&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;description&amp;gt;&lt;/span&gt;Thoughts on programming and technology&lt;span class=&quot;nt&quot;&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
    {% for post in site.posts limit:20 %}
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;item&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;{{ post.title }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;link&amp;gt;&lt;/span&gt;{{ site.url }}{{ post.url }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/link&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;guid&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;isPermaLink=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;{{ site.url }}{{ post.url }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/guid&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;pubDate&amp;gt;&lt;/span&gt;{{ post.date | date_to_rfc822 }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/pubDate&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;description&amp;gt;&lt;/span&gt;{{ post.content | xml_escape }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;/item&amp;gt;&lt;/span&gt;
    {% endfor %}
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/channel&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/rss&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;See &lt;a href=&quot;http://feed2.w3.org/docs/rss2.html&quot;&gt;the RSS 2.0 specification&lt;/a&gt; for all of the details and optional elements and &lt;a href=&quot;http://validator.w3.org/feed/&quot;&gt;validate your feed&lt;/a&gt; when you’re done. Using the method above should produce a valid feed without warnings.&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>The Fish Shell</title>
        <link>http://kmikael.com/2013/05/22/the-fish-shell/</link>
        <guid isPermaLink="true">http://kmikael.com/2013/05/22/the-fish-shell/</guid>
        <pubDate>Wed, 22 May 2013 00:00:00 +0200</pubDate>
        <description>&lt;p&gt;I switched to the fish shell a while ago and it’s great. The sntax is sane and understandable, tab completions work pretty well, history completions save you a lot of time and my shell feels faster to me now.&lt;/p&gt;

&lt;p&gt;It’s super easy to create a custom shell prompt:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;function fish_prompt
  set_color red -o
  echo -n &quot;&amp;gt;&amp;gt; &quot;
  set_color cyan -o
  if test $PWD = $HOME
    echo -n &quot;~&quot;
  else
    echo -n (basename $PWD)
  end
  echo -n &quot; &quot;
  if git status &amp;gt;/dev/null ^/dev/null
    set_color red -o
    echo -n (git branch | grep '*' | cut -c3-)
    echo -n &quot; &quot;
    if not test (git status | tail -1) = &quot;nothing to commit, working directory clean&quot;
      set_color yellow -o
      echo -n &quot;× &quot;
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This displays the current working directory, then the current git branch if one exists, then an ×, if there are uncommitted changes in the git repository.&lt;/p&gt;

&lt;p&gt;My right prompt displays the ruby version currently in use&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;function fish_right_prompt
  set_color white -o
  rbenv version | cut -d ' ' -f 1
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;All you need to do is create two files, name them &lt;code class=&quot;highlighter-rouge&quot;&gt;fish_prompt.fish&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;fish_right_prompt.fish&lt;/code&gt; and place them in &lt;code class=&quot;highlighter-rouge&quot;&gt;~/.config/fish/functions&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Adding your own tab-completions is also pretty easy. Here’s a simple example:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;complete -f -c jekyll -a 'build doctor help import new serve'
complete -f -c jekyll -s w -l 'watch'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The first line will tab-complete jekyll’s &lt;code class=&quot;highlighter-rouge&quot;&gt;build&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;doctor&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;help&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;import&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;new&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;serve&lt;/code&gt; commands. The second line will complete the &lt;code class=&quot;highlighter-rouge&quot;&gt;-w&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;--watch&lt;/code&gt; option. Of course, Jekyll has many more commands and options and writing the whole thing would be much longer, but you get the idea. Put these lines in &lt;code class=&quot;highlighter-rouge&quot;&gt;.config/fish/completions&lt;/code&gt; into a file named &lt;code class=&quot;highlighter-rouge&quot;&gt;jekyll.fish&lt;/code&gt; and you’ll be good to go.&lt;/p&gt;

&lt;p&gt;I highly encourage you to at least read through &lt;a href=&quot;http://fishshell.com/tutorial.html&quot;&gt;the introductory fish tutorial&lt;/a&gt;.&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>Making Good-Looking Bar Buttons with Unicode</title>
        <link>http://kmikael.com/2013/05/21/making-good-looking-bar-button-items-with-unicode/</link>
        <guid isPermaLink="true">http://kmikael.com/2013/05/21/making-good-looking-bar-button-items-with-unicode/</guid>
        <pubDate>Tue, 21 May 2013 00:00:00 +0200</pubDate>
        <description>&lt;p&gt;The standard &lt;code class=&quot;highlighter-rouge&quot;&gt;UIBarButtonSystemItem&lt;/code&gt;’s are pretty limited and mostly boring, so we usually have to find a custom image and create a &lt;code class=&quot;highlighter-rouge&quot;&gt;UIBarButtonItem&lt;/code&gt; with &lt;code class=&quot;highlighter-rouge&quot;&gt;initWithImage:style:target:action:&lt;/code&gt;. This is, of course, great in most cases, except when you have limited resources and don’t want to have too many images in your bundle.&lt;/p&gt;

&lt;h2 id=&quot;unicode-to-the-rescue&quot;&gt;Unicode to the rescue&lt;/h2&gt;

&lt;p&gt;There are literally thousands of unicode characters available on iOS for you to use and it’s, for the most part, simple to use them. For the standard behavior, just use &lt;code class=&quot;highlighter-rouge&quot;&gt;initWithTitle:style:target:action:&lt;/code&gt; and set a unicode character as the title, but in cases where you need to customize the button even more, you could use something like this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-objective-c&quot; data-lang=&quot;objective-c&quot;&gt;UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0f, 0.0f, 32.0f, 32.0f);
[button setTitle:title forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:20.0f];
button.titleLabel.shadowColor = [UIColor blackColor];
button.titleLabel.shadowOffset = CGSizeMake(0.0f, -1.0f);
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
button.showsTouchWhenHighlighted = YES;
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;It’s that simple. Let’s refactor it into a category and add the ability to invert the unicode symbol, which is useful for creating butons with matching arrows.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-objective-c&quot; data-lang=&quot;objective-c&quot;&gt;@interface UIBarButtonItem (PBAdditions)

+ (UIBarButtonItem *)barButtonItemWithTitle:(NSString *)title
                                   inverted:(BOOL)inverted target:(id)target
                                     action:(SEL)action;
                                     
+ (UIBarButtonItem *)barButtonItemWithTitle:(NSString *)title
                                     target:(id)target
                                     action:(SEL)action;
                                     
@end

@implementation UIBarButtonItem (PBAdditions)

+ (UIBarButtonItem *)barButtonItemWithTitle:(NSString *)title
                                   inverted:(BOOL)inverted target:(id)target
                                     action:(SEL)action
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 32, 32);
    [button setTitle:title forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:20.0f];
    button.titleLabel.shadowColor = [UIColor blackColor];
    button.titleLabel.shadowOffset = CGSizeMake(0.0f, -1.0f);
    if (inverted) {
        button.titleLabel.transform = CGAffineTransformMakeRotation(M_PI);
    }
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    button.showsTouchWhenHighlighted = YES;
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    return barButtonItem;
}

+ (UIBarButtonItem *)barButtonItemWithTitle:(NSString *)title
                                     target:(id)target
                                     action:(SEL)action
{
    return [self barButtonItemWithTitle:title inverted:NO target:target action:action];
}

@end&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Here are a few ideas to get you started:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Settings (⚙)&lt;/li&gt;
  &lt;li&gt;Slide-out Menu (☰)&lt;/li&gt;
  &lt;li&gt;Forward button (➜) (invert the symbol for a back button)&lt;/li&gt;
  &lt;li&gt;Add/Cancel (✚, ✖)&lt;/li&gt;
  &lt;li&gt;Star/Unstar (★, ☆)&lt;/li&gt;
&lt;/ul&gt;
</description>
      </item>
    
  </channel>
</rss>
