← Older posts


Dompdf weird characters

Posted on by John


If you ever have issues with weird characters appearing in PDF documents it is most likely a character encoding issue.

This often occurs when someone does a copy and paste from Microsoft Word, or similar. Things like quotes get converted into characters that are not properly displayed unless character encoding is kept consistent all the way.

Two places the UTF-8 charset is often missed, is in the <html> body, and the load_html() tag. Often the entire <html> body is missed and only the pdf content is passed. This body tag is required to ensure dompdf knows the encoding of the document it is rendering.

A quick example:

$pdf_content = "some pdf content here";

$html = '<html><head><meta http-equiv="Content-Type" 
content="text/html; charset=utf-8"/></head><body>' . 
$pdf_content . '</body></html>'; 

require 'dompdf/dompdf_config.inc.php';

$dompdf = new DOMPDF();


$pdfFile = $dompdf->output();

header('Content-Type: application/pdf');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Pragma: public');
header('Content-Length: ' . mb_strlen($pdfFile, '8bit'));

echo $pdfFile

Posted in General, Programming | Leave a comment



SSH Password-less login – Linux

Posted on by John


Sometimes you need to give automatic scripts access to another box for things like RSYNC.  These will usually fail asking for a password unless you do a bit of extra work.

To setup passwordless login you need to do the following, under the user account that you want password-less login from. Eg. If you are running cron scripts as root ( which isn’t usually advisable, you would need to do this from the root account )

:~$ ssh-keygen
Generating public/private rsa key pair
Enter file in which to save the key (/home/username/.ssh/id_rsa):  << Accept default which should be your home dir.
Enter passphrase ( empty for no passphrase ): << Make sure you don’t set a password here  or it will prompt for a password which defeats the purpose of what we are doing
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is: …

Next you need to copy this key to the server you want to connect to. When you run this command make sure you connect using the account you want to use as password-less login.
Eg, due to the security risks of having password-less login, you may want a highly restricted account to be the only one with access like this

:~$ ssh-copy-id remoteusername@servername
remoteusername@servername’s password:
Now try logging into the machine, with “ssh ‘remoteusername@servername’”, and check in:
to make sure we haven’t added extra keys that you weren’t expecting.

After you have done this, you should be able to do things like
ssh remoteusername@servername

It should log you in without asking for a password. This becomes really useful when you want to do automatic RSYNC commands.

One example of usage is, I have a Raspberry Pi monitoring my Solar Inverter. This constantly logs to CSV files on the Pi. My main server then does an RSYNC every few minutes to get the latest data for graphing.

Posted in Computers, Linux | Tagged , , , | Leave a comment



Don’t use getimagesize() – PHP

Posted on by John


Over the years I have been involved in fixing numerous websites that are performing slow. The PHP execution time on some were insane, into the many minutes.

Nearly every time it has been down to the getimagesize() function.

This function is terribly slow and should only be used if absolutely necessary.

One thing people seem to like doing is, say in a gallery, loop through every single image getting the properties of the image using getimagesize then generating thumbnails, or even worse, just setting the HTML width and height of images.

Setting the width and height of images in HTML means the huge images are sent to the browser, then resized by the browser. It adds lots of load time and bandwidth usage.

If you are doing something like this, and need to get the image size, do it once, when the image is uploaded and create thumbnails. This way you are only delayed once when adding the images, and your visitors are not delayed.

I should also add that I have seen people recommend using alternative methods such as reading in the first 32bytes of the image, then creating an image from that data, then reading that as the size.
In my testing, this was actually slower, and has issues with different file types.
It may work in some situations, but I recommend doing some speed testing to see if it will suit your situation.

Posted in Programming | Tagged , , | Leave a comment



What I realised about Mac OS

Posted on by John


Coming from a long background of Windows starting at Windows 3.1, Mac always seemed foreign and pointless. Over the years I had the occasional use of Mac but it was always met with frustration and wonder why anyone bothered with it.

It was around Windows XP I started getting frustrated with things on Windows. I started using Linux on a few PC’s and servers.
Windows Vista was released and I shelled out $400+ for the Pro version only to be met with the plague of Vista issues. It was terrible. After 3 or so months with it, I gave up and began using Linux as my main PC.

Linux just made sense and there was no turning back to Windows.
But what does this have to do with Mac OS? More than you may think, and more than I thought.

It was a few years after getting into Linux that I found out that Mac OS version 10 and later, was based on BSD, part of the *nix family. This had me intrigued. I decided to get a Mac Mini.
It was good, but it was still just another foreign OS with nothing to really draw me to it.

It wasn’t until last year that I decided to get a MacBook Air that it really hit me. I stopped using Mac OS as a Mac, and started using it as a *nix operating system.

Install Total Terminal ( http://totalterminal.binaryage.com ). This gives you a Quake style drop down terminal accessible via a shortcut for quick command line options.

Also install Brew ( http://brew.sh ). This gives you a Linux style package manager on Mac OS.

With these two pieces of software, I feel my Mac is like running any Linux distro, but with a different interface, eg KDE vs Gnome. The desktop is just a layer on top of the underlying    BSD OS.

A few other things I have done to use Mac OS effectively relate to the GUI itself

  • Enable all the gestures, especially 3 fingers app swipe switching
  • Full screen all apps, then use 3 finger app swipe switching
  • Enable tap to click rather than push to click

If you get a Mac Laptop, do yourself a favour and buy a Apple TV. The Mac will find any Apple TV on the network automatically and give you an option at the top of the screen to connect to it. When you connect to the Apple TV, you can use it as a second screen in dual screen or mirror mode.
It takes seconds to get say a Youtube video up on the TV using this. I have Youtube clients built into many other devices such as the TV itself, Apple TV, and the PS3. But nothing makes it as easy as just switching the Apple TV as a second screen.
The audio also switches to the Apple TV so you get the sound coming from your surround sound system. This is also good for listening to music from your Laptop.

The applications I use on Mac

  • PHPStorm – Cross platform ( Mac,Linux,Windows) PHP IDE http://www.jetbrains.com/phpstorm/
  • Mac Mail – Better than any existing Linux Mail Client
  • Spotify – Music streaming
  • Skype – IM
  • XCode – Mac OS & iOS Development
  • Qt Creator – Cross platform C++ development
  • Arduino – IDE for Arduino boards
  • Dropbox – Cloud storage
  • GIMP – Cross platform image editor, similar to Photoshop
  • HandBrake – Video conversion
  • Microsoft Remote Desktop
  • Numbers – Excel-like application
  • Pages – Wordprocessor
  • Pencil – Diagramming tool
  • Q Cache Grind – Profiling of cache grind files. Important to see where code is performing slow.
  • ApplePi Baker – SD Card ISO imaging tool designed for Raspberry Pi ISO’s
  • Steam – Games
  • Sublime Text – Advanced text editor
  • Total Terminal – Quake style drop down menu showing the systems terminal
  • VLC – Cross platform video player with a huge list of file type support
  • Twitter
  • Yummy FTP


Posted in Linux, Mac | Leave a comment



Exploding Beer Bottle with your hands.

Posted on by John


This is a video from a few years ago.

A friend didn’t believe me that you could explode a Beer Bottle, just by hitting the top of it when its filled almost to the top with water. Here are the results..

To do this trick get an empty Beer Bottle, one filled with beer won’t work.
Fill it almost to the top leaving about half a cm of room.
Then with the palm of your hand hit the opening of the neck as hard as you can.

This will cause the bottom to explode off.

According to things I have read, this apparently occurs due to micro bubbles forming in the bottom of the bottle. These bubbles are a vacuum. They form then rapidly pull the water back down to the bottom of the bottle causing enough force to break it off.


Posted in Around the House, Entertainment | Leave a comment



Ford Focus – Automatic – Surging Accelerator

Posted on by John


Cars are not my usual topic of discussion but after the weird thing I experienced, and it turning out to be computer related I thought I should post incase it helps others.

My Ford Focus had a weird issue where it would randomly surge when accelerating.

I would try to take off slowly. Slowly increasing the pressure on the accelerator would do nothing. I would keep increasing it gradually until it suddenly kicks in and the wheels spin.

I thought it was just me, and I needed to get used to the car but. I got my dad to drive the car, he wasn’t sure but said something didn’t seem right.

I decided to take it back to the service centre. They knew exactly what I was talking about and said it was a common fault.

A software update later and the car is now fine. I never thought I would see the day where a software update fixes an issue with a cars accelerator.

Posted in General | Tagged | Leave a comment



Water Feature

Posted on by John


I finally got around to building this small water feature on the weekend. 10329016_10152409599374679_8127795848487386734_n

It only took a few hours ( + silicon drying time ) and was rather cheap.

What you need

  • Pot of your choice
  • Storage container that is wider than the base of the pot on all sides so the water can flow into it
  • Stones
  • Mesh that is small enough to prevent the stones from going through it
  • Water pump
  • Pipe that fits the water pump outlet
  • Silicon sealer
  • Wire ( I used an old coat hanger )
  • Bricks, pavers, anything that can go in to the water to support the weight of the pot.

Start by feeding the pipe through the hole in the bottom of the pot. Make sure you leave enough out the bottom to reach the pump in the container. I recommend pulling enough through the hole so it reaches past the top of the pot. You can cut this back later.

Silicon the pipe into the hole of pot and set it aside to dry.

Place your storage container on the ground in the area you want the water feature and mark out the size of the container on the ground.

Dig out the hole so the storage container fits inside, make it slightly lower than the surrounding ground so water can flow into it easily.

Place the storage container into the hole and back fill to support it properly.
Next you need to place the bricks into the storage container in a way so they can support the pot, while allowing the pipe to run out the bottom. I used 3 bricks. One flat, then two on their side on top of the flat one. The pipe easily fit between the two on their side, and ran down to the pump.

Lay your wire mesh over the hole, and cut to size. You will want to allow a bit of overhang so it doesn’t fall in, or let things fall into the storage container.

Cut a hole in the centre of the mesh to line up with the pipe.

Feed the pipe through the mesh and connect it to the pipe.

Fill the storage container and pot to the top with water and switch the system on.

The water should start spilling over the top of the pot and flow back into the storage container. At this stage you should make sure it is as level as possible so the water spills over all sides. I had to put bits of random “things” under some sides of the pot to make it level.

Once you are happy that it is level cut the pipe coming out of the top of the pot, so it is level with the top of the water.

Next use the wire to support the pipe so it sprays up directly in the middle of the pot.
I did this by finding the middle of the wire and looping it around the pipe. I then bent down either end of the wire to make a triangle shape slightly larger than the sides of the pot. These then jammed in fixing it solid. You will need to play around with this and it will be harder with a round pot. You may be able to come up with alternative methods to hold it in the centre. I just found this was the easiest with the style pot I used.

The last step is to cover the mesh with stones. I started with a more coarse stone, before covering with the finer decorative stones.

Last step is to sit back and enjoy the sound of the water.

Posted in Around the House | Tagged , | Leave a comment




Posted on by John


I have written a number of posts about a development framework called PhoneGap ( also known as Cordova.  ) so I thought I should give a bit of informatiScreenshot 2014-05-15 14.40.57on about what it is.

Firstly in regards to PhoneGap vs Cordova, they are basically the same.
Cordova is an open source Apache project.
PhoneGap is the downstream distribution produced by Adobe.

Think of it as Webkit being part of Safari and Chrome. Cordova would be Webkit, and Safari would be PhoneGap.

They did this to allow PhoneGap to provide more end user features that may not apply to the core Cordova goals. However at the time of writing, they are basically identical apart from the name.

PhoneGap allows for rapid development of cross platform phone applications.
This is especially useful for anyone coming from a Web Development background.

PhoneGap itself is a application shell, containing JavaScript hooks into internal phone functions.

To develop an application you start by creating a new project. This gives you an application with basically a Web Browser, and an index.html page.

From here you can go and add all your pages. You can use AJAX to get external content, or package up all the content into the application itself. This step is similar to what you would do for any other website.

JQuery and JQuery UI are important to use with PhoneGap to get the right mobile phone look.

If you need to access any internal functions of the phone, such as take a photo, it is a simple JavaScript function call.

The awesome thing about this framework is the ability to extend the framework, and application further. You can easily add in iOS Objective-C functions, or Android Java functions, then call these from JavaScript.

Once you are done adding all your content, package it up for the destination platform, and deploy it.

eclipsePhoneGap is great for a quick development cycle especially when targeting multiple platforms.

I should point out the few issues I have with it before I end though.

  • It is often very slow on some devices. I have noticed this particularly with a number of Android devices.
  • The touch sensing on the slower Android devices is often off. You push one thing, it highlights, but something else is selected instead. I am not sure what causes this.
  • It is a relatively new framework which has caused a number of major changes. I have had issues where a new version is released causing numerous code changes in what I have already developed. However as the product is maturing this issue seems to have slowed down.

If you are developing a simple informational application which needs a bit more than a mobile website, then I recommend giving PhoneGap a look.


Posted in Computers, Programming | Tagged , , , , , | Leave a comment



RockSmith 2014

Posted on by John


Years ago I was quoted in a news paper saying how I thought games like Rock Band were “a bit silly”. My issue with them was always that people go and push 4 coloured buttons that are barely in time with the music then feel like they can play the guitar. Sure lots of people found fun in it, but I felt there was a lot more potential for people to actually learn how to play guitar.

About a month ago I stumbled on RockSmith 2014. This game is simply amazing. It allows you to plug in any guitar and play Lead, Rhythm or Bass.

Years ago I used to play Bass for fun. Just self taught, but nothing serious. On getting this game I felt my progression in learning go faster than all my previous playing.

The game has a number of modes including

- Learn A Song ( Play songs over and over as they get progressively harder, as you get better )
- Lesson Mode ( videos and interactive tutorials )
- Guitar Arcade ( Early 90′s style arcade games based around learning different guitar techniques )

After playing the Bass guitar for a few weeks in the game, I decided I should give Lead Guitar a go.
I went out and purchased a cheap guitar and began to annoy my fiancé by destroying classic songs.

Learning Lead is a hell of a lot slower than Bass, but it feels like the game is teaching me, and its fun.

I highly recommend this game to anyone that wants to learn guitar without going to lessons.

Posted in Entertainment | Leave a comment



Arcade Cabinet

Posted on by John


After a friend built an awesome cabinet, I decided to give it a go also.

I used the same plans but decided to make it a bit different. The main difference is that all the PC parts are contained within the controller box. This means that it is portable.

IMG_1139 IMG_1133

It wasn’t too hard to build as most of the parts were off the shelf. The hardest part was constructing the box.

Inside the box I used parts from an old computer. Computing power really isn’t an issue with the games I run on it.
The push buttons and sticks were from eBay. I was surprised to see that everything just uses simple click together push switches, even the sticks.
The push switches are then wired to a keyboard encoder. So if you push up on a stick, it say pushes a letter ‘a’ on the keyboard. This method works really well and works out of the box with existing games.


Posted in Computers, Entertainment, Linux | Leave a comment



← Older posts


maps@jcroucher.com tguvba