Skip to main content

Tech

Improving the Dropbox sync #2

25 sec read

I remembered I have a Hazel rule that syncs the files automatically when a new file is added. So I realised I can improve the future posts even further: instead of excluding files, it's better to exclude posts, based on date:

get '/' do
  [...]
  all_posts.reject! do |post|
    time_from_string(post[:datetime]) == nil || DateTime.now.to_time < time_from_string(post[:datetime])
  end
  [...]
end
 
get '/feed' do
  [...]
  posts.each do |post|
    next if time_from_string(post[:datetime]) == nil || DateTime.now.to_time < time_from_string(post[:datetime])
    [...]
    end
  [...]
end

Improving the Dropbox sync

1 min read

Sometimes I have an idea to write about, but I don't really want to post it now, since I want to spread the posts out, so I will just prepare it for future posting. The problem is that right now the sync command tries to add all files, so I came up with a way to only parse files with a date in the past:

def time_from_string(string)
  date_matches = string.match(/(\d{4})-(\d{2})-(\d{2})-(\d{4})/)
  time_zone = Time.now.getlocal.zone
  time = Date._strptime("#{date_matches[4]} #{time_zone}", '%H%M %Z')
  
  DateTime.new(date_matches[1].to_i, date_matches[2].to_i, date_matches[3].to_i, time[:hour], time[:min], 0, time[:zone]).to_time
end
 
get '/sync_command' do
  [...]
  client_metadata.each do |file|
    next if DateTime.now.to_time < time_from_string(datetime)
  [...]
end

Swift inferred types

45 sec read

I read this a while ago, and I just love doing this:

view.backgroundColor = .red
view.backgroundColor = .custom
 
formatter.locale = .autoupdatingCurrent
 
label.font = .withSize(15)
label.font = .customFont(ofSize: 15)

If only the compiler would offer proper autocomplete ... But, hey, at least it's faster and/or easier sometimes.

Fastlane

25 sec read

Build, archive, submit to iTunes Connect, HockeyApp or similar services from the command line. I was skeptical at first, but now I kinda look forward to using it. Took me a while to set it up properly, due to poorly configured openssl, mostly, but otherwise it's pretty straightforward. You can get it here. Felix is an awesome guy too - I had a problem and he managed to reply faster than I came back from lunch 😊.

Securing the Dropbox sync command

2 min read

Since I don't want everybody to run this command, although it doesn't really harm in any way, I added a parameter to act as a private key:

get '/cmd.Dropbox.Sync/:key/?:with_delete?' do
  redirect_to_404 unless params[:key] == MY_SYNC_KEY

The with_delete parameter lets the sync posts command know if to check for deleted files or not. Why this approach? Because the support for multiple posts with same title implies iterating over all posts and on each iteration to iterate over all file names, to make sure.

Continue reading →

Improved Dropbox sync

2 min read

I don't think this is a likely scenario, but I wanted to cover the case where two posts have the same title, and, most likely, the same URL. Filenames will always be unique, because their format is YYYY-MM-DD-Post title, meaning I can make use of this, when running the sync command:

Continue reading →

Long Time

45 sec read

Oh man, I can't believe it's been almost a year since I've written anything. But it's been an amazing year!

I will start with Polychromatic, an Xcode theme that takes a different approach to syntax coloring: emphasize variables (only local ones for Swift), arguments, macros and statics by only coloring these, with a dynamically picked color.

I was skeptical at first (I quickly uninstalled it the first time I tried it, a couple of months ago) but I feel that my eyes are a bit more rested, due to less color and I can spot important information more easily.

Swift first impressions

2 min read

Technically, it's not a first impression, because the first one was "ugh". But then I read the book and watched all the WWDC videos. Oh boy!

Don't even know where to start, but man, oh man, some stuff is just mind-blowing. Here are a few examples of Operator Overload combined with Generics.

Continue reading →

Puppet Anthems

45 sec read

This is the second project I've been working on in the past year or so.

It's your fancy and fun way to learn about the national anthems and cultures of many different countries. This is the special World Cup 2014 Edition, featuring all 32 participating nations under one theatrical, vaudeville roof.

Features:

Continue reading →

DeinDeal

25 sec read

For the past 6 months I've been working with the guys at DeinDeal on their native iOS app. During this time I worked with some great, creative and really smart people, and I've had the chance to learn a lot.

This is the result, of which I'm quite proud.