Categories

Amateur Radio (4)
Blog (36)
Calc (10)
Cars (7)
Honda Accord Hybrid (4)
Jeep (11)
Miata (21)
Coding (6)
Gadgets (235)
Sprint Ambassador (23)
Game (16)
Jokes (10)
Link Cache (36)
Misc (139)
Personal (39)
Photography (8)
Politics (1)
Tech (254)
AWS (8)
Travel (52)
Honeymoon (16)
Work (7)
Flickr

Social Stuff
Site Info

Sponsored Links

Laurie's Entries

Category: Coding

March 14, 2007

Found a Fix for the MTEntryNext Tag

I Found It!  (Photo copyright 2006 Lauren Darcey) In the latest version of MovableType, 3.34, and a few of the earlier versions, the MTEntryNext tag was broken on dynamic archive templates.  The fix was relatively simple, too.

In the mt/php/lib directory, you'll find lots of PHP scripts for Smarty replacement tags.  The block.MTEntryNext.php file configures the arguments  to fetch_entries and assigns them to the $args variable as an array.  The value of lastn should not be set to 1.  That limits the entire set of entries to just the last 1, so the result is always the last one, which is always the most recent post. 

So, for the longest time, all of my individual entries have had a link to the main page, the previous article, and my most recent article.  Commenting this line out (with "//") has fixed this issue.  Hopefully Six Apart will have this resolved in the next version.

Since this was an issue in the Smart replacement tag, it only affect dynamic templates and not statically published templates.  And no, I didn't discover this on my own.  I don't have that much time on my hands. ;)  This forum posting at Six Apart's site helped out.

| | () | (0)

February 9, 2007

Does Perl Use OS Threads on Win32?

So, after reading through perlipc about how threads used to be only available for emulating fork on Windows, I became curious to know if Perl, specifically ActiveState's ActivePerl, had it's own thread manager or if it used OS based threads.

Even when reading about threads it sounded as if they may not be true OS level threads since they were called "interpreter threads."  That sounded like something where Perl might have it's own manager.  In fact, Perl might be required to have it's own manager on systems where OS level threads do not exist.

On a typical Linux system, doing a fork will usually show the process duplicated in the ps view.  On Windows, however, I noticed that there was still only one Perl process running.  So, I went about to find a tool to show the threads of a process.

A quick Google search (or is that just "google" these days?) turned up PrcView (or pv on the command line).  So, I brought up the CPAN module at the command line (e.g. "perl -MCPAN -e shell") and checked it out.  Sure enough, there was only one thread sitting in the process.

Then I brought up my little test app that does two forks.  It ended up with 4 threads total in the process, which was great to see.  Why?

Well, if an application doesn't use OS level threads then the OS just thinks of it as a single process.  The reason this matters is because then all of the processing will only ever be scheduled on to a single CPU.  This used to only matter for servers and higher end workstations where most people would be running applications designed for a multiprocessor environment.  However, in the days of multicore chips and even hyperthreaded chips, almost anyone can have a system with multiple execution cores.  Any application that does spread it's processing across multiple OS based threads will benefit from this.  I'm not just referring to the performance of the application, either.  The response time and smoothness will be improved. 

Of course, since threads will truly be running at the same time, proper synchronization is that much more important. Even the Perl documentation talks about lower level calls not being re-entrant. 

At a first glance of Apple iTunes, one would almost certainly peg it as not using OS based threads.  After all, if you're downloading, or doing certain other tasks, the UI becomes completely non-responsive.  You can alt-tab in and out of it, but you can't actually do anything with it.  However, using this tool on iTunes right now, shows that it's using at least 17 threads.  So, the real question then, is what the *bleep* are they doing to cause the responsiveness and performance to be so poor??

| | () | (0)

February 8, 2007

Making Your (Computer) Life Simpler: Automation

Simplicity Brings Peace to the Mind! One of the things I like to do on computers is automate various tasks.  Now, I'm not talking about things like disk cleanup, virus scanning, and other such mundane and boring tasks.  I'm talking about slightly smarter things. 

I often find myself create a lot of temp files.  That is, I'll briefly download a file to use in a post or something like that.  These files are rarely needed for more than just a few minutes.  If I have them go to the desktop, then my desktop ultimately gets cluttered with stuff I don't need and stuff that I do need.

So, on my work machine, I created a directed called "Deleted Daily" where I can put temp stuff in.  However, instead of deleting it myself every once in a while, I created a simple batch file:

rmdir /s /q "c:\Documents and Settings\Shane\Desktop\Deleted Daily\"
mkdir "c:\Documents and Settings\Shane\Desktop\Deleted Daily\"

The "/s" option is used to remove an entire tree.  The "/q" option keeps it from prompting.  Finally, the script recreates the directory. This batch file is then called every 4 hours throughout the day by using "Scheduled Tasks" within the control panel.  The only issue is if you are using the directory right when it's deleted.  This can be reduced by running it less frequently, but I like having it cleaned out so frequently I'll take care on what I put in there -- and what I don't.

I also have scripts that send me emails about various things.  I'm more likely to read an email than I am to notice a popup when I'm not at the machine.  This also allows it to run without interrupting my work.

Not all of these scripts have to run on a schedule, but causing them to do so helps simplify your life.  They then become things you don't have to think about.  Another way to have scripts run is to base them on triggers.  That is, if a script runs every time you do action X, it can run more efficiently while also being more likely to run in a reliable method.

An example of this sort of script could be one that monitors for BMP files in a particular directory and automatically creates a JPEG out of the file.  It's like running the script or action over the file, but with the added benefit that you can do it on files pasted or saved into there from another application.

All modern machines have various scripting options available to them for automating things from the mundane tasks to the advanced behaviors.  Learning to use them can make your life simple and speed up your work.

| | () | (0)

March 21, 2006

Perl: Iterating and Assigning Hash of Hashes and the Enigmatic Search

So, I was trying to do something simple.  I had a normal, everyday hash of hashes in perl.  That is, something where you have the likes:

$var{$key1}{$subkey1} = $value1;
$var{$key1}{$subkey2} = $value2;
$var{$key2}{$subkey1} = $value3;
$var{$key2}{$subkey2} = $value4;


Now, anyone can iterate over a normal hash:

foreach $key (keys %var)
{
    print "$key = $var{$key}";
}
But if these are hashes, this won't work.  You might think you just iterate over the next level of hash:

foreach $key (keys %var)

{

    print "$key = $var{$key}";
    foreach $subkey (keys $var{$key})
    {
       print "$subkey = $var{$key}{$subkey};
    }

}
#or this
foreach $key (keys %var)

{
    %subhash = $var{$key};

    print "$key = $var{$key}";

    foreach $subkey (keys %subhash)

    {

       print "$subkey = $subhash{$subkey};

    }

}



This won't even compile -- "$var{$key}" isn't a hash! (It's actually the text "HASH xxx", I think.) The key to this is simple, but finding the solution wasn't because it's not a topic on it's own.  All of you have to do is basically cast it:

foreach $key (keys %var)

{

    print "$key = $var{$key}";

    foreach $subkey (keys %{$var{$key}})

    {

       print "$subkey = $var{$key}{$subkey};

    }

}
#or this

foreach $key (keys %var)


{

    %subhash = %{$var{$key}};


    print "$key = $var{$key}";

    foreach $subkey (keys %subhash)

    {

       print "$subkey = $subhash{$subkey};

    }


}




I never did find a description of this, but I first saw it when googling at the site listed below.  I wouldn't consider this advanced, or even intermediate, really.  It was just particularly difficult to find.  And the results -- or even compile errors -- listed didn't help find a solution any faster.  So how would you search to find the answer to this?

! Aware to Perl: Access and Printing of a HASH OF HASHES

| | (5) | (0)

March 16, 2006

Turn Your Code Into a Text Adventure

Playsh is a tool that turns your collaborative coding environment into something resembling a text adventure game comparable to MUDs and Zork and other such things.

But instead of ducking grues and collecting zorkmids, you're interacting with whatever program code you're working on, as well as the data and hardware devices that it uses. "It treats the web and APIs as just more objects and places, and is a platform for writing and sharing your own code to manipulate those objects and places," says developer Matt Webb, who unveiled the tool at last week's O'Reilly Emerging Technology Conference in San Diego.
More information:

| | () | (0)

May 25, 2004

Martial Arts and Coding

We had a discussion a while back at work about Zen and the art of programming. Essentially, keep yourself out of the problem to see the problem in a new light; a light without the worry of you or perception of you as making mistakes, etc.

Well, this article is both similar and different. It's about Ri-Ai and development. The two can work together very well.

| | (1) | (0)