Archive

Archive for the ‘Development’ Category

More shell magic: find orphan images

June 12th, 2010 No comments

Ok, ok. So lets say you are using wordpress and want to find all the deprecated images in your theme’s image directory. Because I’m a madcap party animal, I’d say you could do something like this:

#!/bin/bash
for i in *.*; do
cd ..
RES=`grep -lIrc "$i" * | grep -v ":0" -`
if test -n "$RES"; then
echo "$i good, $RES";
else
echo "$i deprecated";
fi

#echo "move $i deprecated";
cd images/
done

fancy right? That’s how I get down for Saturday night.

Categories: Development Tags:

Random number generation in bash

June 2nd, 2010 No comments

Ok, so lets say just hypothetically that you had all the 80 episodes of the 3 seasons of Star Trek the Original Series listed in a text file named list.txt and you wanted to select one at random to simulate what you might’ve seen on channel 13 on your black and white tv.

Well, you could simply do this…

R=$[ $RANDOM % 80 + 1 ] && cat -n list.txt | grep $R

That is a pretty complex command, lets look at it piece by piece. The part before the double ampersand assigns a random number to the variable $R, based on the pseudo-random shell variable $RANDOM. We know our file is 80 lines long, so we choose a number between 0 and 80, then add one to make it inclusive of 1 and 80. The double ampersand tells bash to wait til that’s done, and if it is sucessful, then go on to the next thing. The next thing then cat’s the list (with line numbers via the -n switch), then greps the line containing your random number $R.

I do that, and it spits out something like this:
76 Season 3/Star Trek - 3x20 - The Way to Eden.avi

Categories: Development Tags:

iPhoto Export

February 5th, 2010 No comments

iPhoto is the default camera/photo application for Mac OS X computers. And it is not readily obvious how to get your images out of there, and into a folder for emailing to your web developer!–hence this post.

Permalink: http://www.kfdev.com/2010/02/05/iphoto-export/

0) Step zero is to create a new folder in your home directory. I called mine “web_uploads”.  Isn’t that a nice name?-all lower-case, no extended ascii characters, no punctuation, underscore instead of space. Boy, I just love it when I see a file name like that.

1) Crack open iphoto, and select the batch of photos you want to export. Regular Finder selection rules apply, command-click to select additional items, drag a lasso around multiple. Click one, then shift-click an arbitrary number of items forward, and all the items in the middle should be selected.

Note blue line around the selected items. I selected 5, but the same principle works for 500 or 5000.

01-select_in_iphoto

2) From the File menu, select “Export”, or use the keyboard shortcut, Command-shift-e. That should bring up the export window:

02-enter_max_width

I want the max width to be 800, so I’ve entered “800″, and iPhoto figured out that the max height should be 1067. Good going, iPhoto! I kept the default values for the other options. Format (original — my camera shoots jpegs, and that’s fine), and kept “Use extension” clicked.

Then, just click the “Export” button at the bottom.

3) Clicking the “Export” button pops up the familiar “open and save” dialog box. This has confounded more than one person, so don’t feel bad if you don’t know what to do. Or you may be saying to yourself, “hah. Babies in their cradles know how to work the open and save dialog box.” In either case, what you want to do is export the pictures into the folder you made starting out in step 0. How you do that is by choosing the folder you made, in this case, “web_uploads” Now, click “Ok”, and just watch while all the magick of exporting happens. Sweet.

03-select_folder

I know, it should be harder, but it’s not. That’s all there is to it. :)

Categories: Development Tags:

Database Normalization

August 31st, 2009 Comments off

The purpose of this document is to serve as a basic overview of database normalization. This example uses a hazarous waste disposal company as a client.

The example company has customers, who have waste generator locations, who produce waste streams.

Read more…

Categories: Development Tags:

Database Array

August 26th, 2009 No comments

Arrays are a crucial element of php. There are a number of array functions, look on php.net to see them.  http://us2.php.net/manual/en/book.array.php

Data from databases is usually returned as an array, so given a table like this: Read more…

Categories: Development Tags: