How to upgrade ImageMagick on RedHat Enterprise Linux 5

ImageMagick 6.2.8 comes with RHEL5.  This is pretty ancient in terms of being able to do some more advanced manipulations, like -kerning, -distort, etc…

As it turns out, ImageMagick publishes their own RPM for RHEL.  But if you try to just install it directly, you get something like this:

[root@boss ~]# rpm -Uvh
error: Failed dependencies: is needed by ImageMagick-6.7.9-6.x86_64 is needed by ImageMagick-6.7.9-6.x86_64 is needed by ImageMagick-6.7.9-6.x86_64 is needed by ImageMagick-6.7.9-6.x86_64 is needed by ImageMagick-6.7.9-6.x86_64 is needed by ImageMagick-6.7.9-6.x86_64 is needed by ImageMagick-6.7.9-6.x86_64 is needed by ImageMagick-6.7.9-6.x86_64 is needed by ImageMagick-6.7.9-6.x86_64 is needed by ImageMagick-6.7.9-6.x86_64 is needed by ImageMagick-6.7.9-6.x86_64 is needed by ImageMagick-6.7.9-6.x86_64

The answer is – use yum to take care of it:

As root, download the correct RPM from the ImageMagick site.  Then uninstall the system ImageMagick.  Then install this one.

yum erase ImageMagick</p><p>yum install --nogpgcheck ImageMagick-6.7.9-6.x86_64.rpm

Note: because the version # is beyond the one shipped with RHEL, it will not be updated automatically.  You will need to monitor ImageMagick for security updates and install them yourself.

Note: this is not recommended — replacing a RHEL package.  But sometimes it is needed.

yum erase ImageMagick
yum install --nogpgcheck ImageMagick-6.7.9-6.x86_64.rpm

HomeSchool Software: Page Rendering (Also ImageMagick Text Example)

Last couple days have had me working on the page rendering functionality of the HomeSchool software.  I’ve made some design decisions (for now) to speed up development like fixed 8.5″ x 11″ pages.  Hopefully later I will be able to go back and improve some aspects, but for now, time is of the essence.

Here is an example page render without the photographs included.  Still need a UI for selecting photographs and positioning them on the white area of the page.

At the bottom, see an ImageMagick Text Example about the python code used to render multiple text areas and color blocks on one image…

It took me a long time to figure out how to use ImageMagick to place multiple text areas on one image.  Here are some keywords for google:

ImageMagick, ImageMagick multiple text areas, ImageMagick pdf rendering, ImageMagick text.

      PrimerFont = join(App.Path, 'Static', 'Primerb.ttf')
      PrimerFontBold = join(App.Path, 'Static', 'Primer.ttf')
      RenderFile = join(TempDir, 'Render.jpg')

      # Build the full image

        # Setup the background
        '-size', '2550x3300',

        # Title Bar
        '-fill', 'grey14', '-draw', 'rectangle 0,0 2550,300',

        # Summary bar
        '-fill', 'RoyalBlue4', '-draw', 'rectangle 0,300 2550,600',

        # Description Bar
        '-fill', 'LightGrey', '-draw', 'rectangle 0,600 2550,1050',

        # Now draw the Name
          '-density'    , '300',
          '-fill'       , 'white',
          '-background' , 'grey14',
          '-font'       , PrimerFont,
          '-size'       , '1650x150',
          '-gravity'    , 'West',
          '-pointsize'  , '20',
          'caption:'    + self.Book.Name,
        '-gravity', 'NorthWest', '-geometry', '+150+150', '-composite',

        # Now draw the Date
          '-density'    , '300',
          '-fill'       , 'white',
          '-background' , 'grey14',
          '-font'       , PrimerFont,
          '-size'       , '600x150',
          '-gravity'    , 'East',
          '-pointsize'  , '20',
          'caption:' + Activity.Date.strftime('%B %d, %Y'),
        '-gravity', 'NorthEast', '-geometry', '+150+150', '-composite',

        # Now draw the Summary
          '-density'    , '300',
          '-fill'       , 'white',
          '-background' , 'RoyalBlue4',
          '-font'       , PrimerFontBold,
          '-size'       , '2250x300',
          '-gravity'    , 'Center',
          '-pointsize'  , '20',
          'caption:'    + Activity.Summary.replace("\n", " "),
        '-gravity', 'North', '-geometry', '+0+300', '-composite',

        # Now draw the Description
          '-density'    , '300',
          '-fill'       , 'black',
          '-background' , 'LightGrey',
          '-font'       , PrimerFont,
          '-size'       , '2250x450',
          '-gravity'    , 'Center',
          '-pointsize'  , '14',
          'caption:'    + Activity.Description.replace("\n", "\\n"),
        '-gravity', 'North', '-geometry', '+0+600', '-composite',

        # Now draw the Page
          '-density'    , '300',
          '-fill'       , 'black',
          '-background' , 'white',
          '-font'       , PrimerFont,
          '-size'       , '2250x150',  #entire right half minus 150pt margin
          '-gravity'    , 'Center',
          '-pointsize'  , '14',
          'caption:'    + 'Page {0}'.format(self.PageNumber),
        '-gravity', 'South', '-geometry', '+0+150', '-composite',

#        NameFile, '-geometry', '+0+0', '-composite',
#        DateFile, '-geometry', '+1275+0', '-composite',
#        SummaryFile, '-geometry', '+0+150', '-composite',
#        DescriptionFile, '-geometry', '+0+450', '-composite',


Optimal PuTTY Settings for SSH Connections to Linux

PuTTY is a great program.  I think it tops the cake for most-useful-utility-on-windows that I have ever encountered.  I’ve used it to connect to telnet, ssh, linux, unix, windows, hypervisors, and even IBM iSeries (AS-400).  However, despite all the cool things one can do with PuTTY, the default out-of-the-box-settings leave a good bit to learn.

For a long time, I put up with some less than optimal settings.  But over time, I learned what worked best for me.  The purpose of this post is to share that with you.


Download from:

Hint: I prefer the windows installer.  However, whatever you do, make sure you get the whole suite (unless you know you don’t need it)

Launch PuTTY and configure “Session” section

user@host is handy for auto-login.  I prefer to place my server name before my username in the saved sessions because the sort order will be maintained as the list grows.

Configure the “Terminal > Bell” section

I have found it preferable not to disable the bell if it is overused.

Configure the “Window” Settings

This is one of the most important settings.  The default of 200 lines of scrollback is just not enough.  I find 20000 to be more useful.  Also, the window size should be set according to your screen size and preferences.

Configure “Window > Appearance” settings

I find that the Luicida Console 14 point font is very easy on the eyes.  Keep in mind I’m usually using a 27″ or 30″ display at 2560 pixels wide, so I can afford the extra size of 14pt.  However, even on smaller screens, I still find it nicer to be able to read effortlessly and see less than the other way around.  Just give it a try :)

Configure the “Window > Translation” settings

As of a few years ago, Linux began to use UTF-8 character encoding by default.  This means that if your terminal is set to latin1 or similar, then each single multi-byte-character is literally interpreted as multiple latin1 characters, mostly drawn as out-of-place accented letters and various symbols.

So in my experience, it is best to use UTF-8 when connecting to Linux.

Configure “Window > Selection” settings

You need to decide here if you want an important safety precaution.  Under the “Compromise” setting above, right-click will paste whatever is on the clipboard… even if you were just blogging about sudo rm -rf /

So, think that over pretty hard.  The first option of “Windows” will bring up a right-click menu with a convenient “Paste” option.  Also, you can simply us SHIFT+INSERT to paste in PuTTY.

Configure “Window > Colours” settings

If you can read dark-blue-on-black, then your vision is in another “spectrum” than mine.  Check out the difference here:

Simply select “ANSI Blue” and change the RGB values to 112, 112, 255.

Configure “Connection” settings

It is helpful to send a null packet every once in a while to keep sessions alive.

Configure “Connection > SSH” settings (Update)

David Aldrich pointed out in a helpful comment that  “I also think it is probably worth enabling SSH compression if working over a slow connection.”

Configure “Connection > SSH > Auth” settings

If you use SSH Agent forwarding (eg pagent) to allow you to “hop” from one server to another, then PuTTY must be told to enable Agent Forwarding.  There are some security issues with this setting when connecting to an untrusted server, so please understand them first.

Configure “Connection > SSH > Tunnels”

If you want to connect to a MySQL or PostgreSQL service running on the host you are connecting to, but have all communication encrypted and sent via SSH tunnel, here is how to set that up.

Keep in mind that your Windows OS you are on must have the source port free, so if you are ALSO running MySQL locally, then pick a different local port number like 13306.

Once your SSH session is established, then you can connect to localhost port 13306 and it will be tunneled to the remote server on 3306.  Cool!

Finally!!! Don’t forget to save your session.

(hint: press the “Save” button)

And that’s it!  The basic PuTTY settings that I use which work quite nicely.

Hope this helps.

How to force-drop a postgresql database by killing off connection processes

Ever need to drop a postgresql database, but it would not let you because there are open connections to it (from a webapp or whatever)?

Quite annoying.  If on a production server, and other databases are being used, restarting postgresql is a last resort, because it generates downtime for your site (even if small).

I finally took the time to scratch around and find the answer.

As a super user, to list all of the open connections to a given database:

select * from pg_stat_activity where datname='YourDatabase';

As a superuser, to drop all of the open connections to a given database:

select pg_terminate_backend(procpid) from pg_stat_activity where datname=’YourDatabase’;

Or for 9.x, change `procpid` to `pid`

select pg_terminate_backend(pid) from pg_stat_activity where datname='YourDatabase';

Here are some references to the functions:

How to checkout and track a remote git branch

One of those really handy things to remember…  When git “tracks” a branch, it basically sets up an entry in .git/config which tells git what to do with push and pull.  For example:

I had a remote branch called Task/Round3.3.

I wanted to work on it locally, but have push and pull work right.

So I ran this:

git checkout -b Task/Round3.3 --track origin/Task/Round3.3

To which git said:

Branch Task/Round3.3 set up to track remote branch refs/remotes/origin/Task/Round3.3.
Switched to a new branch "Task/Round3.3"

And in .git/config, these lines were added:

[branch "Task/Round3.3"]
remote = origin
merge = refs/heads/Task/Round3.3

Now, when I checkout Task/Round3.3, I am able to say `git pull` and `git push`, and it will do the “right thing”…

Ubuntu Post-Install tips…

I received this from a friend, and thought I would post it here in case anyone would find it useful.

After Installing Ubuntu, basically I do this:

Go to:
System -> Administration -> Software Sources -> Other Sofware, and enable partner repository.

After that, we can this on a Terminal:

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install ubuntu-restricted-extras
sudo /usr/share/doc/libdvdread4/

nginx restart error

Was playing around with nginx on Centos 5 (EPEL package).

Most of the time I ran:

service nginx restart

I would get this message in the /var/log/nginx/error.log file:

panic: MUTEX_LOCK (22) [op.c:352].

After some hunting around, it appears to be a known bug in nginx (perhaps perl in nginx?)… Anyway, a simple workaround is to do this:

service nginx stop
service nginx start

Or, simply edit /etc/init.d/nginx, and add the sleep 1 line:

51 restart() {
52     configtest || return $?
53     stop
54     sleep 1
55     start
56 }

Nice workround!