Associative Array (Hash) Tricks in PHP

Suppose you're tallying some data. You want to know if a value has shown up in the data. You can do this by using the array, like this:

$tally = array();
while( $row = getData() )
    array_push($tally, $row);
if (in_array($tally, 'theValueIWant'))
    echo "yes";
else
    echo "no";

There's a faster way, by using the array key. (It should be faster.)

A Safer Way to Copy a Directory

This is a Perl version of the VB FileMirror class shown earlier on this site. The class helps you write scripts to (semi) safely mirror or move a file system from one directory to another. It does this by building the correct destination paths, making destination directories, and deleting files only after they appear to have been copied over.

Docs are in FileMirror.txt, attached.

DriveGMover.pl is a script that uses the class.

Classes to Create htdigest and htaccess Files

This is a first draft of some classes to manipulate .htaccess and htdigest files. I'm putting it up because there aren't many classes to do this, and seemingly none for htdigest files. (I just learned about the PEAR::Config classes. Neat.)

HTAuthFile is a superclass with a common writer. HTAccessFile is a very incomplete way to manipulate Apache .htaccess files.

htdigest Password Function in PHP

This is a function to change a password within an htdigest password database file. htdigest is one method of user authentication in Apache HTTP Server.

Global $htdigest contains a path to the htdigest file. Global $domain is the security domain.

The htdigest formula for the hash is: md5("$username:$securitydomain:$password")

htdigest is like htpasswd, except it uses the md5 hash for hiding the password, and it supports digest authentication.

Password Quality Evaluators Rendered Almost Useless

[This is obsolete. Short passwords are basically obsolete, and the main protection against hacking will be password managers like LastPass and 1Password. These kinds of "quality" widgets can provide a false sense of security.]


This is an up-and-coming feature on some sites. It measures the quality of a password, and gives the user immediate feedback about how good it is.

The JavaScript below does that. It calculates the score by grouping the keyboard into uppercase, lowercase, punctuation, and numbers.

Spy on Internet Users with: 1-Pixel GIF File, in Base64

This little bit of code returns a 1-pixel gif file. You can add it to the bottom of any script that you want to call from an IMG tag.


<?php
header('Content-type: image/gif');
echo base64_decode('R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
?>

Learn VisualBasic.NET with Me: (s)locate files on a disk with VBA

This is a class that will help you find files on the disk, without hitting the disk too much. It's a simplified unix "slocate" library. The first time you use it, it creates an index of all the files on the drive. (Subsequent uses update the file when a day passes.) The index is loaded into memory, and searched with regular expressions.

Oldie but a Goodie: Hierarchical Menu Rendering

I've been coding on experts exchange, testing myself. Here's some relevant code for one of the answers.

They're classes that have been used to generate hierarchical menus.

Learn VisualBasic.NET with Me: no new code

I thought there'd be a whole system to deal with the bad files, by now, but my attention shifted to understanding ESRI datasets. Spot checks on the copied data indicated that there were a fair number of datasets used, and they weren't copied over. The topic seems to be involved, and there's a lot to read.

Learn VisualBasic.NET with Me: running the code

This blog entry doesn't discuss any code, because I ended up doing very little work on the software. I was busy running it, and the app tends to take over the UI, making programing difficult. For the most part, it functioned as expected, but a couple things changed in how I actually used it.

I added a text box to restrict scanning for MXD files to a subdirectory. This new feature allowed me to set the source root and destination root directories, and then type the subdirectory to be processed. The text box could also be left blank.

I used this feature a lot.

Learn VisualBasic.NET with Me: crash woes, threading template

It was looking pretty grim for the file copier. The main problems were twofold:

First, the app sometimes crashed on bad data. The Windows crash-reporting dialog box came up, and all work stopped until it was dismissed.

Learn VisualBasic.NET with Me: rubber meets road

I'm finally running that program I've been writing. For the most part, it was "bug free" inasmuch as the different parts ran their test cases correctly, and it runs fine on a small subset of data. Of course, it's not like I ever really learned the system completely, so there are a lot of situations that I'm not handling (or even aware of). Moreover, because the users probably don't use all the features of the software, it's not likely that a complete solution is necessary. No project is debugged "enough" until it operates on real data, in a real situation.

Learn VisualBasic.NET with Me: recursion

It's going to be a lesson about recursion. It's strictly beginner level.

I don't have any code today, because I was working the polls yesterday, and spent most of today's worktime tuning that file copier. I hit a big problem because of some confusing, mis-coded loops. Here's the scenario in pseudocode (I don't want to fire up the Windows box just to get this code).

for each item in collectionA
    if type of item is Layer then
        processLayer item
    else if type of item is LayerGroup then
        for each subItem in item

Learn VisualBasic.NET with Me: is a time within a time span?

This article discusses debugging a function by rewriting the code.

I'm not sure what I did wrong here, but, my first version of this function didn't work. The function returns true if the current time is withing two time spans. This code was written in a rush, without really thinking about how to do it, because it seemed pretty straightforward. The code, however, was a mess (and embarassing).

    Private Function itIsTimeToWork() As Boolean
        ' Get the two start and end times, and determine if we're within 
        ' the intervals.

Learn VisualBasic.NET with Me: spinning my wheels, animating an image with the timer

For some reason or other, I didn't get an email response from the client on this gig*, and the week was hectic, so instead, I just worked on making the UI a little nicer. VB has a lot of controls, including a background threader, some standard dialogs, and a serial port. This is giving me a real "Rip Van Winkle" feeling, having been over in Unixville for a while.

(* It was lost in my huge email pile. My bad. No matters... the program got a nice facelift.)

Syndicate content