Lukas Z's Blog

NSHipster

I am currently having a good time programming an iOS app at my current project. While searching for information about a certain topic I’ve stumbled over NSHipster, written by Matt Thompson. The tagline reads: “NSHipster is a journal of the overlooked bits in Objective-C and Cocoa. Updated weekly.”

There’s great content there that I am recommending for every Objective-C programmer. In fact, I am putting it on my Bookmarks-page.

Oblique Strategies

In the 1970s two authors created a box of cards called “Oblique Strategies”. [1] They are supposed to help creative people (musicians) to break creative blocks. It works like this: You get stuck. You pull out a card from the box and ponder it’s meaning which hopefully will help you resolve your problem.

The suggestions are sometimes cryptic. But many suggest a change of perspective. [2] This is useful. Perhaps it is a good idea to start developing our own sets of cards, as well.

There is a website that will randomly give you one card from the original decks. [3] Try it out or read the whole list extracted from that website’s HTML:

  • (Organic) machinery

  • A line has two sides

Websocket-Chat With Rails 4

Couldn’t sleep last night, so I coded up a little web-app to get tired. It’s a simple chat that works with websockets with Rails and the websocket-rails gem.

It’s really not much, but if you want to see how to write such a thing, check out the Github repository.

Idea: A Kickstarter.com for Open Source Software

There’s software I’d like to have written. For example, a port of the Zenburn colorscheme [1] for Octopress. Or a real time map-matching algorithm in Ruby.[2] Or an up to date guide on securing a Linux webserver. And many things more.

I could of course sit down and tackle these problems one by one myself. But I’d run out of time. After all I have work for clients, my personal projects and everything that makes up my private life. So can’t others write it?

The open source software world is full of great things. Not just nice-to-have gimmicks, but truly essential software that often generates great value for startups and established companies. The days of Oracle and Microsoft licenses for libraries and developer tools are over. At least in the Web and mobile application world. [3]

But how much more could be developed and released for free if there was a way for open source devs to make a living from their contributions?

Sure, some do. An open source database can be financed by selling premium services such as hosting, teaching and tech-support. But many things, some small, but still significant, are made by individuals in their free time.

And then there’s Kickstarter.com which is spearheading a paradigm shift in how projects of all sizes can be financed online. Wouldn’t it be cool to have a site like this exclusively for open source software and related things? [4]

Let’s imagine how a site like this could work.

First, people could post requests of things they want to have developed. For example: “A streaming-webradio library written in Objective-C for use with iOS 6”.

Other people (and companies) could now vote to either express “Yes, I/we need this, too.” or they could agree it’s a worthwhile pursuit and say “Yes, and I am willing to pay 50USD to a developer who writes the software.”

At the same time developers could write responses like: “I can do this. It will take me one month and I want to be paid X dollars for it. I will develop it in this fashion: […insert implementation details here…]”

The idea is to not start a website where the cheapest developer wins, but rather someone who can layout his implementation idea and, possibly, back it up with references, such as his Github repository.

The users can then select which developer should be awarded the job. [5] After a developer is selected, a kickstarter-esque funding round begins. If the amount of Dollars is reached, the money is charged and put into escrow.

The money should be given to the developer in parts, for example as a weekly salary. Meanwhile others should be able to review his work. (And even join in to help him or her.)

If the project looks like it’s a failure it can be stopped, and the remaining funds can be transferred back to the backers. If it succeeds, the last payment goes to the developer.

The software (finished or not) is then released under an Open Source license.

I don’t know.. Perhaps this is a silly idea for many reasons I haven’t thought of. But I think it would be neat thing to have if it worked. Companies would of course benefit as well, and they would have the chance to help finance projects directly and get things that mean profit for their business in return.

Footnotes:

[1] Zenburn colorscheme

[2] This is something I work on for a side-project. The link is to my question on gis.stackexchange.com

[3] Okay, I guess you still need vendor specific libraries, if you develop for any phone platform. I just wanted to make a point that Open Source software changed where we get our tools and libraries from.

[4] Kickstarter.com - There might be many others. I should take some time to research similar sites..

[5] Instead of chosing an individual developer a team could be selected, as well. This team could even change in the future and money to individuals is given proportinately to their involvement.

Resume Scp Transfers

A quick tip that just worked beautifully on a 90GB file for me: It’s possible to continue scp transfers with rsync.

rsync --partial --progress --rsh=ssh user@host:remote_file local_file

taken from here. (Thanks!)

My Second Visit to the Apple Store

Replacement iPhone

There was a scratch on the glass that covers the lens of my iPhone. Once I knew it is there it became very annoying, because I noticed it on every photo I took. And since one of the benefits of having an iPhone is the excellent camera, (Excellent for a phone, anyway.) I felt like I’m not getting all the value for the money I’ve spent anymore.

So I went to the App Store again, this time in the early afternoon, and unlike the first time [1] it wasn’t as crowded. I got a service appointment within 30 minutes, and sure enough, when I returned an Apple store employee was with me on time.

Even though the scratch on the glass could have been caused by my own clumsiness (and maybe it was), I was given a brand new replacement phone. For free. I was told that this is was a case for the 2-year warranty.

He asked me if I have a backup of my phone. I told him I had synced the phone that morning. So he wiped my old one clean using the Reset-feature and told me to plug the new one into iTunes at home. I did and about 20 minutes later I had a phone that had the contents of my old phone, including all apps and configurations (except the internet-settings for my cell-provider).

You can bash Apple all you want, but everything they do is smooth. Their hardware is good, the software is good and their service is good. Why should I want to buy a competitor’s phone next time, provided Apple stays the way it is? I don’t see a reason to.

P.S.: There’s been some talk about Apple losing it’s edge since Steve Jobs died. I don’t think so. Check out this article [2]. They make more money with Macs, which are just a small part of their revenue, than the entire PC industry combined.

Links:

  • [1] My First Visit to the Apple Store
  • [2] Mac Makes More Profit Than the Entire PC Industry

Javascript Popup Windows With Rails

Javascript popups still have their uses. Here is a tiny snippet that one can use to create Javascript popup-windows in a Ruby on Rails application in an elegant fashion.

In your application.js (or whatever .js-file you prefer) include this:

$('a[data-popup]').live('click', function(e) { 
  window.open( $(this).attr('href'), "Popup", "height=600, width=600" ); 
  e.preventDefault(); 
});

Then, in your views add the data-popup-attribute to the link_to-helper:

<%= link_to( 'Open Popup-Window', popup_window_path, 'data-popup' => true ) %>

This is basically taken from [here](http://stackoverflow.com/a/8828841 “”). I have just added two extra parameters to window.open().

The Gist of GIS With MySQL and Ruby on Rails

I am currently working on a small prototype application that requires my rails app to store and process geospatial information. Basically, I am storing and querying longitude/latitude coordinates.

I have been working on projects that had similar use-cases before, but when I joined everything was set up already. Also, usually it was PostgreSQL with PostGIS. This time though, I had to do it myself and with MySQL.

So, since other people might have the same idea, I figured I’d put a few code snippets here so you can get started quicker.

First, here’s my Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.11' # you should update this to 3.2.13 now! ;)

gem 'mysql2'
gem 'spatial_adapter', :git => "https://github.com/descentintomael/spatial_adapter.git"
gem 'geokit-rails3'

# ... some other gems here

This is how a migration might look like (I don’t think you still need the ENGINE=MyISAM line with a current MySQL version):

class CreatePoints < ActiveRecord::Migration
  def change
    create_table(:points, :options => 'ENGINE=MyISAM') do |t|
      t.string :name
      t.column :lat, :decimal, :precision => 15, :scale => 10
      t.column :lon, :decimal, :precision => 15, :scale => 10
      t.timestamps
    end
  end
end

I also added indexes on both decimal-fields.

And here is a bit from my model including two simple queries.

class Point < ActiveRecord::Base
  attr_accessible :lat, :lon, :name

  acts_as_mappable :default_units => :miles,
                   :default_formula => :sphere,
                   :distance_field_name => :distance,
                   :lat_column_name => :lat,
                   :lng_column_name => :lon


  def self.nearest_points( lat, lon )
                Point.within( 10, :origin => [lat, lon] ).order( "distance asc" )
  end

  def self.at_point?( lat, lon )
                Point.within( 0.02, :origin => [lat, lon] ).order( "distance asc" ).first
  end

  # ... etc.
end

Check out the geokit-rails3 README on Github for some examples.

I hope I just saved someone an hour or so of googling.