Archive

Author Archive

Wordpress and Windows Live Writer

July 28th, 2008 ^Lestat No comments

liveWriter

I haven’t posted much (No, this isn’t a blogpology) lately. Mainly because I haven’t had the passion to write about anything. Secondly because I just don’t want to do the work of messing with the UI and entering one.

Thanks for the tip from my buddy TDavid who pointed me toward Windows Live Writer.

The setup was simple for this machine (Vista Business edition sp1). It’s got some really neat features. First off inserting hyperlinks is a snap. So is adding pictures. Also drag and drop tables, and image resizing.

It also includes preview views, and category selecting, tagging, and you can post date posts.

You can post drafts, post live, and even save drafts locally. I find it much easier to use than the WP UI.

Categories: Blog Adventures Tags:

php: Checking if a directory is empty

February 21st, 2008 ^Lestat No comments

I found myself working with text files a little more recently and was looking for a way to tell if a directory was empty. Why? In my case I wanted to check if a directory was empty. If it wasn’t, to grab the data in those files and put them in a database.

What I didn’t want to do was have the expense of connecting to a database if the directory didn’t have any files in it to begin with. After chatting with my good friend TDavid at php-scripts.com, I decide to run with his suggestion…

Fill (or don’t fill) a variable with information if there were files in the directory. Then test the var to confirm or deny if there are files in the directory. It’s really a small bit of code…

//----- Check if ticket dir has files. If it has files,
// set a variable to hold the list of file names.

$dir = "../path/to/my/textfiles";      // set directory

if($handle = opendir($dir)){           // open directory

	while(($file = readdir($handle)) !== false){
		if($file != "." && $file != ".."){
			$file_list[] = $file;  // Set file list variable
		}

	}

	closedir($handle);      // Close directory
}

If there are files in this directory, the variable $file_list would not only exist, but also contain files. For example…

Array
(
    [0] => 195972.txt
    [1] => 196027.txt
    [2] => 196053.txt
    [3] => 196067.txt...
)

If there aren’t any files in this directory, the variable $file_list would not even exist because no $file would be inserted into it. At this point we can check/ test the variable to output or do further processing…

if(isset($file_list)){
    echo "This dir has files!";
    // perform further processing
    // eg: collect each files contents
} else {
    echo "This dir has NO files!";
    // stop processing
    // Not much do do with this since there are no files
}

Of course there are a few ways of checking to see if a directory is empty, but this way seemed to be the most simplistic to me. If you wanted to you could turn the entire lot into a function for reuse, and less script code clutter.

Comments? Questions?

php, empty directory

Categories: Computing, Programming, php Tags:

MySQL Conditional Insert

December 20th, 2007 ^Lestat No comments

I came across a situation where I needed to pull records from 1 db to another on a recurring basis. I read many different ways to do it via searching around the net. Some of the suggestions included creating a temporary table and copying it over. What was lacking was that sometimes the new table also needed to be UPDATED, as the information changed from the original table.

I’ve come up with a dirty little example to show this can be done. There are more keywords that can enhance the ON DUPLICATE KEY UPDATE function even more. The Example is assuming an “employees” table that looks like so:

employees
id (PK)
first_name

For brevity, I’ve left out connection data etc;

$myArray = array(0 => array('id' => '1', 'fname' => 'Steve'),
                      array('id' => '2', 'fname' => 'sara'),
                      array('id' => '3', 'fname' => 'Matt')
                 );

// Don't forget to validate & clean your data
// Connect to db here 

foreach($myArray as $key => $value){
          $query = "INSERT INTO employees
          (id, first_name) VALUES ('$value[id]', '$value[fname]')
          ON DUPLICATE KEY UPDATE first_name = '$value[fname]'";

          $result = mysql_query($query);

          if(!$result){

                    print("Problem: " . mysql_error() . "");
          } else {

                    print("Success !");
          }

}

Read the manual on this for more information. This snippet will INSERT if a UNIQUE (in this case ‘id’) does not exist. It will UPDATE any existing unique. In this case any existing ‘id’s, the ‘first_name’ column will get updated.

One could also use the REPLACE function. As I understand the difference, REPLACE will DELETE any matching uniques, and INSERT a new record in it’s place.

Comments? Better ways? I’m always up for learning something new so please chime in ;-)

Categories: MySQL, Programming, php, php Snippets Tags:

Get your mug on soda bottles

November 28th, 2007 ^Lestat No comments

Jones soda

Jones soda (of which I do own a few shares of) is offering the feature of creating your personalized label on a flavor of choice. As of this writing the feature is offered for 29.99 + S&H.

The order process is pretty simple really. Sign up for an account, upload an image, and pay the bill. The image to upload can be anything you like really. You can upload from a url, or from a local file on your computer. The image needs to be 2.25″ wide by 1.875″ tall at 300dpi (or 675 x 563 pixels at 300dpi). If you are unsure of what those sizes are, Jones provides sample templates of jpeg, TIF, and bitmat formats to measure up. They also give additional helps by providing image resizing instructions for Photoshop, Paintshop Pro, and Macromedia Fireworks.

After you have your image uploaded, you also have the option to add some text to an area just above the nutrition panel on the back. It’s plain text and allows up to 7 lines of 50 characters each (including carriage returns).myJones Back of Label
After your customisation you are sent to a page to finish adding the billing options, and to choose your flavor. The flavors are limited but the FAQ states “We rotate the flavors regularly, so check the site often to see if your favorite flavor is available.” One of the more questionable flavors this month (Nov) is Turkey + Gravy?? No thanks. I’ll pass.

myJones select flavor

You can’t mix flavors, or images. 1 flavor and 1 image per case. It’s supposed to take 3-4 weeks for delivery. We’ll have to do an update on that. I ordered mine on Nov 15.

If your interested Jones provides a photo gallery page where you can view labels of already submitted images. It’s not entirely clear but it appears as if there is a photo/label contest going on. The winners photo will make it to officially released cases to retailers.

Categories: General Interest, Personal Tags:

A List of Black Friday online sites with lists

November 20th, 2007 ^Lestat No comments

The rush is just around the corner. I found a bunch of sites that list places and prices of ‘hot’ Black Friday deals. Most of which include links to many major stores:

How much shopping will you be doing online this year?

Categories: General Interest, Personal Tags: