2011
10.27

Easy Monitor calibration

I spend a lot of time in front of my monitor and if it’s too bright my eyes get tired quickly. As a result, I keep my brightness down so low that people have thought I had a broken monitor. However, when viewing pictures I need it to look as accurate as possible. Here’s a quick and dirty way to be sure that my Contrast and Brightness are set to reasonable values.

http://www.photofriday.com/calibrate.php

It won’t be perfect, but the price is right and you have nothing to lose but a few minutes of fiddling.

2011
10.06

Every now and then I need to write a block of Oracle PL/SQL that’s a little more involved. I’ve had this block of script put aside as an example of how to include functions and procedures in an anonymous block.

-- PLSQL code
BEGIN
   DECLARE
       -- Equivalent of a package level variable
       i   INTEGER := 0;

      PROCEDURE doStuff (description IN VARCHAR2)
      IS
         i   INTEGER;
      BEGIN
         DBMS_OUTPUT.put_line ('description is ' || description);

         i := i + 1;
      END;

      FUNCTION calcStuff (i_value IN INTEGER)
      return integer
      iS
         i_dummy   INTEGER;
      BEGIN
         i := i + 1;
         DBMS_OUTPUT.put_line ('Function called ' || i || ' time(s)' );

         return i_value + i;
      END;

   BEGIN
      -- Call our shiny new procedure
      doStuff ('one');
      doStuff ('two');
      doStuff ('three');

      -- Call our new function
      DBMS_OUTPUT.put_line ('Function returned: ' || calcStuff(100));
      DBMS_OUTPUT.put_line ('Function returned: ' || calcStuff(150));
      DBMS_OUTPUT.put_line ('Function returned: ' || calcStuff(200));

   END;
END;
2011
10.03

When sharing digital images online, I often find myself looking for an easy way to copy and paste the EXIF data. This little script when put into my ~/.gnome2/nautilus-scripts folder will create a text file of the most commonly used EXIF information.

#!/bin/bash
files=$#
count=1
message=`echo "Dumping EXIF from $files files"`

(while [ $# -gt 0 ]; do

	# Strip off the file extension, including the "."
	upperExt=`echo $1 | sed 's/.*\(\..*\)/\1/' | tr '[a-z]' '[A-Z]'`

	if [ -f "$1" ]
	then
		# Get the file name without the extension
		# trimmed=`echo $1 | sed 's/\(.*\)\..*/\1/'`

		if [ $upperExt = ".JPG" -o  $upperExt = ".JPEG" -o  $upperExt = ".PPM" -o $upperExt = ".CR2" -o $upperExt = ".NEF" -o $upperExt = ".OTHER_RAW_EXTENSION" ]
		then
			# Output EXIF data to a new text file named the same as the original image.
			exiftool -canon -S "$1" > "$1.txt"
		fi
	fi
	# Output the zenity progress bar
	sav=`echo "(($count / $files) * 100)" | bc -l`
	echo $sav
	count=`expr $count + 1`
shift
done) | zenity --progress --auto-close --auto-kill --text "$message"
2011
09.22

Recently my webhost installed mod_security on my webserver. It seemed like a non-event until I started getting calls from a few clients who had been merrily working for a long time. When they tried to update content in either Open-cart or WordPress, they were getting strange errors such as “501 Not Implemented” or “406 Not acceptable”.

The fix is to sidestep mod_security for those requests. Ideally it should be limited to the offending request, but in the interest of getting people running, I simply added a .htaccess file in the /admin folder of the broken sites with the following contents.

<IfModule mod_security.c>
    SecFilterEngine Off
    SecFilterScanPOST Off
</IfModule>
2011
09.02

Ok, I saw the warning but didn’t think it applied to me. Don’t assume it doesn’t apply to you!

Remove any proprietary ATI/AMD drivers from your Natty installation. You can put them back on after we install the new kernel.

Now that you’ve checked for anf removed any ATI proprietary drivers, visit this URL and pick out the kernel that you want to try. http://kernel.ubuntu.com/~kernel-ppa/mainline/

In my case, I was running the latest natty kernel on a new (but low-end) Toshiba C650D laptop. It was crashing constantly, never running for more than an hour. As there weren’t any clear indicators in the logs, and the hardware worked fine on Windows, I wanted to try a different kernel. I wanted to the newest kernel possible in the hopes that whatever issue had been resolved.

I opened the above Url and scrolled way down to the bottom of the page. All the way to “v3.0.4-oneiric”. It was dated four days ago – that ought to be new enough! As I’m running 64 bit 11.04, I need the “amd64″ binaries. Download the appropriate ones, “headers…all” and the “headers” and “image” file for my architecture.

 linux-headers-3.0.4-030004_3.0.4-030004.201108301138_all.deb linux-headers-3.0.4-030004-generic_3.0.4-030004.201108301138_amd64.deb linux-image-3.0.4-030004-generic_3.0.4-030004.201108301138_amd64.deb 

Next, open a terminal window and cd to the folder where your binaries are located. Run the following command to install the new kernel:

 /sudo dpkg -i /linux-headers-3.0.4-030004_3.0.4-030004.201108301138_all.deb linux-headers-3.0.4-030004-generic_3.0.4-030004.201108301138_amd64.deb linux-image-3.0.4-030004-generic_3.0.4-030004.201108301138_amd64.deb 

Let it run for a minute or two and if there are no errors reboot. If you have errors, fix them, try the install command again and reboot. If Grub doesn’t prompt you to choose a kernel, check it from terminal once you’re logged in. with the following:

 /uname -r /

There you have it! Running a 3.0 kernel on Ubuntu 11.04, Natty.

2011
08.18

Working as a freelance web developer means that I work really strange hours. I may not get to a project until my kids are in bed and keep working late into the evening. When there’s something that needs to be done, nothing ticks me off quite like a broken website that requires a phone call to customer support. Once or twice I’ll let someone get away with it, after-all sometimes stuff breaks. That’s just the way it is. But when it came time to renew my website domain – the face of my freelancing business, and I discovered yet again that the domain renewal pages of my registrar *still* would not allow me to renew online I nearly lost it. I called up their customer support where the person on the other end asked me for my username and password so that they could enter the transaction for me. Yeah right. It was time to find myself a new registrar. After the usual poking around the Internet and some discussion among my associates, I settled on http://www.namespro.ca/. They’ve been in the business since 2003 and are a Canadian business so I feel like I can trust them to manage my domains properly. I signed up and was able to quickly and easily move over my domain. The website is easy to follow and the domain management pages are clean and easy to use. I sent a couple questions out to their tech support and received prompt replies that made me very happy with my choice. I’ve since moved a couple more domains to them and will continue to chance my domains over to namespro as they come due. Managing my domains from a proper web interface on my own schedule has never been simpler!

2011
08.16

Resize and Rotate

Last week my laptop died so when the new one arrived I started re-installing all those apps that make it work the way I want. This post is about one of those *must-have* applications. I manage all may camera images on my laptop so being able to quickly resize or rotate images is pretty important to me. Luckily a friend showed me an easy way to do bulk rename and resize with a simple right-click.

Installation

To add the new options to the Nautilus context menu we’ll first need to install the package:

 sudo apt-get install nautilus-image-converter 

You’ll need to restart Nautilus or simply logout and log back in before you get the new right-click menu options. After you’ve done that you will be able to right-click on any image file and you’ll see the two new menu items: “Resize Images” and “Rotate Images”.

When you choose one of the menu items you will be presented with a simple interface to provide the relevant input parameters. What could be easier?!

2011
06.14

I should point out that I didn’t write this script, only that I found it useful while trying to put a movie with subtitles in a separate file (*.srt) onto my Android phone.

Here’s where I found the original script: http://ubuntuforums.org/showpost.php?p=7809155&postcount=6

I put the following script into a text file named hardsub.sh and copied it into “~/.gnome2/nautilus-scripts”. Then restarted Nautilus and copied the (movie).avi and (movie).srt files into the same directory and ran it by right-clicking on the video and selecting “scripts -> hardsub.sh”. It ran for a while and spat out a file named (movie).hardsub.avi that included the embedded subtitles.

Here’s the script:

 #!/bin/bash

# hardsub.sh # a basic script to hardcode subtitles into movie files using mencoder # # uses a two pass - high quality encode by default # fast option invokes a quick one pass encode # # it assumes that you are using an .srt subtitle file with the same #+ name as the movie file # # if you are using a matroska movie (.mkv) and it can't find the .srt #+ file it uses the embedded english subtitle track # # # NB: this is a preliminary script and doesn't do much error checking # # Version 0.11 # # Mike Lahey 2009 #####################

# language used for subtitle track embedded in a matroska file # for alternative subtitle (& audio) tracks try "mplayer -v movie.mkv" LANG=eng

# these mencoder options scale down the subtitles and move them #+ up just a bit SUBOPTS="-subfont-text-scale 3.3 -subpos 96"

if [ -z "$1" ]; then echo usage: $0 movie.avi [fast] echo echo fast -  do a fast one pass encode exit 1 fi MOVIE=$1 EXT=${MOVIE##*.} OUTPUT=${MOVIE/%.$EXT/.hardsub.avi}

# first make sure that our movie file is there if [ ! -f "$MOVIE" ]; then echo input file "$MOVIE" does not exit exit 1 fi

# next check if we have the SRT file and create subtitle command for # mencoder SRT=${MOVIE/%$EXT/srt}

if [ -f "$SRT" ]; then

# good we have an SRT file, so create our subtitle command SUBCMD="-sub "$SRT"" else #no SRT file? well check if we are dealing with a matroska file if [ "$EXT" == "mkv" ]; then echo "################################################" echo couldnt find "$SRT" echo so trying embedded subtitle track "$LANG" echo "################################################" SUBCMD="-slang $LANG -spualign 2" # "-spualign 2" ensures proper placement of vobsub tracks else echo could not find subtitle file "$SRT" echo echo maybe its called something else? try renameing it. exit 1 fi fi

# if the input movie is not an avi then transcode the audio to mp3 # this may result in an unnecessary transcode but it will make #+ incompatable audio streams (such as ogg/vorbis) work with an avi

if [ "$EXT" == "avi" ]; then ACODEC=copy else ACODEC=mp3lame fi

# most formats other than avi allow non-square pixels. # by invoking the scale filter we ensure that the video is # displayed with the proper aspect ratio in our avi # since were scaling anyway - scale to a multiple of 16 to make the encoding more effiecient if [ "$EXT" != "avi" ]; then SUBOPTS="$SUBOPTS -vf-pre scale=-8:-8" fi

#### if fast option was invoked, do a fast one pass encode if [ "$2" == "fast" ]; then

CMD="mencoder "$MOVIE" $SUBCMD $SUBOPTS -o "$OUTPUT"  -oac $ACODEC -ovc lavc" echo $CMD eval $CMD

if [ $? != 0 ]; then echo "################# mencoder failed ################" exit 1 fi exit fi

 #### normal two pass encode

CMD="mencoder "$MOVIE" $SUBCMD $SUBOPTS -o /dev/null -oac $ACODEC  -ovc lavc -lavcopts vcodec=mpeg4:vhq:turbo:vpass=1" echo $CMD eval $CMD

if [ $? != 0 ]; then echo "################# mencoder failed ################" rm divx2pass.log exit 1 fi

CMD="mencoder "$MOVIE" $SUBCMD $SUBOPTS -o "$OUTPUT" -oac $ACODEC  -ovc lavc -lavcopts vcodec=mpeg4:vhq:vpass=2" echo $CMD eval $CMD

if [ $? != 0 ]; then echo "################# mencoder failed ################" rm divx2pass.log exit 1 fi

rm divx2pass.log
2011
04.26

Using Cron jobs from CPanel

I’ve set this up before but couldn’t remember just how I did it. Instead of having to figure it out all over again next time, I thought I’d write it somewhere.

Setting the time in CPanel’s Standard Cron UI is very simple so I won’t bother with that but the command for triggering a web page has a few things that messed me up.

For those who don’t care to read much, here’s the command:

 wget -O - -q -t 1 'http://www.mydomain.net/doit.php?id=12345' >/dev/null 2>&1 

Or, if you’re using a .htaccess username and password, like this:

wget -O - -q -t 1 'http://username:password@www.mydomain.net/doit.php?id=12345' >/dev/null 2>&1

Of course you’ll need to insert your own url but you can otherwise cut and paste the line above and start running your php script as a cpanel cron job. But what does it all mean?

“wget” is a linux command line utility to fetch the contents of a web page. In our case we don’t care about the output of the page, only that it gets triggered – or ‘looked’ at.

“-O -” says to discard the output (aka, the page contents), we’re not interested to keep these!

“-q” put wget into quiet mode, I don’t want to know about errors here either.

“-t 1″ tells wget to only try once, if the page doesn’t work for some reason, give up.

The url should be wrapped in single quotes! This is an easy one to miss because in a simple case, it’s not required but if you have url parameters it’s a must otherwise the url gets truncated and the request won’t work as you planned it to.

“>/dev/null 2>&1″ This tells cron *not* to send out a notification that the script was called. The details of this part gets a bit hairy but I’ll do my best to explain. As the script I’m triggering already sends an email when it completes, I don’t really want the one that is sent out automatically each time the cron runs. As well, the subject for the email is the complete cron command. I don’t know about you but if your scheduled cron command includes anything even sort-of private, I’d prefer not to blast it out in email every day! Consider if you included a URL to a script behind an htaccess password, the username and password would be right there in the subject of your email every day!

The first part, “>/dev/null” redirects the output (standard out) of the command to /dev/null (the Linux equivalent of a black hole!). The second part, “2>&1″ redirects ‘standard error’ to ‘standard out’. The short story is that there is no more output from your command and therefore there’s no email to be sent out!

2011
04.18

This morning I find myself in need of a file that used to exist in an SVN project. The file was deleted several months ago and I don’t have a copy anywhere else. Finding it in my SVN repository turned out to be quite simple.

Run the following command to dump the complete activity log from the project.

> svn log --verbose > myLog.txt

Then simply open the ‘myLog.txt’ file with your favourite editor and hunt for the last mention of the file you need. I’m looking for “register.module.php”, so for me that looks like this:

------------------------------------------------------------------------
r428 | mvoorberg | 2010-11-15 22:06:33 -0700 (Mon, 15 Nov 2010) | 2 lines
Changed paths:
   M /faq.php
   M /login.action.php
   D /register.module.php

Use the following command to restore the file to the local filesystem at which point you can copy it out or do whatever you like with it. Notice the version number (427) is one less than the version that included the Delete action above.

> svn up -r 427 register.module.php

Once I copied the file out, I removed it again by simply running:

> svn up

Don’t forget to remove the ‘myLog.txt’ file when you’re done with it.