Change HTML To Lowercase For Entire Site

January 5th, 2009
No comments
This is a great script when you need to change HTML code from uppercase to lowercase for an entire site; or at least any given directory on a site. I wrote this one a while back when a friend was in charge of fixing a site that came over from a Windows server to a Linux server. Being that Windows is not case sensitive, he was going through and manually changing the HTML to lowercase. This script did the entire site in a matter of seconds.

WARNING: Please backup your site first or at least use a test copy to make sure there are no issues. Also, it only converts tagged code, that is anything between a < and > so that would include HTML and probably some PHP, ASP, etc, but not any Javascript. That being said, let’s go through the code.

Line 5: Specify the directory you want to recurse.
Line 8: This is where the function is called initially. As it works through the directories it will call itself again and again.
Line 11: Start the sub (function) definition.
Line 12: Get the directory name passed in.
Line 13: Open the directory or fail trying.
Line 14: Loop through all the items in the directory.
Line 15: If it’s not pointing to the current or upper directory, keep going.
Line 16: If it’s a directory then print out what it’s doing then call the function to recurse this directory.
Line 20: It’s a file, not a directory, get the file extension.
Line 21: Make sure it’s one of the files we want to modify - add to or remove from this list if you need to.
Line 22: Print out that it’s parsing the file.
Line 23: Open the file to read it.
Line 25-28: This is where the magic happens. It reads through the file line by line and finds anything inside the <> tags and lowercases it.
Line 30-31: Write the newly changed data back to the file.



That’s it. Please feel free to use this code and modify how you’d like. I’d love to see suggestions for improvement too.

Here is the actual code to copy/paste:
#!/usr/bin/perl
use strict;

# Specify the directory
my $dir = '/home/hallamigo/Desktop/html';

# Call the function
uptolow($dir);

# The function that does the work
sub uptolow {
  my $topdir = shift;
  opendir (DIRH, $topdir) or die "Could not open: $!";
  foreach my $item (readdir DIRH) {
    if ($item ne '.' && $item ne '..') {
      if (-d "$topdir/$item") {
        print "Recursing directory: $topdir/$item\n";
        uptolow("$topdir/$item");
      } else {
        my $ext = substr("$topdir/$item", (rindex("$topdir/$item", '.') + 1));
        if ($ext eq 'htm' || $ext eq 'html' || $ext eq 'php' || $ext eq 'asp') {
          print "Parsing File: $topdir/$item\n";
          open (FILH, "$topdir/$item") or die "Could not open $!";
          my @mod;
          while (my $line = ) {
            $line =~ s/(<.+?>)/\L$1/g;
            push(@mod, $line);
          }
          close FILH;
          open (MODH, ">$topdir/$item") or die "Could not open $!";
          print (MODH @mod);
          close (MODH);
        }
      }
    }
  }
  closedir DIRH;
}

HTML, Perl , ,

DVD to iPod Made Easy

January 3rd, 2009
No comments
Taking one of your DVDs and putting it on your iPod is relatively easy on Debian Linux (Lenny) using the very powerful applications; vobcopy, cat, and ffmpeg. Be prepared to install some new apps if you don’t already have them, but that is really easy with aptitude (apt-get).

First you’ll need to modify your sources.list file to add the debian-multimedia.org repository.
vi /etc/apt/sources.list

and add …
deb http://www.debian-multimedia.org lenny main
deb-src http://www.debian-multimedia.org lenny main

Then run the following:
apt-get update
apt-get install debian-multimedia-keyring
apt-get update
apt-get build-dep ffmpeg
apt-get install build-essential subversion
apt-get install ffmpeg

Finish up with this:
apt-get install libdvdread3 libdvdcss2 vobcopy

Put your DVD in and run the following which will create some .vob files on the same directory level where you ran it:
vobcopy

Combine the .vob files by running:
cat *.vob > full.vob

Now run ffmpeg, tweaking any settings you need to (first remove the comments):
ffmpeg \
-i full.vob \   # input file name
-f mp4 \        # output file format
-r 30 \         # frame rate
-vcodec mpeg4 \ # video codec
-maxrate 1000 \ # maximum video bitrate tolerance
-b 700 \        # video bitrate in kbit/s
-qmin 3 \       # minimum video quantiser scale (VBR)
-qmax 5 \       # maximum video quantiser scale (VBR)
-bufsize 4096 \ # rate control buffer size
-g 300 \        # gop (group of pictures) size
-acodec aac \   # audio codec to use
-ar 44100 \     # audio sampling frequency
-ab 192 \       # audio bitrate
-ac 2 \         # the 2 stereo channels
-s 320x240 \    # output resolution
-aspect 4:3 \   # aspect ratio
~/new.mp4       # filename for output

Where credit is due - the site(s) where I got help and info:
- http://ramblings.narrabilis.com/wp/howto-encode-dvd-video-for-an-ipod-ffmpeg/

Multimedia , , , ,

12 Best Firefox Add-ons

January 2nd, 2009
No comments
For the last couple of years I’ve used different Firefox Add-ons off and on and now have it narrowed down to 12 that I use almost every day.  I’ve got a screenshot attached at the very bottom showing the Add-on Installation window.  My list is in alphabetical order, by the way, not by popularity.

1. DownloadHelper
The easy way to download and convert Web videos from hundreds of YouTube-like sites. This works also for audio and picture galleries.

2. Firebug
Firebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page…

3. Flagfox
Displays a country flag depicting the location of the current website’s server and provides quick access to detailed location and webserver information.

4. Google Reader Watcher
Checks your Google Reader for unread news.

5. Greasemonkey
Allows you to customize the way a webpage displays using small bits of JavaScript. …

6. Organize Status Bar
This extension will enable you to organize your status bar icons. You can now rearrange or remove any item (icon or text) in the Firefox status bar. If your status bar is full and cluttered like mine was, give this a try.

7. ReloadEvery
Reloads web pages every so many seconds or minutes. The function is accessible via the context menu (menu you get when you right click on a web page) or via a drop down menu on the reload button …

8. Screengrab!
Screengrab saves entire webpages as images…

9. SearchStatus
Display the Google PageRank, Alexa rank and Compete ranking anywhere in your browser, along with fast keyword density analyser, keyword/nofollow highlighting, backward/related links, Alexa info and more.

10. ShowIP
Show the IP address(es) of the current page in the status bar. It also allows querying custom information services by IP (right mouse button) and hostname (left mouse button), like whois, netcraft. Additionally you can copy the IP address to the clipboard.

11. Web Developer
Adds a menu and a toolbar with various web developer tools.

12. YSlow
YSlow analyzes web pages and tells you why they’re slow based on Yahoo’s rules for high performance web sites.



Firefox

Easy Apache Basic Authentication

January 1st, 2009
No comments
This is a really handy set of instructions for when you need to restrict access to a website or a directory under a website.  You will need to have access to both the Apache config for your site and the .htaccess file you need to create/modify.

1. In the httpd.conf file put the following for the domain or directory (you can have other options, this is the minimal):
<Directory "/full/path/to/the/directory/to/restrict">
  AllowOverride AuthConfig
  Order deny,allow
  Deny from all
</Directory>

2. In the root of the domain or directory put an .htaccess file with:
AuthType Basic
AuthUserFile /full/path/to/your/new/password/file
AuthName "What You Want The Popup Login Window To Say"
require valid-user
satisfy any

3. Make the password file (you will be prompted to create the password):
/usr/local/apache/bin/htpasswd -c /full/path/to/your/new/password/file username

Apache ,