Browsing articles in "Code"

Time Flies when you’re…

Apr 27, 2012
Mark
Comments Off on Time Flies when you’re…

April has pretty much flew by this year. Free time has been slim to come by and when it was available, I spent the majority of it gaming rather than writing. Not to mention three different projects I’m currently trying to complete. Swapping from one to the next and then back again isn’t a path to completion. Two are close but the third keeps twisting and changing. The brain keeps coming up with more ideas than my I have time to design and code. What appears to be a final design shifts into something larger and more complex. It appears close for the moment.

Yesterday, the local telco decided I didn’t really need an active line. Somewhere amid other repairs, my phone line got disconnected and out went the internet connection. Trivial to fix but it took 15 hours before they got to the repair. A fair amount of muttering occurred yesterday. Hard to finish coding anything when half the files are inaccessible. Note to self: keep even prototypes committed to the code repository.

Given the time wasted awaiting the DSL repair, I’m just going to spend the afternoon working code and watching a bit of barbecue. One the menu for this evening is stuffed pork loin smoked with freshly cut crab apple. The store had ripe mango available so I’ll glaze it up with mango-jalapeno sauce at the end.

Mark’s Stuffed Pork Loin

1 Pork Loin (as big as you want)
1 Apple
1/2 Onion
3 Celery Stalks
1/2 cup Brown Sugar
1/2 tsp Cinnamon

Dice apple, onion and celery and put into a bowl. Increase or decrease the amount depending on the size of the pork loin. Sprinkle with cinnamon. Add the brown sugar and mix well.

Split the pork loin three quarters of the way along the long side. Fold open. You may want to leave the ends of the pork loin uncut to aid in keeping the stuffing from falling out. Fill the pork loin with the apple/onion/celery mixture. Fold closed. Using cotton cooking string, tie the loin back together. Place strings every couple of inches.

Apply dry rub to tied loin. Refrigerate for 1-2 hours. [I just prepped it and then went to get the smoker going.] Place loin on the smoker and baste every 45 minutes. Cook at 250 degrees for 5-6 hours. Apply glaze for the last 20 minutes of cooking. I’m using apple juice for basting with a jigger of brandy.

Just over an Hour

I better invite some friends for grub tonight. If I don’t, I’ll be eating pork loin for a couple of days.


Comments Off on Time Flies when you’re…

Old West Name Generator

Apr 16, 2012
Mark
Comments Off on Old West Name Generator

The Old West is cool genre. The rich history is something I enjoy in games and reading material. So I decided to whip up a quick Old West Name Generator. The process was not quick or easy. Unlike name data from modern times, only a few databases exist for names during the latter half of the 1800’s. Most of those databases only allow minimal interaction due to the prodigious amount of work spent assembling the data from hand written census, military, and other records.

Strangely, the United States National Park Service has a searchable database of six million individuals from the Civil War. The NPS is a government funded organization but apparently has no released the database to the public. I settled on using a number of public rosters of Civil War veterans along with data on popular given names from the Social Security Agency. What started as around 40,000 records resulted in just under 14,000 unique names [10K surnames, 2.3K male names, and 1.3 female names]. The data set is significantly smaller than I envisioned initially. Tip of the hat to the individuals who have endeavored to transcribe the oft illegible records from that era.

Much like the data for the Medieval Name Generator, this database will take additional effort and research to flesh out fully.


Comments Off on Old West Name Generator

Chasing the phantom dragon…

Apr 9, 2012
Mark
Comments Off on Chasing the phantom dragon…

Today, I discovered things were broken. Namely, the Treasure Book on Demand’s PDF generation system. The output was run together without a single space in between words. So I began to chase the bug.

In the process, I overwrote code that took hours to create. Test after test after test, couldn’t repeat the problem in a standalone environment. Strange? I thought so. So I battled further. I broke things that were previously functional. Then trashed even more functional code.

The dragon? Bug in the browser. I didn’t have to touch a thing. #)$*#$ idiot. Backup? Yeah, source control. Checked in? Of course not. Battle. Rage. Recreate. ##)*$!@#.

Solution? Backup of a backup.

Now, what the hell was I planning to do tonight? Doesn’t matter, I cannot get there from here…


Comments Off on Chasing the phantom dragon…

ROTWORLD NPC Generator Repaired

Mar 28, 2012
Mark
Comments Off on ROTWORLD NPC Generator Repaired

Big shout-out of thanks to Mark C. for pointing out the ROTWORLD NPC generator was broken. During the optimization of the city name generator a few days ago, I changed the database schema but failed to update the RWNPC page.

More code I need to re-factor so it can fail on one element without causing the entire process to fail. Code can always be improved. Especially hobby code that I don’t spend sufficient energy on.

Thanks again, Mark, I truly appreciate you taking the time to let me know.

Tags:

Comments Off on ROTWORLD NPC Generator Repaired

A blend? Puree? Whip? Esoteric Creature Generation meet Classic Monsters

Mar 26, 2012
Mark

Complete and utter synapse firing in odd directions today. Somewhere around noon I decided to blend Raggi’s Random Esoteric Creature Generator with classic fantasy monsters (via Labyrinth Lord). Granted, the idea is in complete conflict with Raggi’s original intent of producing one-off interesting creatures.

Why? Sometimes “stock creatures” are a bit dull. Almost everyone knows what most of the creatures do. Change it up, shift the universe, and see what comes out. Good goal. Guaranteed to produce odd results.

It does.

Tags:

City Name Generation Expanded

Mar 23, 2012
Mark
Comments Off on City Name Generation Expanded

Yea old City Name Generation System got a bit of an upgrade. The release is called ExtendzShazam — now bigger and pokier.

New countries: Cuba, Greece, Japan, Morocco, Pakistan, Taiwan, Thailand, Venezuela, Vietnam, North and South Korea, and South America.

Updated names: Australia, Austria, Belgium, Brazil, Canada, Croatia, Denmark, Finland, France, Germany, Hungary, Italy, Ireland, Luxembourg, Mexico, Netherlands, Norway,, Poland, Portugal, Romania, Spain, Sweden, and Turkey.

During the process a few duplicate entries did manage to sneak into the system. Overall, the system got a couple of hundred thousand new names. A few minor duplicates can get purged downstream.

This update is courtesy of the GNS.


Comments Off on City Name Generation Expanded

Refactoring Day

Mar 15, 2012
Mark
Comments Off on Refactoring Day

I have a couple of dozen different generators all using similar but not identical database access routines. Tonight, I began to build up a core set of database access functions designed to replace all the redundancy. A single set of data handlers will be far easier to debug and enhance.

The bulk of my generators extract data from a single database, table, and column. Additionally, all of my underlying data contained in databases structures uses Sqlite v3. Thus the code is specific to sqlite. An additional layer of abstraction isn’t necessary.

Here’s what I’ve come up with so far. I will not be surprised to find additional code duplication as I begin to update the generators.



// Fetch a single column from the specified database, table and column name.
// Query executes using RANDOM() ordering (use RAND() for other dbs)
// Returns an array of results
function GetRandomResultsFromDatabase($database, $table, $column, $number = 0)
{
    $db = new PDO("sqlite:$database");
    if($number > 0)
        $query = "SELECT $column from $table ORDER by RANDOM() LIMIT $number";
    else
        $query = "SELECT $column from $table ORDER by RANDOM()";
    $rval = $db->prepare($query);
    $rval->execute();
    $results = $rval->fetchAll(PDO::FETCH_COLUMN, 0);
    return $results;
}

// Fetch all entries in the specified column from the given table and database
// Return array of column entries
function GetSingleColumnResultsFromDatabase($database, $table, $column)
{
    $db = new PDO("sqlite:$database");
    $query = "SELECT $column from $table";
    $rval = $db->prepare($query);
    $rval->execute();
    $results = $rval->fetchAll(PDO::FETCH_COLUMN, 0);
    return $results;
}

// Not as efficient as GetRandomResultsFromDatabase(). Pulls the entire data
// set from the database.   
// Returns an array of results.
function GetFullRandomResultsFromDatabase($database, $table, $column, $number = 1)
{
    $results = GetSingleColumnResultsFromDatabase($database, $table, $column);
    return RandomElementsFromArray($results, $number);
}

// Returns array of random results from the input array
function RandomElementsFromArray($input_array, $number = 1)
{
    shuffle($input_array);
    return array_slice($input_array, 0, $number);
}

// Returns array of random results from the input array but removes the exceptions
// from the input array prior to selection.
function RandomElementsFromArrayWithException($input, $exception = array(), $number = 1)
{
    return RandomElementsFromArray(array_diff($input, $exception), $number);
}


Comments Off on Refactoring Day