Archive for the ‘Open Source’ Category

bash script to copy all files in a directory and convert uppercase characters to lowercase

So, I recently found out that the version of PHPList that we were using on a client site (2.10.2) had a nasty bug in it where it would convert all URLs in a text version of an email message to lowercase. This bug is fixed in the latest version (2.10.3) but it left a number of subscribers complaining that the links in their email were broken.

I wrote this handy bash script to fix those links for emails that had already been sent out.

To use this script, follow these steps on your server command line. This is a bash script.

First, copy this code to your clipboard:


#!/bin/sh

# This script takes the contents of a directory and will make a copy
# of every file converting any uppercase characters to lowercase
# (Useful because PHPList had a bug where it converted URLs to
# lowercase in text-only mailing list messages and the links were
# therefore broken. This script will enable those links to work.)

for file in *
do
if [ -f "$file" ]; then
filelower=`echo $file | tr “[:upper:]” “[:lower:]“`
if [ -f "$filelower" ]; then
echo “You are trying to copy a file that has the same name as an existing file.”
echo “$filelower file was NOT copied.”
echo “”
else
if [ -d "filelower" ]; then
echo “You are trying to copy a file that has the same name as an existing directory - $filelower”
echo “$filelower file was NOT copied.”
echo “”
else
# not a file or directory. make a copy of the file
cp “$file” “$filelower”
fi
fi
fi
done

Next, you are going to create a bash script file.

$ vi cp_files_to_lowercase.sh

Press i and then paste in the code.

Press ESC then :wq to write the file and quit vi.

Next you are going to set the executable permission on the file.

$ chmod 700 cp_files_to_lowercase.sh

Next, change directory to the place you want to run the script on. In this case, we’ll change to the images directory.

$ cd images/

Let’s see what’s in the directory currently:

$ ls

$ Image1.jpg IMAGE2.jpg image3.jpg

Now run the script.

$ ../cp_files_to_lowercase.sh

The script will make a copy of any file that has an uppercase character in it and name it the same thing except all lowercase. It will tell you if the file already exists as a completely lowercase file (it won’t copy a file onto itself).

Now let’s see what it did:

$ ls

$ Image1.jpg image1.jpg IMAGE2.jpg image2.jpg image3.jpg

Now any URLs should work and any previous text-version emails that were sent out using the old version of PHPList should now have working links again.

DISCLAIMER: This script will copy files on your server. I am not responsible for any problems that this causes. I’ve tested this on my server, but you’d be wise to test what will happen first. If you add an echo in front of the cp command in the script you will see displayed what it would do without actually doing it.

Popularity: 6% [?]

Use Flash to create a custom upload button with SWFUpload beta

What is it?

  • Upload files via flash to get the flash-upload dialog goodness.
  • Only display chosen filetypes in dialog
  • Upload multiple files at once by ctrl/shift-selecting in dialog
  • Trigger javascript functions on start, cancel, progress and complete
  • Get file information/size before upload starts
  • Style upload buttons any way you want
  • Do progress-bars/information using valid XHTML and CSS
  • No page reloads, display uploaded files as they are finished
  • Works on all platforms/browsers that has Flash support.
  • Degrades gracefully to a normal html upload form if Flash or javascript isn’t available

Sounds pretty neat. MIT Open Source licensed too.

SWFUpload beta

(Via del.icio.uspopular on RSS2.com)

Popularity: 2% [?]

WordPress 2.0.5 - Ronan - new release that also includes important security fixes

And to think, I was just browsing the WordPress Trac repository earlier today looking at their sweet upgrade scripts in /wp-admin/.

Time to upgrade our sites. There are a lot of them. We love WordPress.

It’s new release time. The latest in our venerable 2.0 series, which now counts over 1.2 million downloads, is available for download immediately, and we suggest everyone upgrade as this includes security fixes. We’re breaking the tradition of naming releases after jazz musicians to congratulate Ryan Boren on his new son (and first WP baby) Ronan.

What’s new? We have about 50 or so bugfixes, which you can review on our dev tracker here, mostly minor bug fixes around feeds, custom fields, and internationalization. If you’d like a nitty-gritty view, check out Mark’s blog post on the changes.

Development Blog - WordPress 2.0.5 - Ronan

Download the latest version of WordPress now (2.0.5)

Popularity: 2% [?]

Wordpress MU 1.0 is released!

I’ll be upgrading blog-o-matic.com and Share the Practice with this new release… We should also do Niner Blogs as well, come to think of it.

WordPress MU is an official branch of WordPress that is designed for managing and hosting thousands of blogs instead of just one. It’s the software that powers WordPress.com, for example. MU has been in heavy development for about a year now, and we’ve finally polished it up to a place where we feel like it’s ready for public consumption. Since setup is a bit more complex than the 5-minute install of regular WordPress, MU is best suited for a more server-savvy audience. You can download it on the WordPress MU site.

Development Blog - MU 1.0 and bbPress

Popularity: 2% [?]

lastRSS.php - PHP RSS parser/reader

lastRSS.php - PHP RSS parser/reader

lastRSS.php is simple yet powerfull PHP class to parse RSS.

Popularity: 2% [?]

SourceForge.net: Tesseract OCR

SourceForge.net: Tesseract OCR

A commercial quality OCR engine originally developed at HP between 1985 and 1995. In 1995, this engine was among the top 3 evaluated by UNLV. It was open-sourced by HP and UNLV in 2005.

Popularity: 1% [?]

Upgraded the firmware on my Linksys WRT54G to Thibor’s HyperWRT firmware

I’d been wanting to do this for a while. The biggest feature for me was the “static” DHCP setup, where you can keep DHCP for most machines on your network but assign a couple of machines to static IPs that never change. This comes in handy when you’re running servers that need to always have a specific port forwarding to them.

The installation was really easy - just download the latest firmware, unzip it and upload it using the Linksys web gui.

One note: Use Firefox, not Safari when navigating the new/upgraded pages. It kept all the pre-existing data / preferences.

HyperWRT is a GPL firmware project for the Linksys WRT54G/WRT54GL/WRT54GS and WRTSL54GS wireless routers based on the
latest stock Linksys firmware. The original goal of the HyperWRT project was to add a set of features–such as power boost–to the Linux-based Linksys firmware, extending its possibilities but staying close to the official firmware. Over time, it has continued to be updated with newer Linksys firmware, and
incorporated many more features typically found in enterprise routing equipment.

Thibor’s HyperWRT page

Popularity: 3% [?]

Prototype Carousel - Javascript scrolling window

This class is a Prototype/script.aculo.us version of the excellent Bill Scott’s Carousel component.
I needed it to be able to use it in Ruby On Rails application without using the 200KB of YUI JS classes.

This library is licensed under a MIT-style license, so you can use it for anything you like, as long as you include the copyright notice.

The current version (0.1) is the first release with only few parameters. I am working on it to have a lot of more features.
This version has

* Ajax or static content
* Horizontal orientation
* Rails helper

It’s has been tested on IE 6, Firefox (PC,Mac), Opera 9, Safari and Camino.

Check it out: Prototype Carousel

Popularity: 5% [?]

Unix command line tip of the day: How to recursively add all newly added files to Subversion in an existing working copy

When using Subversion for version control, if you have a working copy checked out and then you want to add a variety of new files and directories to the existing ones, you might do something like this:

[code]cp -R newfiles/* files/[/code]

Unfortunately, svn add only will add files or directories in the immediate directory unless you explicitly specify each new file or directory to add when you are adding to directories that already exist.

This means that if there is a directory called images in both files and newfiles that is already under version control, and inside of newfiles/images/ is a new directory called icons, running svn add * from within the files directory will NOT recursively add it as you might hope it would.

Here is a one-line command-line way to find all new / unknown files using Subversion’s status command and recursively add all of the found files to your current working copy, ready to commit.

[code]svn st | grep ? | sed ’s/^?[\t]*//;’ | xargs svn add[/code]

This runs Subversion status, then filters the resulting list using grep to find only entries with a ? in front of them (unknown files), then pipes the resulting list through sed to remove the question mark and the leading space, then pipes the resulting set of files / directories into Subversion add using xargs, which operates on each supplied line.

Popularity: 2% [?]

Fix for PHP PEAR on OS X 100% CPU problem

I was rebuilding PHP 5.1.4 for my G4 PowerBook to use with Apache 2.2.2 and MySQL 5.* when I ran into this problem using PEAR:

When I would run a command like:

pear install Log

PEAR would download the package, indicate that it was done, and then hang, consuming 100% of the CPU and never do anything more.

I finally tracked down that this seems to be a problem with PHP uncompressing the file (a .tgz). I’m not entirely sure WHY PHP is having this problem, but I did find a workaround solution:

Instead of this:

pear install Log

Run this:

pear install -Z Log

This requests just the .tar version of the file, which is larger, but doesn’t require the .tgz uncompression. Once I used that command, PEAR worked like it used to (just fine, super quick, actually works, etc…)

P.S. This is the ./configure command that I used to compile PHP:

./configure –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql –with-gd –with-libjpeg=/sw –with-libtiff=/sw –with-mysql=/usr/local/mysql –with-mcrypt –enable-soap –with-curl –enable-trans-sid –enable-ftp –with-ldap –enable-exif –with-mhash –with-openssl –with-zlib –with-ttf –enable-gd-native-ttf –with-zlib-dir=/usr/local/lib/ –with-png-dir=/usr/local/lib/ –with-bz2

I’m not sure if this is an issue with how I compiled PHP, or OS X Tiger, or zlib, or what. I’m glad to have a working PEAR again though even if it isn’t quite as efficient as it would be otherwise.

Popularity: 2% [?]