How I set up my wordpress sites on digitalocean with dokku


I recently discovered two great joys in my IT life: one is digitalocean where I can set up a droplet and have my own server in no time, the other one is docker/dokku. Docker alone is great, but dokku makes deployments a breeze.. it is so close to the heroku experience that it’s almost poignant. I took the easy road and created a dokku droplet.

I’m skipping a lot of steps here such as actually creating a DigitalOcean droplet for dokku and so on but that info can be found here. Also I’d like to say that this specific recipe works for me but your mileage may vary. There’s a lot of resources about setting up wp on dokku out there.

 1. Get wordpress

git clone blog
cd blog

2. Modify wordpress according to your needs

Your wp-config should have the following:

$table_prefix  = 'myblog_';

This is especially useful as you have more than one blog on the same mysql instance. I usually just create one mysql docker instance for all blogs and let each of them use a different table prefix. Works like a charm and limits resources.

And the database settings as follows:

define('DB_NAME', getenv('BLOGS_DB_NAME'));
define('DB_USER', getenv('BLOGS_DB_USER'));
define('DB_PASSWORD', getenv('BLOGS_DB_PASSWORD'));
define('DB_HOST', getenv('BLOGS_DB_HOST'));

3. Set the dokku remote

git remote add dokku dokku@:

If your server is and your blog is called myblog this would be:

4. Creating the database

Now with the mysql plugin for dokku installed we can do:

dokku mysql:create blogs_database

And the configuration vars we have set in the wp_config. I’m using one for all so I’m setting these configurations with the –global flag:

dokku config:set --global BLOGS_DB_NAME='blogs_database'
dokku config:set --global BLOGS_DB_USER='mysql'
dokku config:set --global BLOGS_DB_PASSWORD='8920734jfdsakljfFDAFD7897432987'
dokku config:set --global BLOGS_DB_HOST='dokku-mysql-blogs-database:3306'

Finally we’ll link it to the app we’ll deploy (can be done for multiple apps):

dokku mysqldb:link blogs_database myblog

5. Push to deploy

This ideally should be as simple as doing:

git push dokku master

If nothing happens after pushing probably the ssh key on dokku is incorrect. It will simply silently fail and do nothing. Check the authorized_keys file (~/.ssh/authorized_keys). If your authorized_keys file on the Dokku droplet starts with “ssh-rsa” instead of “command=” remove the ssh-rsa line.

6. Choose your domain

If you have set one or more domains on your droplet you can use them setting them on your app like this:

dokku domains:add myblog

Otherwise you’ll get

7. Storage!

Use docker-options for this. It works fine. If you omit this step you will NOT have persistent plugins/themes/uploads and everything will be wiped clean each time you restart the server or redeploy your apps!

Create directories for your blogs. In case of myblog I like keeping them in the dokku home under a directory I call “volumes”. So:

su - dokku # So we don't need to change owner/permissions later
cd /home/dokku
mkdir volumes
cd volumes
mkdir myblog
cd myblog
mkdir plugins; mkdir themes; mkdir uploads;
#chmod them all to have public read/write access

Now back to root:

su - root

And now the real storage part:

dokku docker-options:add myblog run -v /home/dokku/volumes/homecoffeecode/themes:/app/wp-content/themes
dokku docker-options:add myblog run -v /home/dokku/volumes/homecoffeecode/plugins:/app/wp-content/plugins
dokku docker-options:add myblog run -v /home/dokku/volumes/homecoffeecode/uploads:/app/wp-content/uploads

This is very important! Failing to set this will result in losing all assets/themes/plugins upon restarting any of your wordpress instances.

Also very important is the file upload limit (by default 2mb) that must be set in the nginx configuration as follows:

mkdir /home/dokku/myblog/nginx.conf.d/
echo 'client_max_body_size 50M;' > /home/dokku/myblog/nginx.conf.d/upload.conf
chown dokku:dokku /home/dokku/myblog/nginx.conf.d/upload.conf
service nginx reload

8. Memory

The dokku droplet needs memory… so the 1GB is the minimum viable option. Also the best thing is to just add some swap to make things easier during deployments (especially wordpress or rails). To add swap space do the following:

as root:

dd if=/dev/zero of=/extraswap bs=1M count=512
mkswap /extraswap

How to really really change your UITableView’s background on iOS 8 and Swift

I admit it.. this thing was driving me mad and SO somehow didn’t really give me the answer to this one. Maybe because they were all objC oriented… The solution appeared to usually be the UITableView’s backgroundView. Changing the tableView.backgroundColor alone simply wouldn’t work at all. SO answers all went the way of setting the tableView.backgroundView to nil and then changing the tableView’s backgroundColor and everything should work fine. BUZZ… not up in here.

I ultimately did make it work but not by making it nil, rather by assigning a new UIView to the backgroundView and then setting the bacgroundView’s backgroundColor like this:

tableView.backgroundView = UIView()
tableView.backgroundView?.backgroundColor = UIColor.redColor()
tableView.backgroundColor = UIColor.redColor()

And that seems to do the trick 🙂

XCode and the pleasure of coding on a transparent window in Yosemite

I love to code on transparent windows. It makes me feel so good inside… ha ha jokes aside it’s something that makes my coding hours more enjoyable. So here’s easy steps on how to achieve this on Yosemite with XCode:

  • Download EasySIMBL from the github page
  • Add EasySIMBL to Applications and run it. Check “Use SIMBL” and close the app.
  • Download the latest Yosemite version of Afloat from the github page
  • Run the project in XCode and build. Select the Afloat bundle from Products, right click and show in Finder
  • Copy both files into/Library/Application Support/SIMBL/Plugins
  • Restart your mac!

Now you’ll be able to open un XCode, go into menu->Window and you will find the AFloat menu items where you can make the window transparent.. yay!

XCode transparency Yosemite

Here’s how it looks like on my mac:

XCode transparency Yosemite Now how cool is that? 🙂

Swift refactoring? XCode VS AppCode

Ok so I took up the challenge and started coding in Swift for Pins2Go (the mobile version of Pins) and I needed to simply change a test variable name…

Here’s what XCode told me:

Schermafbeelding 2015-04-17 om 13.14.11







Well that didn’t seem very nice to me given how much Apple’s pushing Swift coding lately!

So I decided to try doing this in AppCode:

Schermafbeelding 2015-04-17 om 13.14.28

This JUST WORKED. Flawlessly. Smoothly.

AppCode: Epic win, XCode: Epic fail!!!

XCode 4 Color Theme

Here is my  XCode 4 Color Theme. I mostly use it during my nightly cocoa programming sessions. I love dark backgrounds because I find them particularly soothing to the eye. This theme is based on the website color palette.

To install the theme unzip the file into your /Users/yourname/Library/Developer/Xcode/UserData/FontAndColorThemes folder.

ObjectiveSheep XCode Color Theme

Works especially well if combined with some good Jazz through your headphones… something like Miles Davis’s “Kind of Blue” for example 🙂 . Enjoy.

NSImage (or UIImage) into Core Data

A problem I have encountered and that took me a lot of searching on google is how to store an NSImage into a core data field.
The solution is actually a very simple one but without guide it could be awfully time consuming.

So here it is.

First of all you need a subclass of NSValueTransformer to do the job:

Here is the interface:

@interface SheepImageToDataTransformer : NSValueTransformer



And the implementation:

#import "SheepImageToDataTransformer.h"

@implementation SheepImageToDataTransformer

+ (BOOL)allowsReverseTransformation


return YES;


+ (Class)transformedValueClass


return [NSData class];


// These two methods use the NSImage implementation that is Mac specific or the iOS one with UIImage. Choose the lines that apply to your case and comment/delete the others.
- (id)transformedValue:(id)value


// Mac implementation 
NSBitmapImageRep *rep = [[value representations] objectAtIndex: 0];
NSData *data = [rep representationUsingType: NSPNGFileType
properties: nil];
return data;

 // -- OR --

// iOS implementation  
return UIImagePNGRepresentation(value); 


- (id)reverseTransformedValue:(id)value


// Mac implementation: 
NSImage *uiImage = [[NSImage alloc] initWithData:value];
return uiImage;

// -- OR -- 

 // iOS implementation:
return [UIImage imageWithData:value];



Just import the header into your NSManagedObject subclass and declare your property as an NSImage like this:

@property (nonatomic, retain) NSImage * thumbnail;

To finish things up you will be setting the attribute type of the desired field in your data model to Transformable and put the name of your NSValueTransformer subclass in the name field like this:

Core Data

bookmark.thumbnail = yourNSImage;

And you’re all set.

Remember to watch your performance. Don’t store images larger than a 100k as a field of an entity. If you need bigger images store them on disk and save the path to core data.


Core Data + Active Record = SheepData

Let me first of all say that I love Core Data. It’s really powerful and easy to use and coming from java and hibernate I immediately felt comfortable with it.

There are a couple of things that I don’t like though. First of all the logic of having access to your core data objects through the Application Delegate (which is what usually happens if you let XCode create a Core Data project for you) and the repetitive code for simply creating and executing requests.

I have always been a strong believer in Martin Fowler’s Active Record pattern. A single entity should have the responsibility of all its CRUD operations. So… scratching my own itch I ended up with a couple of classes that make life a lot easier when using Core Data out of the box:

No core data code in the Application Delegate. In fact there will hardly be any managed object context and persistent store to be seen anywhere. Plus it can be used on existing projects that have not been created as core data projects before (both iOS and Cocoa)

Simple entity management: all entities are real classes subclassing SheepEntity (offspring of an NSManagedObject) and can be used wherever in your code.


Simple methods for fetching / adding / deleting / checking entities from Core Data

Let’s see this step by step.

1. Download the SheepData example project containing the SheepData folder you will need in your own project from github

2. There will be an XCode 4 project that can be tested (command+u) out of the box. A core data model has been created with a couple of entities.

3. If you open the core data model you will notice that every entity has its own class specified… this is actually very important to make things work so make sure this is filled in.




4. Now select the entity you need and from the menu select Editor and then Create NSManagedObject subclass. You will end up with an entity you can use in your code.




5. Now in your code you will have a Mother.h and Mother.m file. First add the SheepData folder into your XCode project.

@interface Child :  NSManagedObject

@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSManagedObject * mother;
@property (nonatomic, retain) NSManagedObject * father;


And then add the #import “SheepEntity.h” line in your Mother.h.. also make it extend SheepEntity. Like this:

#import "SheepEntity.h"

@interface Child :  SheepEntity

@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSManagedObject * mother;
@property (nonatomic, retain) NSManagedObject * father;


That is all you need! You’re done. Here are a couple of examples that show how easy it is to use a SheepEntity in your code.

// a. Creating a new Entity
// No other code is required. No need to create a managed context and persistent store. Everything is automagically done behind the scenes.

Mother *mother = [[Mother alloc] initEntity];

// b. Fetching an array of entities
NSArray* fathers = [Father fetchEntities];

// c. Fetching a specific entity
Child *c = [Child fetchEntityWhereProperty:@"name" equalsValue:@"Johnny"];

// d. Deleting a set of entities
NSArray* children = [Child fetchEntities];
[Child deleteEntities:children];

You will have access to other useful methods like:

+ (id) fetchEntityWhereProperty:(NSString *)aProperty equalsValue:(id)aValue; //Convenience method for fetching a single entity by property/value

+ (id) fetchEntityWithPredicate:(NSPredicate*) aPredicate; //fetches a single entity with a given predicate

+ (NSArray*) fetchEntities; //fetches all entities

+ (NSArray*) fetchEntitiesWithSortDescriptor:(NSSortDescriptor*)sortDescriptor; //fetches all entities in a given order

+ (NSArray*) fetchEntitiesWhereProperty:(NSString *)aProperty equalsValue:(id) aValue;//Convenience method for fetching a list of entities by property/value

+ (NSArray*) fetchEntitiesWithPredicate:(NSPredicate*) aPredicate; //Convenience method for fetching a list of entities given a predicate

+ (NSArray*) fetchEntitiesWithPredicate:(NSPredicate*) aPredicate andSortDescriptor:(NSSortDescriptor*) aSortDescriptor; //Convenience method for fetching a list of entities given a predicate and a sort descriptor

+ (NSArray*) fetchEntitiesWithPredicate:(NSPredicate*) aPredicate andSortDescriptors:(NSArray*) sortDescriptors; //Convenience method for fetching a list of entities given a predicate and multiple sort descriptors

– (void) deleteEntity; //removes the current entity

+ (void) deleteEntities: (NSArray*) entities; //removes an array of entities in one shot

+ (BOOL) checkIfEntityExistsWhereProperty:(NSString *)aProperty equalsValue:(id) aValue;//checks whether an entity with a given property/value already exists.

+ (BOOL) checkIfEntityExistsWithPredicate:(NSPredicate*) aPredicate; //checks whether an entity with a given predicate already exists.

Feel free to use this code in your projects (commercial or not). It has a BSD license. Attribution is welcome. Enjoy!