Lukas Z's Blog

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.

sSMTP on an Ubuntu Server

Usually when I decide to “quickly set up something on a server” it takes much longer than anticipated. Not so with sSMTP.

Basically it’s a simpler way to send emails from the the commandline. In my case with Gmail. Check out this article on how to set it up. I have also combined it with Logwatch and Fail2Ban and it worked immediately.

In the case of Fail2Ban just one extra line in the config-file was needed:

mta = ssmtp

All of this was inspired by this post (via Hacker News).

Shutterbug

Just a picture I took a few weeks ago in Hamburg. This was taken with my phone. It shows a bit of the harbor on a cold January morning. The light was great. There is ice on the water.

Picture of Hamburg harbor

Open the image in a new window to see the picture in high resolution.

Quick Tip: Suppress Output in Rails Console and Irb

Let’s say you have a collection with 10.000 records in your database and you want to put them all in a large array for some reason. With Rails, you can write something like this:

records = Thing.all

Now you can go get yourself a coffee, because the content of all your records will be output to the console window and it will do so for a while.

Here’s the quick tip: If you want to suppress the output, simply do something like this:

records = Thing.all; 0

Problem solved. Easy, but I didn’t think of it immediately..

Update XCode in the App Store

A screenshot of XCode in the App Store

I attempted to update XCode using the App Store app yesterday and was presented with the message “To update this application, sign in to the account you used to purchase it.”. This message however did not point to the real reason why it didn’t work.

What I did was disabling Spotlight Search indexing some time ago, because it affected performance. Turns out, the App Store app uses Spotlight search and in order for XCode to update, it needs to be turned on.

To turn Spotlight Search on, open a terminal and type the following:

sudo mdutil -a -i on

Also make sure you are signed in to your iTunes-Account.