Programming


Links and Programming February 28th, 2007 by Digg

Both refer to their clients as 'users', offer the first one for 'free' and have 'Asian' connections. Hmmm... is there some cross-over here?

I found this by using StumbleUpon and thought I might Digg it as well. There are some similar entries on Digg but this one is a little bit longer.

If you like it Digg it or leave a comment. If not you can always bury it.

As a software developer I get a kick out of this, mostly because it's all true!

read more | digg story

Internet and Programming February 21st, 2007 by HMTKSteve

I recently moved my blog from Serendipty to WordPress. During this long process I ran into a brick wall.

I had been intending to reuse all of my old URLs and place the new blog in the exact same place as the old blog but I encountered a problem.

The Serendipity blog allowed me to use some special characters in the url, this is something WordPress will not do. This was not a major issue as there are ways to have Apache rewrite URLs for you.

The big problem had to do with the fact Serendipity creates a URL with "index.php?/" in it. WordPress does not like the "?" in a URL.

I looked and looked all over the web but everywhere I went told me to put the URLs into a .htaccess file and reroute them that way. I tried that and... because of the "?" all links were being redirected without the argument that followed the "?".

So, if someone followed index.php?/cool-article or index.php?/not-so-cool-article they would all be dumped at the main page for my new blog! The redirect was redirecting the index.php request and ignoring everything else.

Being the resourceful programmer that I am I did some digging and found some PHP code that I could use that would grab the argument, remove any forbidden characters and redirect the reader to the right post.

Here it is, use it if you need it. Just to be sure to change the hmtk.com reference!

<?php
$page = basename($_SERVER['QUERY_STRING']);

$page = str_replace(',', '', $page);
$page = str_replace('+', '', $page);
$page = str_replace('!', '', $page);

       $new_url = "http://www.hmtk.com/archives/" . $page;
       header("Location: $new_url");

?>

Programming February 9th, 2007 by Stephen

This story was told to me by a friend I met while serving in the US Army. His name is Stephen Shields and I have no idea where he is now but if he reads this he should contact me.

To give some background on the story I will tell you the following. Steve worked in an IT shop during the mid 1980's. In this shop he maintained some networks (Unix environment) and, among his colleagues, he was much smart.

I can't recall if he was working on a university or at IBM, it was over 15 years ago when he told me this story...

At the IT shop where I worked there were a few good techs and one smart one, me. Back in the mid 80's I was just one worker, among many, who kept the campus mainframe operational.

We ran Unix, like everyone else did, and though my associates at work could handle most of the day-to-day operations of maintaining a mainframe they were not the brightest folks in regards to programming or how Unix worked.

There were a few joke items scattered about the office such as the proverbial "bit bucket" or "metric" rather than standard crescent wrench but, for the most part, it was a fairly serious shop.

One day a few of my associates approached me to ask me a question. It seems they had found the directory and files where all of the passwords were stored along with the usernames. Please understand, this is back in the day when hashing passwords and network security was almost non-existent.

The only network links off campus were in the 300 baud range. It was easier (and faster) to just dump a tape and fly somewhere than attempt to use a link.

Since only admins had root access and all the techs were admins I knew it was only a matter of time until this question surfaced.

"Hey Steve, we were looking at the password file and we noticed something strange."
"Yeah, what?"
"Well, everyone on campus has a password but you."
"I have a password, you just can't see it because I'm a super user."
"What? How come you get to be a super user?"

It was all I could do to keep from cracking up at this point. I wasn't a super user, I had the same access rights as they people did, but I had a secret...

"Well, if you guys were smart and knew enough about computers maybe you could be super users too!"

They left in a bit of a huff, mumbling to each other how unfair it was that I had special perks that they did not.

The next day my boss pulled me aside, he wanted to know what all the trouble was about and why the other techs were acting uppity. Once again, I had to keep a straight face. I walked with him back to his office, made sure no one was around, closed the door and talked to him.

I brought up the password file and showed him what all the fuss was about. When he saw that I was the only one without a password he grinned. He knew what was going on.

"You bastard!"
"Yup, that's me."
"You got them all worked up over this?"
"Yep."
"Get out of here before I smack you around for being a wise-ass!"

See, the thing that my co-workers never caught on to but my boss saw right away was that the file was ASCII with no encryption or anything. If those passwords had been hashed or displayed in HEX or anything other than ASCII than my coworkers would have never been mislead. What I did was exploit the weakness in the system to make everyone think my password was so secure that no one could see it.

How did I do it? Simple, my password was eight characters long. Eight taps of the spacebar to be precise!

Programming December 17th, 2006 by Stephen

A common tool many programmers use is the array.

The array is very useful in storing like data. Arrays can also be sorted and searched.

What many programmers do not do is use an array along more than two axis.

The simplest form of an array is one with only one axis. It is nothing more than a long row of data.

int array[50];

Let's imagine now that we work in a large warehouse and our boss has tasked us with writing a simple program to inventory all of the items in the warehouse and where they are in the building.

In it's most basic sense, a one axis array is equivalent to a long line of boxes on the floor. This might work in a small warehouse but our building is quite large. We will look next at the two axis array, which is also the most common.

int array[50][50];

Now we have a two axis array. We can consider the first axis to be the row and the second axis to be the column.

We have gotten rid of the long snaking line along the floor and replaced it with a system of rows and columns to find where everything is but, everything is still on the floor!

The boss says he wants some shelving units in each row of the warehouse, but how do we account for this?

int array[50][50][10];

We have just moved on to the three axis array. Since we are already using the first two axis for row and column we will now use the third axis for shelf.

I'm only using ten shelves in the warehouse so I capped out that axis of the array at ten.

Now, if the boss wants to know where the rope is we can tell him it's in row 11, column 21 and shelf 3.

What's that? How do we store "rope" in an integer array? Well, we use product numbers to represent what an item is. The array does not store "rope" at array[11][21][3] but instead it holds the product ID code 7259 which means "rope."

"Well, that's all well and good," says the boss, "but, sometimes we sell out of something and put something new in the warehouse. I don't want to lose the fact that the shelf once held rope on it, how can we track that?"

Now we use a four dimensional array.

int array[50][50][10][50];

We now have an array that tracks: row, column, shelf and time. Our fourth dimension is one of time, it can be used to tell us what was once on that shelf.

Now, when the boss says, "Where's the rope," we can respond, "row 11, column 21 and shelf 3 (time=0)!"

If he then asks us what used to be there we can go back through the time element of the array and know what was once there.

You might be wondering why it is important to track what was once on a shelf? If you have ever worked in a warehouse you probably know that sometimes things get lost or someone misplaces something. If a report comes down that says we have one rope left, and we know where the rope used to be, there is a good chance we can go to where the rope used to be and find one near by.

If it helps think of arrays in the following way:

One element = straight line
Two elements = rectangle
Three elements = box
Four elements = a series of boxes in a straight line

You can go beyond four elements when creating arrays but you will likely not need to. In fact, if you were tracking the contents of a warehouse you would probably have a large array of pointers that point at objects which contain the information about the item in the warehouse.

You will likely never have a need to use anything bigger than a two dimensional array but I hope that this short exercise has enabled you to properly wrap your mind an array with more than two axis.

Programming November 21st, 2006 by HMTKSteve

No, I'm not being held hostage by Russian web hackers!

For the past few years I've been "selling" some character generation software for the HackMaster RPG from Kenzer & Company.

I've recently become more involved in other things, one of which is building an addition to my home.

Because of this, I no longer have the time to work on HMTK.

I would like to release the source code in an open source format so that others may continue where I left off. At the same time I do have some bills to pay so I can't just open source right away.

This is why I'm going with the ransom system.

Here is how it will work. Once this blog makes $4K USD from advertising, donations and affiliate sales I will release the full source code for HMTK/wxHMTK on the main site as a download.

As people make changes to the code and send them back to me I will incorporate them into the project and make them available for download.

It's been a wild ride getting to this point but I can't devote the time and energy to the project any longer.

This may not be the best solution, but it is the best one I can think of.

I will provide monthly updates starting in December.

Thank You.

Programming October 28th, 2006 by HMTKSteve

One of the most useful ways to store data is the linked list.

Read on and explore a very basic framework that you can use to easily add them to your program.

We begin with the h file. Please note, this code is written with wxwidgets in mind but the only change required to use this code elsewhere will be the changing of the variable “wxString” to something else.

Because this is only a sample code snippet for training purposes, the two variables “Name and Value” will not carry over to your own program.

/////////////////////////////////////////////////////////////////////////////
// Name:        hmtkdataitem.h
// Purpose:     hmtk data item function
// Author:      Stephen De Chellis
// Modified by:

// Created:     04/09/05
// Copyright:   (c) Stephen De Chellis
// License:     Creative Commons Attribution-ShareAlike 2.5 License
/////////////////////////////////////////////////////////////////////////////

#ifndef __HMTKDATAITEM_H__
#define __HMTKDATAITEM_H__

class HMTKDataItem
{
    public:
        static HMTKDataItem* pHead;

               HMTKDataItem* pNext;
               wxString      Name;
               int           Value;

        HMTKDataItem();
        ~HMTKDataItem();

        void          AddHead(HMTKDataItem* DI);

        void          AddTail(HMTKDataItem* DI);
        int           Remove (HMTKDataItem* DI);

        void          Clear  (void);
        HMTKDataItem* Find   (wxString Search);

};

#endif

Now let us look at the cpp file

/////////////////////////////////////////////////////////////////////////////
// Name:        hmtkdataitem.cpp
// Purpose:     hmtk data item function
// Author:      Stephen De Chellis
// Modified by:
// Created:     04/09/05
// Copyright:   (c) Stephen De Chellis

// License:     Creative Commons Attribution-ShareAlike 2.5 License
/////////////////////////////////////////////////////////////////////////////

#include “precomp.h”
#include <fstream>
#include <iostream>
#include <stdio.h>

#include <stdlib.h>
#include <string.h>
#include “hmtkdataitem.h”

HMTKDataItem* HMTKDataItem::pHead = 0;

using namespace std;

HMTKDataItem::HMTKDataItem()
{
    Name.Clear();

    Value=0;
    pNext=0;
}
HMTKDataItem::~HMTKDataItem()

{
}

void HMTKDataItem::AddHead(HMTKDataItem* DI)

{
    DI->pNext = pHead;
    pHead = DI;

}

void HMTKDataItem::AddTail(HMTKDataItem* DI)
{

    cout << “Adding Tail” << endl;
    DI->pNext = (HMTKDataItem*)0;

    if (pHead == 0)
    {
        pHead = DI;

        return;
    }
    HMTKDataItem* pCurrent = pHead;

    cout << “Entering while loop” << endl;
    while(pCurrent->pNext)

    {
        pCurrent = pCurrent->pNext;
    }
    cout << “Leaving while loop” << endl;

    pCurrent->pNext = DI;

    cout << “Leaving Adding Tail” << endl;

    return;
}
int HMTKDataItem::Remove(HMTKDataItem* DI)

{
    HMTKDataItem* pCurrent = pHead;
    if(pCurrent == (HMTKDataItem*)0)

    {
        return 0;
    }
    if(DI == pHead && DI->pNext!=0)

    {
        pHead = DI->pNext;
        delete DI;

        return 0;
    }
    if(DI == pHead && DI->pNext==0)

    {
        pHead = 0;
        return 0;
    }

    while(pCurrent)
    {
        if(DI == pCurrent->pNext)

        {
            pCurrent->pNext = DI->pNext;
            DI->pNext = (HMTKDataItem*)0;

            delete DI;
            return 1;
        }
        pCurrent = pCurrent->pNext;

    }
    return 0;
}
void HMTKDataItem::Clear(void)

{
    HMTKDataItem* pPrevious;
    if (pHead == 0)

    {
        return;
    }
    HMTKDataItem* pCurrent = pHead;

    while(pCurrent->pNext)
    {
        pPrevious = pCurrent;

        pCurrent = pCurrent->pNext;
        delete pPrevious;
    }

    pHead=0;
    return;
}
HMTKDataItem* HMTKDataItem::Find(wxString Search)

{
    if (pHead == 0)
    {
        return 0;

    }
    HMTKDataItem* pCurrent = pHead;
    while(pCurrent->pNext)

    {
        if(pCurrent->Name.Contains(Search)==1)

        {
            return pCurrent;
        }
        pCurrent = pCurrent->pNext;

    }
    return 0;
}

Yep, that’s a lot of code!

Once again, please note that the variable “Name” is used in the Find function so if you change it, you also need to change the Find function

In the following example we will add an item to the linked list

HMTKDataItem* DI = new HMTKDataItem;  // create a pointer to a new item
DI->Name = Selection;                 // Give Name a value

DI->Value = 1;                        // give Value a new value
HMTKDataItem.AddTail(DI);             // Add the new item to the tail

delete DI;                            // delete the pointer

Now, before adding an item it might not be a bad idea to search the linked list to see if it already exists.

HMTKDataItem* DI = new HMTKDataItem;   // Create a pointer

DI = HMTKDataItem.Find(Selection);     // Search the existing linked list
if(DI == 0)

// Now you know it does not exist

To remove an item you would use:

HMTKDataItem* DI = new HMTKDataItem;  // create a pointer

DI = HMTKDataItem.Find(Selection);    // use find
if(DI != 0)                           // as long as DI gets something to point at

{
    HMTKDataItem.Remove(DI);          // we now delete the item in the linked list
}

That is about it. I’ve given you a very brief overview on how to use a linked list in your program. If you have any questions please leave a comment.

Programming October 28th, 2006 by Stephen

One of the most useful ways to store data is the linked list.

Read on and explore a very basic framework that you can use to easily add them to your program.

We begin with the h file. Please note, this code is written with wxwidgets in mind but the only change required to use this code elsewhere will be the changing of the variable "wxString" to something else.

Because this is only a sample code snippet for training purposes, the two variables "Name and Value" will not carry over to your own program.

/////////////////////////////////////////////////////////////////////////////
// Name:        hmtkdataitem.h
// Purpose:     hmtk data item function
// Author:      Stephen De Chellis
// Modified by:
// Created:     04/09/05
// Copyright:   (c) Stephen De Chellis
// License:     Creative Commons Attribution-ShareAlike 2.5 License
/////////////////////////////////////////////////////////////////////////////

#ifndef __HMTKDATAITEM_H__
#define __HMTKDATAITEM_H__

class HMTKDataItem
{
    public:
        static HMTKDataItem* pHead;
               HMTKDataItem* pNext;
               wxString      Name;
               int           Value;

        HMTKDataItem();
        ~HMTKDataItem();

        void          AddHead(HMTKDataItem* DI);
        void          AddTail(HMTKDataItem* DI);
        int           Remove (HMTKDataItem* DI);
        void          Clear  (void);
        HMTKDataItem* Find   (wxString Search);

};

#endif

Now let us look at the cpp file

/////////////////////////////////////////////////////////////////////////////
// Name:        hmtkdataitem.cpp
// Purpose:     hmtk data item function
// Author:      Stephen De Chellis
// Modified by:
// Created:     04/09/05
// Copyright:   (c) Stephen De Chellis
// License:     Creative Commons Attribution-ShareAlike 2.5 License
/////////////////////////////////////////////////////////////////////////////

#include "precomp.h"
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hmtkdataitem.h"

HMTKDataItem* HMTKDataItem::pHead = 0;
using namespace std;

HMTKDataItem::HMTKDataItem()
{
    Name.Clear();
    Value=0;
    pNext=0;
}
HMTKDataItem::~HMTKDataItem()
{
}

void HMTKDataItem::AddHead(HMTKDataItem* DI)
{
    DI->pNext = pHead;
    pHead = DI;
}

void HMTKDataItem::AddTail(HMTKDataItem* DI)
{
    cout << "Adding Tail" << endl;
    DI->pNext = (HMTKDataItem*)0;
    if (pHead == 0)
    {
        pHead = DI;
        return;
    }
    HMTKDataItem* pCurrent = pHead;
    cout << "Entering while loop" << endl;
    while(pCurrent->pNext)
    {
        pCurrent = pCurrent->pNext;
    }
    cout << "Leaving while loop" << endl;
    pCurrent->pNext = DI;

    cout << "Leaving Adding Tail" << endl;
    return;
}
int HMTKDataItem::Remove(HMTKDataItem* DI)
{
    HMTKDataItem* pCurrent = pHead;
    if(pCurrent == (HMTKDataItem*)0)
    {
        return 0;
    }
    if(DI == pHead && DI->pNext!=0)
    {
        pHead = DI->pNext;
        delete DI;
        return 0;
    }
    if(DI == pHead && DI->pNext==0)
    {
        pHead = 0;
        return 0;
    }
    while(pCurrent)
    {
        if(DI == pCurrent->pNext)
        {
            pCurrent->pNext = DI->pNext;
            DI->pNext = (HMTKDataItem*)0;
            delete DI;
            return 1;
        }
        pCurrent = pCurrent->pNext;
    }
    return 0;
}
void HMTKDataItem::Clear(void)
{
    HMTKDataItem* pPrevious;
    if (pHead == 0)
    {
        return;
    }
    HMTKDataItem* pCurrent = pHead;
    while(pCurrent->pNext)
    {
        pPrevious = pCurrent;
        pCurrent = pCurrent->pNext;
        delete pPrevious;
    }
    pHead=0;
    return;
}
HMTKDataItem* HMTKDataItem::Find(wxString Search)
{
    if (pHead == 0)
    {
        return 0;
    }
    HMTKDataItem* pCurrent = pHead;
    while(pCurrent->pNext)
    {
        if(pCurrent->Name.Contains(Search)==1)
        {
            return pCurrent;
        }
        pCurrent = pCurrent->pNext;
    }
    return 0;
}

Yep, that's a lot of code!

Once again, please note that the variable "Name" is used in the Find function so if you change it, you also need to change the Find function

In the following example we will add an item to the linked list

HMTKDataItem* DI = new HMTKDataItem;  // create a pointer to a new item
DI->Name = Selection;                 // Give Name a value
DI->Value = 1;                        // give Value a new value
HMTKDataItem.AddTail(DI);             // Add the new item to the tail
delete DI;                            // delete the pointer

Now, before adding an item it might not be a bad idea to search the linked list to see if it already exists.

HMTKDataItem* DI = new HMTKDataItem;   // Create a pointer
DI = HMTKDataItem.Find(Selection);     // Search the existing linked list
if(DI == 0)
// Now you know it does not exist

To remove an item you would use:

HMTKDataItem* DI = new HMTKDataItem;  // create a pointer
DI = HMTKDataItem.Find(Selection);    // use find
if(DI != 0)                           // as long as DI gets something to point at
{
    HMTKDataItem.Remove(DI);          // we now delete the item in the linked list
}

That is about it. I've given you a very brief overview on how to use a linked list in your program. If you have any questions please leave a comment.

Programming and Technology October 22nd, 2006 by HMTKSteve

Ever have a program in X go wrong and blank your screen? This handy Linux tip should help.

The other night I was trying to get some fan-sub anime to play on my Linux box but it was encoded in xvid and I did not feel like taking the time to check which player was setup to play xvid avi files.

Instead I used trial and error to play the file through each of the media player programs I had installed.

Then, while running VLC I tried to go full screen and everything went wrong.

My screen went blank but the audio was fine. Nothing I could think of was working to get me a menu.

I took a deep breadth and thought about it.

In Windows you would hit Ctrl-Alt-Del to bring up the proccess manager screen and try to kill a run-away application that way, but what about Linux?

So I hit Alt-F2 to bring up a new terminal and logged in as myself. I then ran "top" to see what was running on my system. There it was, "xvlc," the guilty party!

With top running you need only hit "k" and enter in the proccess ID to kill it.

I killed it and hit "Alt-F7" to return to my x-windows.

There you have it.

If you get stuck with a run-away proccess you need only open up a terminal and run "top," then use "k" to kill it!

I hope this helps!

« Previous PageNext Page »


ss_blog_claim=50369052f04070d4855a2cf2adc3eab6 ss_blog_claim=50369052f04070d4855a2cf2adc3eab6
Top Blog Lists      Computer and Video Game Blogs -  Blog Catalog Blog Directory

98 queries. 0.315 seconds.