Lonely Proton

Using Haml with Rails

I've started working on an API for my iOS app Ten Moves and for that I wanted an admin dashboard where I could quickly get an overview of the data served by the API.

I decided to build the backend using Ruby on Rails because I didn't feel like learning CloudKit and had some new practices I wanted to try.

One of them was using Haml. This is a small guide to getting Haml setup and an overview of the most important syntax.

Setup

Setup is super easy. Just add gem 'haml-rails' to you Gemfile and run bundle install.

Haml comes with erb baked in, so you don't need to include that in the filenames of your views. Just name them something like "index.haml".

Basic syntax

I find the syntax to be quite self explanatory:

%div.stats
  %h1 Stats
  %dl
    %dt
      Number of moves:
    %dd
      = @dashboard.total_moves_count

%div.top-list
  %h1 Top list
  %dl
  - if @dashboard.empty?
    There are no moves
  - else
    %ul
      - @dashboard.top_list.each do |move|
        %li{"data-id" => move.id}
          = move.name

Vim class snippet for Ruby on Rails

I remember watching an episode of The Weekly Iteration where Joe Ferris demoed a small Vim function he had written that would try to guess, based on the name of the current file and what folder it was, what the name of the class in that file should be.

Here is an example. Imagine you're in a Rails app in a file at app/controllers/users_controller.rb. If you ran this function or snippet it would insert:

class UsersController < ApplicationController
end

Just so you don't have to type that boilerplate yourself.

I have made a small snippet for UltiSnips that does the same thing. You just type "class" and hit tab and it expands into the name of the class that should be in that file. It works for app/models and app/controllers.

Here is the snippet:

global !p
def title(x):
  return x.title()

def class_name():
  path_components = path.split("/")
  basename = path_components[-1].replace(".rb", "")
  return "".join(map(title, basename.split(" "))).replace("_", "")

def inheritance():
  if "controller" in path:
    return " < ApplicationController"
  elif "model" in path:
    return " < ActiveRecord::Base"
  else:
    return ""
endglobal

snippet class "Class for current file" !b
`!p snip.rv = "class " + class_name() + inheritance() + "\n  \nend"`
endsnippet

As you can see it uses the Python interpolation feature of UltiSnips to run some Python that guesses the name of the class. I find this to much easier than writing all this out in Vimscript.

I have yet to figure out how to position the cursor in the block when the snippet is done though.

Initial iPhone 6 thoughts

After waiting in line for quite a while in Hamburg I was finally able to get my hands on an iPhone 6. Here are some of my initial thoughts and impressions. Keep in mind that my previous phone was the 5.

I also got to play around with the 6 plus in the Apple Store and it is indeed way to huge for me. Can hardly reach the home button.

Vim and Xcode

Xvim is a plugin for Xcode that adds Vim key bindings. I've used for a little over a week and its by far the best Vim emulation-plugin-thing I've ever seen for any text editor.

If you like Vim and are developing in Xcode then this is a most have.

How I am learning iOS development

For the past few weeks I've started getting into iOS development. Its something I have long wanted to do and now I finally have an idea for an app and enough time to sit down and figure out how the hell to actually write it.

So I thought it might be useful for someone out there in a similar situation to know how I'm approaching learning all this new cool stuff. So I've made a list.

1. Learn the language

First things first. If you have no experience programming then I would not advise you to start with iOS development. If I was you, and had no programming experience, then I would start with something like web development. Developing for the web is a lot easier to get started with and provides a good platform for learning concepts that'll become important later. I also don't think Objective-C is suitable for being someones first programming language.

If you however do have some programming experience then the first thing I think you should do is learn Objective-C. I think its wise to start learning Objective-C and not Swift because first all Objective-C isn't going away any time soon and there is already a lot of useful stuff written in it, and it would be a real shame if you couldn't understand it.

The Objective-C syntax is also quite different from most other languages that people are familiar with so you might actually enjoy learning a different language.

Lynda.com has a great course for learning Objective-C and it is how I got started.

2. Learn the basics of the platform

If you have experience with programming then learning Objective-C wont take much longer than a weekend. But that doesn't mean that you then know how to write iOS apps.

Creating apps is so much more than just the language. The hard part is learning all of Apple's frameworks.

For getting an introduction to the Cocoa Touch platform Lynda.com has another great course that helped me a lot.

Another course that I also found very helpful was their course on Core Data (A framework used for persisting data). In particular the chapter called "Putting it all together: iOS" was great. Here the author basically walks you through building a complete app from scratch. Good stuff.

3. Build something

Now its time for you get creative, get an idea for an app that you would like to exist and then build it. Try not to come up with something too complicated. I would recommend starting with some kind of list app (thats at least what I'm doing).

4. Research

That last thing you should be doing a lot is sucking up all the knowledge that you can possibly find. I've personally been filling my Instapaper queue with articles to read and videos to watch.

Here are some sites that I'm spending a lot of time on at the moment:

I hope this was helpful and I wish you all the best of luck.

Overcast

I've been waiting for Marco's podcast app to go live in months. Its finally here, and its awesome!

Swift InFlux

A list of things likely to change in Swift. I for one am very excited about this language.

Via Brent Simmons

Apple Pride

Apple supporting the gay community comes as no surprise to anyone.

A danish company would never do this. The amount of discrimination and in part also attention that gay people get are very less - but I guess it does make sense given the current state of the world, especially the US.

1Password for iOS 8

I think this the thing that gets me most excited about iOS 8 - the awesome extensions developers are gonna make.

This is a small preview of what an iOS 8 extension for 1Password might look like. Imagine not having to leave the browser to fill in a password, insanely great.

The Gunfighter

As you can see I have made some changes to the layout of the site and added linked list capabilities.

I first thing I'll link to is a hilarious short film about a gunfighter. You should go check it out.

← Archive