Display UI-blocking overlay on page load

overlay

A client asked me to add an announcement to their website, informing visitors that their business would be shut during the holidays.

“Uh, ok”, I said, thinking that I could place an announcement in the sidebar, but the client wanted more. They wanted it visible, like really, really visible.

The solution we ended up with was to have the announcement displayed in an interface-blocking overlay when the site loaded. This would be shown to the user only once.

Although not overly user-friendly, some people might find this useful, so here’s how I coded it.

Read more…

FXRuby – How to capture close on the main window

An introduction to FXRuby

I wrote a small FXRuby program which allows the user to do some simple file manipulation, then upload the altered files via FTP to a web server.

I ran into a small problem in that when the user clicked the “Close” button (the X in the upper right-hand corner) of the main window, the application closed straight away.

Normally, this would be the desired behaviour, but in this case I wanted to intercept this message and do some application cleanup first (delete temporary files, make sure the user had saved their work etc).

Here’s how I did it.

Read more…

Making rsync behave like SyncToy

synctoy_linux

Microsoft have produced a very handy backup tool for Windows in the form of SyncToy.

It is intuitive and easy to use, so when I made the switch from Windows to Linux as my main operating system, this was something I sorely missed.

I quickly stumbled upon rsync as the de-facto backup program for Linux, but must admit I was somewhat overwhelmed with the plethora of configuration options it ships with, as well as the tremendously verbose output it produces.

Here’s how to tame it somewhat.

Read more…

How to install rbenv on Linux Mint 16

mint-rbenv

Last year I switched from Windows to Linux Mint as my main operating system and wanted to install a Ruby version manager.

I weighed up the pros and cons of what was available and eventually opted for rbenv as it seemed more lightweight, would let me compile my Rubies myself and (in contrast to RVM) didn’t come with any way of managing gems.

I searched Google and came up with a couple of tutorials to follow, such as this one and this one which described how to install rbenv, but unfortunately they didn’t work for me.

Read more…

How to persist checkbox checked state after page reload

checkbox

This is a simple tutorial on how to have your browser remember the state of checkboxes once a page has been refreshed or a user navigates away from your site to come back at a later date.

This might be useful for example, if you use checkboxes to allow your users to set site-specific preferences, such as opening external links in a new window or hiding certain page elements.

For the impatient among you, here’s a demo of what we’ll end up with.

Read more…

Setting a fallback font in Prawn

prawn

At work, one of the applicants to our programme submitted parts of her application in Russian (despite it being an English speaking programme).

The database could handle this fine, as it stores entries using the UTF-8 character set, but the PDF generation part of our application refused to cooperate (just displaying a bunch of underscores). 

We use the Prawn library to generate our PDFs, so I set about finding a way to make Prawn play nice with the Cyrillic characters.

Read more…

Trouble installing mysql2 gem on Windows 8 with Ruby2

mysql-ruby

I recently installed the 64 bit version of Ruby 2.0 on my Windows 8 machine.

All of my old projects I tested with it ran just fine and the world was a happy place.

Then I had to install Rails, so that I could make some minor changes to an existing app … and the pain began.

Read more…

How to center an HTML Element using JavaScript

target

Imagine you have an element which is dynamically added to your web page (an image in a lightbox, for instance) and you want to centre it on the screen both horizontally and vertically.

You could do so with CSS (as this article explains), but if you don’t know the dimensions of the element you want to centre or you need to support older browsers, things can become quite tricky quite quickly.

That’s when you should think about doing the job with JavaScript.

Read more…

Use AJAX to filter MySQL results set

filter_mysql

I recently helped someone with a project where they had to select a bunch of records from a database, then on the client side use AJAX to filter those records according to certain criteria.

This was a fun thing to work on and a good opportunity to demonstrate the power of AJAX, so I thought I’d write it all up in the form of a quick tutorial.

For the impatient among you, here’s a demo of what we’ll end up with.

Read more…

How to restore a previously deleted file from a GIT repository

git_logo

I was recently working on a project and realised that I needed a file that I had long since deleted.

On the one hand, this wasn’t very tragic as I had the project under version control using GIT. However, finding the exact command to restore a single file from a rather old commit proved to be a little more difficult, so I thought I’d make note of it here.

Read more…

Older Entries Arrow pointing to the right