Category Archives: Tips

Speed up Deploy via SCP in GitLab CI/CD

Deploying thousands of small files via SCP to a server takes an inordinately long time, even via a very fast network, much longer than transferring one large file. Here’s a tutorial on my Gitlab CI setup for compressing all my deployment files into one large tarball, transferring it to to the server then uncompressing it there. 

I have been experimenting with GitLab CI/CD for use with my Swimming Management System projects for Masters Swimming Queensland. It’s a legacy project that I’m now gradually transitioning to modern standards. I’ve set up a Pipeline that will allow me to test commits in PHPUnit, then have them automatically deploy to a dev/test server. 

The project now uses both Composer and with some Angular modules it also uses NPM. In the build phase on GitLab CI, composer install is run to get the dependancies into the vendor directory. 

To do it this way, you’ll need to have shell access via ssh to your server. 

I’ve set up the test server deployment details and authentication credentials as in GitLab Variables:

Configuration of GitLab CI/CD Variables
Configuration of GitLab CI/CD Variables

In the deploy stage I’ve added the following code prior to upload via scp:

- tar -czf /tmp/build.tar.gz .
- echo "TEST_SSHPATH=${TEST_SSHPATH}" > sshenv
- sshpass -e scp -P ${TEST_SSHPORT} -r -o stricthostkeychecking=no sshenv ${TEST_SSHUSER}@${TEST_SSHHOST}:~/.ssh/environment

In this case, the target ‘.’ indicates that we are tarballing the current directory.

In the second line we create a file that contains the definition of an environment variable on the target server, which is set to the GitLab CI variable TEST_SSHPATH. TEST_SSHPATH contains the path to the root of my code deployment on the server.

Finally, we then scp this file to the target server, putting it in ~/.ssh/environment. This will mean that when we ssh into the server, that environment variable will be available to us, containing the value from the GitLab CI variable. 

Now we can transfer the build.tar.gz file and un-tar it. 

- sshpass -e scp -P ${TEST_SSHPORT} -r -o stricthostkeychecking=no /tmp/build.tar.gz ${TEST_SSHUSER}@${TEST_SSHHOST}:${TEST_SSHPATH}
- sshpass -e ssh -p ${TEST_SSHPORT} -o stricthostkeychecking=no ${TEST_SSHUSER}@${TEST_SSHHOST} "cd ${TEST_SSHPATH}; tar -zxf build.tar.gz"

The first line in this block does the transfer via scp, to our the path provided in the variable TEST_SSHPATH.

The second line, connects via ssh , changes directory to the code deployment path, then extracts the build files. Tar -zxvf removes the .tar.gz file after it’s done, so there’s no need to seperately delete it.

Before making this change, my swimman project would take 16:30 to build and install. With this change it’s down to 4:35. That’s a saving of 12 minutes which makes a big difference when deploying a quick fix to the test environment. 

How to Restore an iCloud Backup to a New iPhone with 2 Factor Authentication

My wife recently purchased a new iPhone 7. We backed up her old iPhone to iCloud, then proceeded to start up her new iPhone, selecting the Restore from iCloud Backup option. We then hit a snag. 

I had enabled 2 Factor Authentication for iCloud access. This meant to be able to access her iCloud account from the new phone, she needed to provide a code that would be SMS’d to her iPhone. However has her number had been transferred to the SIM card in the new iPhone, this meant the SMS would go to the new iPhone, the one we were trying to set up. Because we were still trying to set it up, we couldn’t see the code. We also didn’t have any other phone we could put that SIM card in.

The only other option would have been to recover the iCloud account via an alternate method., which takes several days. Not what we wanted to do. 

After much frustration and a phone call to AppleCare, it turned out the solution is simple:

Select the Resend Verification option

The initial SMS was hidden and didn’t automatically advance us through the process, but tapping the option to resend the code enabled us to continue forward. We still didn’t see the message, but the phone automatically recognised it had been sent the verification code and allowed us to continue to restore the new phone from the iCloud backup.

Updating/Replacing a MySQL Database from an SQL Dump

Today I needed to replace an existing MySQL database with an updated version of the same database from .sql MySQL dump file. Because my updated sql dump contained duplicate rows that were already in the target MySQL database, just using the standard command-line import produced a fatal insert error due a duplicate primary key.

I couldn’t use PHPMyAdmin for the same reason. Apparently some versions have an option that ignores duplicates but the one on my hosting provider didn’t give me that option.

So to import the SQL dump ignoring the duplicates we need to change the INSERT statements in the file to INSERT IGNORE statements. This can be done using sed:

sed -i -- 's/INSERT/INSERT IGNORE/g' backup.sql

Then import your SQL dump using:

mysql -h host -u username -p -r database < backup.sql

There are two ways to use this with your hosting provider:

  1. If you have shell access on your host and access to the mysql and sed commands you can run it on the host.
  2. If you don’t, you need access to any machine(Linux box or Mac or Cygwin for instance) with both the sed command and mysql client command-line tool. Just replace host above with your hosting provider’s MySQL server address.

For the record, you can also probably do this with any other text editor that has a Find/Replace function. On Windows I’d suggest Notepad++. I used sed though because it made it easy to do the whole task on my hosting provider’s shell.

Redesigning a Small Office with Open Source Software

My wife and I recently had our first baby. The second bedroom of our small apartment which was being used as an office had to be converted to also serve as a nursery for the baby.

Before picture
Before: Computer desk, bookshelf and filing cabinet on wall to left, cot and change table to mid and right

Being such a small room, with such an odd shape it was hard to decide on the best layout for all the items. The room needed to fit a cot and change table, as well as the existing desk, filing cabinet and bookshelf. Initially we’d just put the new items in the room but putting them all in had stopped us from being able to open the wardrobe.

We definitely needed to make a change to the layout, but with such heavy furniture and a small room I didn’t want to have to move everything around without a good plan of where they should go.

The answer seemed obvious: draw a diagram to scale and plan the new layout before moving anything. I wanted to make sure everything would be easily accessible and that the wardrobe doors could be fully opened. I figured I’d use the free CAD program LibreCAD to do the design.

LibreCAD is an open source Computer Aided Design application for Windows, Mac OS X and Linux. It provides a fairly comprehensive set of features for 2D CAD drawing. I’m not particularly skilled at CAD drawing so I had to bumble my way through figuring out how to use the basic features.

I started by measuring the walls and adding straight lines of the correct lengths and using the snap to endpoint feature to join them. I also added arcs to indicate the swing of the wardrobe and room doors. I then measured up and drew the furniture from the room and positioned them as they currently were.

Before: LibreCAD Drawing
Before: LibreCAD Drawing

After completing an accurate CAD drawing of the office it was a simple matter of moving the furniture around until I found a layout that met my requirements of making everything more accessible and allowing the doors to open properly.

After: LibreCAD Drawing
After: LibreCAD Drawing
After: The end result - much more usable space!
After: The end result – much more usable space!

I learned some useful techniques of CAD drawing which I’ll try to improve in the future. My next plan is to create a full layout drawing of our apartment which I can use in my internet of things applications.


7 Practical Tips for Better Professional Networking Business Cards

Who hasn’t come away from a professional conference with a stack of exchanged business cards? Most of them will probably be still sitting on your desk in 6 months time if you’re anything like me. How can you get yourself remembered and create those important network connections with your peers?

A few of my friends were impressed with the cards I made for my attendance a Problogger Event 2014, so I decided to make this article on how to do it. So here’s some practical tips on how to create an effective professional networking business card.

1. Create a Professional Profile Website and Put the Address on Your Card

If you have a number of projects or portfolio items to show off you probably can’t fit them easily on one business card. Even if you do, you want to be making it as easy for people to look at them. You can have one single website that links to your portfolio items, resume, previous employers, previous and current projects, Twitter feed, LinkedIn profile, etc, etc, etc. Being something you own, you can portray yourself in the way you want.

I’m not going to tell you how to build your own website. There’s plenty of existing resources. Instead I’ll link you to a few of my favourite resources that will show you how to do it yourself using WordPress.

A website will need a hosting provider. You don’t necessarily have to pay for one yourself, you could use for free WordPress hosting. The trade off there is that your site address with be like, instead of or

If you are in the technology business or just want to look better, you should probably buy your own site address like and pay for hosting it somewhere. I would recommend using Crazy Domains(I receive a small commission at no extra cost to you if you use this link) to purchase your domain and host it. I have used them for most of my sites and have found their service excellent. They have a one click option for installing WordPress on your site.

Once you’ve got your site, put the address on the card. Leave out the “http://”, it’s just wasted space, most people can recognise a website address when they see one.

2. Let Me Know Who You Are

At Problogger last weekend I received a whole range of different types of business cards, from the flashy designs to the simple minimalisms. Looking at some of them I can totally remember the conversation I had with the person who gave me them. For others I’ve had to rack my brain to recall.

Be sure that your card has references to (or links to) the key things you want to be known for. If I’m talking to people about SEO and your card is for your design company I probably won’t remember who you were when I look at it.

So be sure to include your claims to fame on the card, whether it be skills, experience, projects or businesses. Whatever you want to promote.

3. Include a Picture

My professional face picture
My professional face picture

Consider including a small picture of yourself on your card. Most of us will remember faces much more easily than names. If you include your picture, when I look at your card I’ll remember exactly who you were!

Choose your photo carefully. A face picture will be the best. You want to look good, but it’s not a glamour shot. Unless you’re a model.

If you use the same picture on your professional profile on LinkedIn and on other social media feeds it’ll help your recognition.

4. Include a QR Code Contact Card

My QR Code Contact Card
My QR Code Contact Card

You’ve got your name, postal address, mobile phone, email address and website address to include on your card. That’s a fair bit for your contacts to type into their phone address book. You can make it easier for them by using a QR Code.

There’s lots of software available for making QR Codes, but I just used The QR Code Generator website. Select the Contact tab and enter the details you need. Then click the orange Save button.

Add the saved image file to your business card. Make sure it’s large enough to be clearly scanned. I made mine about 34mm x 34mm. You may not need to make it that big though. Do a test print and try it out with your phone camera. I use QR Reader for iPhone. There are similar apps for Android.

5. Don’t Spend Too Much

Don’t spend too much on flashy design or special card. Your card is likely going to be lost in someone’s drawer for the next 2 years. 

In most cases your card is going to have a short useful life. What you really want to achieve is to get your contacts to look at your personal profile site and connect with you on LinkedIn, Twitter, email or phone. So your card just needs to deliver your contact details. It doesn’t have to be fancy cardboard or amazing design for that to happen.

For my Problogger cards I just got 100 printed on standard card at my local office supply store, OfficeWorks. I took my PDF to the store and they printed them overnight for just $23(single sided).

6. You Can Do It Yourself in Word

Sure a designer could do a fantastic job for you and if you have the finances go for it. In my case I had no time and not much money, so I just use a template that was included in Microsoft Office 2011 for Mac OS X.

The templates are designed to print 8 to an A4 piece of card. If you have a good quality printer and a guillotine, you could do it this way. As mentioned above though I got mine done at the office shop, which saved me a lot of time and a better result in my opinion.

If you are getting your printing done professionally you’ll need to modify the template document:

  1. Remove all but one copy of the card from the document.
  2. Set the page size to Custom, width 100mm, height 65mm. See this page from OfficeWorks website.
  3. Set the margins to 5mm on all sides.
  4. Adjust your layout to make it fit neatly inside the margins, taking into account they’ll be trimmed along the margins.

Save your document as a PDF and put it on a USB stick to take to the store. If you’re asking your wife to do it for you, don’t forget to tell her what your filename is(I did, oops).

7. Follow up

You may not be the most exciting person your contact met at the conference. Make follow up contact with the person you met within a week or so of the conference. To effectively build a network you need to do more than just connect to them on LinkedIn or follow them on Twitter.

Send them a message by some format, preferably email, saying hi and expressing your appreciation of meeting them. Refer to the content of your discussion and try to find a way to help your contact with no expectation in return. If you have a proposal for them, be sure you to pitch it from their perspective. How will it benefit them?

The classic reference for building a network is Dale Carnegie’s How to Win Friends and Influence People. If you haven’t read this book, buy it now on Kindle and read it. Refer to it regularly. Another great reference is The Art of Charm Podcast. There are heaps of networking related episodes, but I suggest you may want to start on this one about likeability.

So how did my cards work out for me at Problogger Event?

I handed out about 30 cards and my profile website got about 15 hits. Not a bad rate in my opinion. I suspect I’ll get more as I continue following up with my contacts from Problogger Event 2014.

My card from Problogger Event

I didn’t do everything that I had wanted to. I only really implemented 4 of my 6 tips – I didn’t have a picture and I didn’t have a skills list. I was rushed. It was Monday night when I realised I still didn’t have any cards made up. I made this website, made the QR codes and made the cards just before midnight. My wife took them the next day to print.

Fortunately I did have my skills list and photo on the profile website, so that should help my recognition. A number of people I met did seem impressed with the cards, so I wrote this article. I’ll report back in the future on how it works out long term!