Raam Dev » thoughts essays journal notes contact about subscribe rss

Posts Tagged: Tricks

iCal Missing AM/PM Option? Change to 24-hour Mode!

Am I crazy or is there no way to make iCal show AM/PM when editing a calendar entry?

iCal Missing AM/PM Option

The AM/PM option IS there, because if I use the arrow key to move over to next field, there’s a hidden AM/PM field which I can change. However, unless I know what it’s already set to, I have no way of knowing what I’m changing it to. Very annoying.

My fix for this is to simply use 24-hour mode, which I already use on my main system clock anyway. (By the way, if you have trouble converting 24-hour time to 12-hour time, you might want to check out my post on Learning to Interpret Military Time.) Unfortunately, enabling the “Use a 24-hour clock” option in the Date & Time settings does not enable 24-hour clock mode in iCal. To do this, you must modify the International settings (!?).

System Preferences -> International -> Formats -> Times -> Customize

Changing time format

From here, you can select and delete the AM/PM option from the white field and then click the little arrow on the hour field to change it’s format to 24-hour (this screen is very non-intuitive for something made by Apple). I made the changes to Short, Medium, Long, and Full time formats and then clicked OK and WHAM! iCal showed 24-hour time and made it possible to easily change the time on an entry.

iCal 24-hour format

Uppercase table tags create extra whitespace in WordPress

When creating tables inside a WordPress post, using uppercase TABLE and/or TR tags causes additional whitespace to appear above the table. I say and/or TR tags because uppercase TABLE tags alone don’t seem to create additional whitespace, however uppercase TR tags do. If you combine the use of uppercase TABLE and TR tags together, they create even more whitespace!

First, lets see what normal output looks like:

This is a simple sentence used to demonstrate an odd spacing effect when uppercase TABLE and TR tags are used in a table.

<table cellspacing="10" cellpadding="0" border="0">
<tr>
<td align="center"><img src="/wp-content/uploads/2007/12/br.jpg" border="0"></td>
<td align="center"><img src="/wp-content/uploads/2007/12/br.jpg" border="0"></td>
<td align="center"><img src="/wp-content/uploads/2007/12/br.jpg" border="0"></td>
<td align="center"><img src="/wp-content/uploads/2007/12/br.jpg" border="0"></td>
<td align="center"><img src="/wp-content/uploads/2007/12/br.jpg" border="0"></td>
</tr>
</table>

WordPress output:

And now, if we copy the exact same content and make the TABLE and TR tags uppercase, look what happens:

This is a simple sentence used to demonstrate an odd spacing effect when uppercase TABLE and TR tags are used in a table.

<TABLE cellspacing="10" cellpadding="0" border="0">
<TR>
<td align="center"><img src="/wp-content/uploads/2007/12/br.jpg" border="0"></td>
<td align="center"><img src="/wp-content/uploads/2007/12/br.jpg" border="0"></td>
<td align="center"><img src="/wp-content/uploads/2007/12/br.jpg" border="0"></td>
<td align="center"><img src="/wp-content/uploads/2007/12/br.jpg" border="0"></td>
<td align="center"><img src="/wp-content/uploads/2007/12/br.jpg" border="0"></td>
</TR>
</TABLE>

WordPress output:

I’m running the latest version of WordPress (v2.3.1 as of this post) and I have confirmed this oddity appears on multiple platforms (Mac OS X 10.4.11, Windows XP SP2) with multiple browsers (Firefox 2.0.0.11 on Windows and OS X, Internet Explorer 6.0.29 and Opera 9.22 on Windows, and Safari 3.0.4 on OS X).

Upon closer inspection of the actual output produced by WordPress in my browser (using view source), I discover the problem:

Browser output of the lowercase example:

<p>This is a simple sentence used to demonstrate an odd spacing effect when uppercase TABLE and TR tags are used in a table.</p>
<table cellspacing="10" cellpadding="0" border="0">
<tr>

Browser output of the uppercase example:

<p>This is a simple sentence used to demonstrate an odd spacing effect when uppercase TABLE and TR tags are used in a table.</p>
<p><TABLE cellspacing="10" cellpadding="0" border="0"><br />
<TR></p>

It appears that WordPress is looking for the <table> and <tr> tags and when it finds them it doesn’t automatically add <br /> and <p> tags around them like it does with the rest of your post. (I don’t use the visual editor, so I’m able to easily add hand-written HTML directly to my post.) However, the search for <table> and <tr> must be case sensitive which causes problems if your tags are anything but lowercase.

I would normally report this as a bug to WordPress, but I’m sure the reply will be that all XHTML must be lowercase and so the problem is not relevant. I say that’s bad backwards compatibility. :|

Recovering from CTRL+S in Putty

Every once in awhile, I’ll press CTRL+S by accident while I’m inside a terminal window. For the longest time, this simple accidental keystroke meant I had reconnect to my Linux server, kill whatever program I was running, and then start it again. Eventually I got sick of this happening and decided to do what I should have done in the first place: Google It.

Apparently CTRL+S actually does XOFF, which means the terminal will accept key strokes but won’t show the output of anything. It will appear as if your terminal is dead when it’s really just waiting to be turned back on. The fix? Simply press CTRL+Q to turn flow-control on (XON). If you pressed a whole bunch of keys before pressing CTRL+Q, you’ll see the output from those keystrokes.

In the Windows world, CTRL+S is used as the Save command. Over the years, I’ve developed the habit of pressing CTRL+S every few minutes while working on a document, simply because I’ve had too much work lost from stupid errors. Thankfully, this habit will no longer get in my way of working in the Linux world.


Recursively Renaming Multiple Files

I needed to rename a bunch of files for a customer at work the other day — more than 60 files. The files were on a Linux system, so I knew there was an easy way of doing it. A few days ago I used perl to search and replace a piece of text in a several files , so I decided to find a way to do it with perl.

I found the following script on this site:

#!/usr/local/bin/perl
#
# Usage: rename perlexpr [files]

($regexp = shift @ARGV) || die "Usage:  rename perlexpr [filenames]\n";

if (!@ARGV) {
   @ARGV = <STDIN>;
   chomp(@ARGV);
}

foreach $_ (@ARGV) {
   $old_name = $_;
   eval $regexp;
   die $@ if $@;
   rename($old_name, $_) unless $old_name eq $_;
}

exit(0);

After saving the script to a file called rename (and chmod 755‘ing it) I was able to run the following command to change the file extension on all .JPG files from uppercase to lowercase .jpg. To search for all files underneath a particular directory, I used the find command and piped it’s output to the rename script:

find /home/customername/content/images/ | rename 's/JPG$/jpg/'

A few seconds later and all the files were renamed! This script is incredibly versatile, as you can pass it any regular expression! A few quirks I found were that you cannot reference the script; you must use it from the directory you stored it in (find / | ~/rename 's/JPG$/jpg/' won’t work). This is because the script uses itself (on line 17). This also means if you save the script as something other than rename, you must also modify line 17 of the script.

Easily Replace all Occurrences of a String in Multiple Files Using Linux

This came in handy when I needed to change the IP address used in several links on a customer’s site. I simply specified the path to all the web files, and ran a command similar to the one below.

find /path/to/directory -name "*.txt" | xargs perl -pi -e 's/stringtoreplace/replacementstring/g'

Note that you can change *.txt to just * to search inside all files. Also keep in mind the replacement command will be completed recursively (files nested inside directories will also be searched).

Where in the world is Raam?

Join the Facebook Community

Raam Dev » thoughts essays journal notes contact about subscribe rss

Powered by WordPress and other Open Source Software
Uncopyright by Raam Dev