Creating Commands with xargs

February 23rd, 2008

I have a couple of folders with a ton of compressed files in them. I’m not talking about 10 or 20. No I’m talking about a couple thousand. Instead of spending all eternity uncompressing the files, I did some research into how one would go about having the command line do all the glorious work for him.

One of the requirements was that I didn’t want to decompress any Japanese files, which were indicated by ‘(J)’. However, if the file was American, European, and Japanese, then I did want the file decompressed. Another problem I had was that the indication of the type of file was clear. It could have either been UE, EU, JUE, UJE, or UEJ.

I wanted to keep the files separated, so I created another directory called dir2, which is the directory I’m in when I run the following command:

$ ls -1 /home/paulus/dir1 | grep -E ‘.*\((E|U|EU|UE|JUE|UJE|UEJ|JU|UJ)\).*\.zip’ | xargs -d’\n’ -L 1 -I ‘{}’ unzip ‘../dir1/{}’

The first command is a very well known command to anyone who has used a *nix distribution. This is listing the files in /home/paulus/dir1. The -1 is printing a list of files with one item on each line. The output is piped to the grep command.

The grep command gets a little messy with the regular expression. The . (period) is the beginning, the * (Asterisk) is saying “anything from the beginning to the first parentheses.” We have to use the back slash to escape it, otherwise it will be interpreted as a condition.

Notice how the second parentheses is not escape, that’s because we’re using it like we were if we were doing an if statement. From ‘\(’ to ‘\)’, we are using an if statement. So, return true if E or U or EU or UE or JUE or UJE or UEJ or UJ or JU are found. The ‘.*’ is saying anything after the ‘()’, then we have the extension, so we’re only looking at zip files.

Now that the regular expression is out of the way, we can move on to the xargs command. The xargs is used to build and execute command lines from input. Some programs don’t like to get data piped into it, such as the case of unzip. With the -d‘\n’ parameter, we are saying that each line is a separate argument and we are limiting one argument per command by the use of -L 1 parameter. -I ‘{}’ is saying that we are going to replace {} with an argument, such as one of the file names received from stdin. We finally get to the point where we can use the unzip command as if it were on the command line. xargs will execute ‘unzip ../dir1/{}’, but the actual command that gets sent is unzip ../dir/file.zip, where file.zip is one of the arguments that it was passed.

Ultimate Weapons for Castlevania: Curse of Darkness

February 13th, 2008

I wrote this little guide because I got annoyed when I learned that I didn’t steal material from a one time only boss or realized that I should got back a few stages to spend a half hour trying to get that one material that I needed. I wanted the most powerful weapons and strongest armor in the game. This is a very quick and dirty break down on how to get the weapons.

Read the rest of this entry »

Discovering your Past Lives

February 5th, 2008

This weekend I finished Discovering Your Past Lives by Gloria Chadwick. I was rather disappointed by the book overall. Perhaps it was because I was expecting more out of it, something more scientific. She did touch on what Alpha and Beta brain waves were and through out the book she kept telling the reader to get ‘into Alpha.’ That was the extent of the science.

According to the Author, she makes claim that behaviors, how we talk, books we read, dreams we have, interests, hobbies, talents, and weather we like are all indications of who we were in a past life. Even the jokes we make and how our home is like indicates who we were in a past life. One of the more known is the Birthmark theory. Typically a birthmark is an indication of tramma that you suffered in a past life. One of the most entertaining claims is that deja-vu is a definite sign that something around you was apart of your past life, whether it be a person, place, or thing. I read an article by Rick Nauert Ph.D. There is a mechnism in the brain that distinguishes similar yet distinct places. When we visit a place, neurons in the brain fire creating a blueprint. So next time we see the place, the same neurons fire. When we come into a new place, that is very similar to a place that we’ve already been, some of the same neurons fire as well as new neurons creating the sensation of deja-vu.

The next major subject of the book is Karma and why we are destined to be reincarnated. We are reincarnated to perfect our souls by learning lessons. If we let someone down in a past life, we must learn that lesson by living it in another life. Frankly, I believe that’s stupid. I don’t think I need to learn a lesson by having to live it. Personally the idea of us dying, poking around in the interuim deciding what lessons we want to learn in the next life is completely absurd.

“Karma is the universal law of cause and effect.” It IS cause and effect, it doesn’t take a rocket scientist or deep philosopher to come up with that. The cause and effect can be felt from the time an event takes place to whenever it runs out of steam.

Perhaps re-incarnation isn’t what Gloria thinks it is. Perhaps re-incarnation is something along the lines of us living, then dying, our decaying bodies being used as food for plants, and those plants are consumed by pregnant women who then use that food to sustain the babies still in the womb. Perhaps there is a collective conscience that we all share and that we are nothing more than devices that access that database and utilize it’s resources to how we feel we can benefit from the situations.

If you are looking to discover who you are, then I don’t recommend you read this book. The way that the author describes how to retrieve past life memories is weak and can easily be suggested. To me it’s more about having a buffet of information laid out in front of you and you get to create who you were in a past life. Until there is a method of learning of a past life, if one actually exists or not, we will never know who we were.

Recovering iTunes Music

January 31st, 2008

Occasionally I will get a customer in my store whose library has been corrupt or lost but their music is still on their iPod. The way that apple designed iTunes is that if the library gets messed up, you run a high risk of losing your music. Fortunately there is a way around that. What I do to save the customer’s music is take their iPod, connect it to my Linux computer. In order to see the files on the iPod, you’re going to need a few drivers either compiled as modules or into the kernel:

  • Device Drivers
    • USB Support
      • <*> Support for Host-side USB
      • [*] USB device filesystem
      • <*> EHCI HCD (USB 2.0) support
      • <*> OHCI HCD support
      • <*> UHCI HCD (most Intel and VIA) support
      • <*> USB Mass Storage support
      • [*] USB Mass Storage verbose debug
      • [*] Datafab Compact Flash Reader support (EXPERIMENTAL)
      • [*] Freecom USB/ATAPI Bridge support
      • [*] ISD-200 USB/ATA Bridge support
      • [*] Microtech/ZiO! CompactFlash/SmartMedia support
      • [*] USBAT/USBAT02-based storage support (EXPERIMENTAL)
      • [*] SanDisk SDDR-09 (and other SmartMedia) support (EXPERIMENTAL)
      • [*] SanDisk SDDR-55 SmartMedia support (EXPERIMENTAL)
      • [*] Lexar Jumpshot Compact Flash Reader (EXPERIMENTAL)
  • File systems
    • DOS/FAT/NT Filesystems
      • <*> MSDOS fs support
      • <*> VFAT (Windows-95) fs support
    • Miscellaneous filesystems
      • <*> Apple Macintosh file system support (EXPERIMENTAL)
      • <*> Apple Extended HFS file system support.

I compiled in all the things under USB support for various other things. If you don’t need them then you don’t have to compile them into the kernel.

Once you recompile the kernel or compile the modules and load them, you can connect the iPod to the computer and then mount it. When you try mounting it, it’s going to be a SCSI device. After you have mounted the iPod, Copy all the m4a files from the ipod_control folder, then re-import them into iTunes.

PHP User Authentication

January 31st, 2008

The Tables

First we’re going to need a table to hold the user information. I’ve done a very basic table, you can expand this table to include the user’s name, e-mail address, street address, etc.

CREATE TABLE TblUsers(
user_id VARCHAR(18) NOT NULL PRIMARY KEY,
user_password VARCHAR(255) NOT NULL,
question TEXT NOT NULL,
q_answer TEXT NOT NULL,
CONSTRAINT user_id_fk FOREIGN KEY(user_id)
REFERENCES TblPermissions(user_id));

For the sake that I can, in the event that you want to limit users to perform certain tasks you can create another table for permissions:

CREATE TABLE TblPermissions(
user_id VARCHAR(18) NOT NULL PRIMARY KEY,
perm_one INT NOT NULL DEFAULT 0 CHECK( perm_one < 1 && perm_one > 0 ),
perm_two INT NOT NULL DEFAULT 0 CHECK( perm_two < 1 && perm_two > 0 )
);

I kept this table simple. Obviously, if you wanted to you could definitely add more permissions depending on how big your application or site is. I will explain this in a later entry. We’re going to need a place for the user to log in. In order for the user to login and remain logged in, we’re going to have to start a session:

session_start();
Now we must undo what magic quotes does. If magic quotes is enabled, this will undo everything that it did.

if( get_magic_quotes_gpc()) {
$_REQUEST = array_map(’stripslashes’, $_REQUEST);
$_COOKIE = array_map(’stripslashes’, $_COOKIE);
}

We’re going to need at least three files for the user to login, do some work, then log out. Again, you can definitely have more pages depending on what you’re trying to acomplish.

The login page is a very basic page where the person is going to put in their credentials. Behind the scenes the page will submit the data to itself and verify that the user is a valid user. After it determines that the person trying to gain access is valid, it will foreword the user to the second page, which is called main.php in this example.

When storing passwords in a database, it’s important to encrypt them. NEVER store them in plain text!! The query that we’d use in this case to create a user would be:

INSERT INTO TblUsers(user_id, user_password, question, q_answer) VALUES(’test’, PASSWORD(’password’), ‘Where was I born?’, ‘New York City’);

Now, if you wrote a page to add users, the query would look like:

$query = “INSERT INTO TblUsers(user_id, user_password, question, q_answer) VALUES(’” . mysql_real_escape_string($_REQUEST[”UserID”] . “‘, ‘” . mysql_real_escape_string($_REQUEST[”UserPWD”] . “‘, ‘” . mysql_real_escape_string($_REQUEST[”UserQuestion”] . “‘, ‘” . mysql_real_escape_string($_REQUEST[”UserAnswer”] . “‘)”;

The mysql_real_escape_string function is to ensure that the user isn’t putting any evil data into the field that would result in data being exposed.

That’s it! If you want, you can download the files that were used in this entry:

Unit Testing PHP

December 29th, 2007

A while back I was working on a site, and as I was writing the back end and making sure that it works properly I thought to myself “If .NET has nunit, and Java has junit, does PHP have phpunit, or something similar?” After some digging I found the answer. The answer I found was yes! In addition to finding unit frame works for PHP I also found some for other languages like ada, haskell and so on:

aunit - for Ada
hunit - for Haskell
ant-junit - Apache Ant’s optional tasks depending on junit
dbunit - DBUnit is a JUnit extension targeted for database-driven pr
ojects.
tagunit - for testing custom JSP tags
xmlunit - for XML
and so on. If you want a complete list, on the command prompt, if you’re using Gentoo, just type:

# emerge –search unit | less

and have fun!

For PHP there are a few different ones:

dev-php4/phpunit
dev-php5/phpunit
dev-php/simpletest

At the time of writing this, dev-php4/phpunit is masked, but the version of phpunit for PHP 5 is not. I chose simpletest because I didn’t have to unmask any packages in order to install it.

# emerge simpletest

BAM! Done!

Read the rest of this entry »

Enabling Auto Login in Windows XP and Vista

December 22nd, 2007

Some people don’t like to enter a user name or password to use their computer. For others it’s pointless as they are the only one using the computer. To disable the Login Prompt follow the steps below.

  1. Start->Run

  2. Un-check the box that says “Users must enter a user name and password to use this computer”

That’s it. You no longer have to enter a user name or password to use the computer.

Server Upgrade

December 17th, 2007

About two months ago I received word from my Hosting provider that they will be performing upgrades to their server. After two months, they finally got around to me. I have scheduled the upgrade for December 31 at 00:00, so that’s 12:00 am, CST.

I can’t begin to tell you how happy this makes me. When I signed up for them over a year ago, I was only able to use PHP 4, and MySQL 4. On their Windows Server, they were still using .NET 1.1. This was rather frustrating as when I signed up they just said “PHP, MySQL, and ASP.NET” It wasn’t until later they changed it to reflect the actual version.

So by the time the new year starts, I will be able to use PHP 5 and MySQL 5. Hopefully, they will upgrade .NET 2.0.

I’m praying that there won’t be any kinks with my blog or anything else on my site. If there is, you know what I’m going to be doing for the first part of 2008!

Changing Images with Java Script

December 17th, 2007

While working on a site, I decided to add some Java Script to the menu bar so the site would be more interactive. I wanted the image to change so it gave the appearance as if the user is actually clicking on the button. Being a bit rusty on my Java Script I had to look up how one is supposed to reference an object on the page.

I came across a well written tutorial on how to change the images, but there was one minor problem. The script didn’t work. Perhaps it’s my web browser, or maybe I’m doing something wrong. When I look at the code itself it doesn’t make sense to me. What I kept finding over and over again was this:

document[image_name].src = …

The problem with the above statement, is that you’re trying to find the image by referencing the document array with the image name. That is an array of documents, not an array of images. I played around with this at first thinking that maybe Java Script is a bit funny. The error console in Firefox kept telling me that I was trying to set the property of an object that did not have that property. Further investigation revealed that I was correct in my thinking.

The correct way in setting the source of an image object is actually:

document.images[image_name].src = …

The best way to change the image when the cursor is over the image is to write a function that can be reused:

function(mouse_over(image_name, image_source)
{
document.images[image_name].src = image_source
}

After including the code in your page, you can use the function like so:

Psychic Hearing

November 26th, 2007

Unlike the other psychic senses, Psychic Hearing isn’t as easy as dismiss. Where that feeling you get could just be nervousness, that feeling of knowing could be Deja Vu, and what you see could be dismissed as nothing more than an over active imagination.

Psychic Hearing impressions are usually subtle. This ability is very much like talking to yourself. People who have this ability may not even know they have it. Often times they rationalize their premenotions being nothing more than an over active imagination. These people tend to ask:

  • Does psychic perception really exist?
  • Why haven’t I had the same kind and number of ESP experiences as other people?
  • Others have strong feelings, experience intuitive premonitions, and see visions. Why doesn’t that happen to me?

The receptive area for psychic hearing is located above the ears. Using this ability is like using your physical ears, but you are not focusing on your ears but the area above them.

  1. Sit comfortably; relax.
  2. Take a deep breath and exhale gently.
  3. Practice sensing the different parts of your head area.
  4. Shift your focus upward and sense the area above the ears. This area is about 1 - 2 inches above the ear.
  5. gnote how this area has a hieghtened sensitivity, like a microphone ready to amplify any sound or signal.
  6. Alternate the levels of focus several times, first aiming your awareness at ear level, then letting it slide up to the temporal-lobe area above the ears.

Practice by noticing the difference between outer and inner listening. Move to a location where you can hear people talking around you; sit down and relax:

  • Listen to some background converstation and notice how your attentino is not only at ear level, but how your sense of the sound is outside of you.
  • Shift focus now to the temporal-lobe area and talk to yourself, think to yourself. Notices how your attention is not only above the ear level, but above how your focus is inward.

Something that you can do is ask youself questions while you are doing the above exercise. When you ask yourself a question, don’t analyze it right away, just record it and come back to it later.

While working with psychic hearing you may recieve nothing more than a few words or sounds. These are called keywords. from there you have the skeleton for what you seek. You may also use psychic hearing to obtain your own mantra:

  1. sit quietly and relax.
  2. As you breathe omfortably and easily, turn your thoguhts inward and focus on yourself and your day.
  3. Project the mental question and at the same time let it echo in your mind.
  4. Grasp and note the word, phrase, or understanding that comes to your mind.
  5. Continue the process by reviewing the people and events of you upcoming day and getting psychic guidewords for dealing with them.

Advantages

  • At full volume, best for grabbing attention.
  • Best for getting key guidewords and inital direction
  • Best for understanding and analyzing a problem or situation.
  • Best psychic sense for thought projection.
  • Best for getting specific answers to questoins.

Disadvantages

  • At low volume, can be confused with thoughts.
  • One of the slower psychic senses.
  • One of the hardest psychic sense to develop.

Stengths

  • Can hear when someone is lying to them.
  • Are the best at getting keyword mantras
  • Are the best transmitters of psychic thoughts.
  • Are least likely to experience psychic overload.
  • Are direct, uncomplicated initiators.
  • Are excellent organizers of details
  • Are the best at receiving and understanding specific psychic information

Weaknesses

  • Can doubt their psychic potential and talk themselve out of ESP.
  • Can be overanalytical and ask too many questions.
  • Can come on too strong and radiate too much mental energy.
  • Can have trouble trusting feelings and intuition.
  • Can be least sensitive to psychic subtleties.

Personal notes taken from “You are Psychic” by Pete A. Sanders Jr.