Brad's Blog

web dev, django, running, food, or whatever

Recursively deleting files (based on regex) 2008-09-09

While we're on the topic... (the topic being recursively doing stuff to files), I often want to delete all the files in a hierachy of directories that match a regular expression (or regex).The typical scenario for this is, "I want to delete all of my compiled python files."Here's how I do it:find ./ -type f -name "*.pyc" -exec rm {} \;find ./ -type f -name "*.pyc" should find all files ending in .pyc under the current directory. Once ...

Recursively Renaming files 2008-09-05

My hosting provider offers PHP4 and PHP5. Unfortunately, all files ending in .php get interpreted by PHP4, while all files ending in .php5 get interpreted by PHP5. So, how do I quickly change all of my files that end in .php to .php5?Do a google search for "recursively rename files", and you might run across this:http://seal-7.blogspot.com/2006/12/recursively-rename-files-with-regex-one.htmlSo, to accomplish my task, I use the following:find . -type f -print0 | xargs -0 rename ...

Looking Forward to BarCampMemphis 2008-09-05

BarCamp is coming to Memphis!A project of LauchMemphis, this is yet another event focused on growing the local tech industry. It follows the successful Memphis Startup Weekend (which resulted in Spynnr).The theme of BarCampMemphis is FLUX: Your Paradigm, and from the About BarCampMemphis page: In a constantly shifting environment, what do you do? Entreprenuers and businesses are constantly trying to walk the line between chaos and control, between the cutting edge and solid ground. Things are in FLUX ...

Safari is Cooler than you Think! 2008-09-04

When you really start digging into Mac OS X, it's fairly mind-boggling how much extra stuff it has that your average user never sees. I recently encountered a problem on my MacBook Pro, where the Optical Audio was overriding my internal speakers, which prevented me from hearing any audio (without using headphones). Unfortunately, there's no easy-to-access preference pane to enable or disable various audio devices. This led me on a search for command-line utilities to manage system preferences ...

Net Neutrality 2008-08-13

Save the Internet | Rock the Vote

How to update an input value with the value from a selected option using Prototype 2008-08-12

Today, I needed to set the value of an HTML input element based on the value of a option in a select element. This is fairly easy to do with Prototype's writeAttribute. Here's an example:A simple javascript function to do the work:function populate_input(){ var field = $('tf_select').getValue(); $('tf').writeAttribute('value', field);}A simple HTML snippet to see it in action:<div><p><select id="tf_select" name="tf_select" onchange="populate_input();"><option value="">- choose one -</option><option value="v1">value ...

Extracting and Encoding Still images to/from Video files 2008-08-11

ffmpeg is a cool tool.While it's got many many features and uses, I mostly use it to extract frames (or still images) from a video and create a video out of frames. While instructions on how to do this are posted on their list of FAQs, it's probably worth posting again.To extract all frames from a video file named "video.mpg": ffmpeg -i video.mpg frame%d.jpgThis will produce a series of JPEG image files ...

The Apple Dock is a Mirror! 2008-08-08

I guess I'm still a relatively new Mac User, but I consider myself fairly technical and probably more savvy that your typical Mac user (though there are a lot of mac users who are far more savvy than I!)Imagine my surprise when, while working tonight, I discovered that the Dock in Leopard is a Mirror! Yes, I'd noticed the reflection of the Icons, but tonight, I actually saw my cursor (in Terminal) moving as I typed... that ...

PHP is chopping off my Access Memo Fields 2008-07-30

I've got a few simple web forms that use PHP to read and write to an Access database (running on IIS), and I just spent the last few hours frantically trying to figure out why some of my Memo fields were being truncated around 4000 characters. I know Memo fields "should" be able to contain up to 65536 characters, and I could verify this by inserting data directly into the database. However, when querying the database through PHP (using ...

Django: Generating an Image with PIL 2008-07-16

I've been reading through the Django Book, and in chapter 11 they talk about generating non-HTML content (such as PDF files, Images, RSS/Atom Feeds). They mention using PIL to generate images, but they don't give an example. So, I thought I'd post a simple example View that generates an image.def pil_image(request): ''' A View that Returns a PNG Image generated using PIL''' import Image, ImageDraw size = (100,50) # size of the image to create ...