Powershell

I have recently begun using Windows PowerShell for some bash-like tasks under windows. Thus far I like it much more over the cmd. One minor note about this is by default the text is white with a blue background. Why is this a minor note? Well it scares me quite often!

I run virtuals on several different servers and this workstation. Some of them virtuals are windows-based. Making the PowerShell window (filled with text) look eerily familiar to a BSOD makes me jump every time I catch a glimpse of that window out of a corner of my eye. Subconsciously it has been engraved into my mind that blue screens with white text means windows has crashed. Now the exception is PowerShell.

Back to Ubuntu

Let it be known that I have come full circle on my development machine as far as operating system goes. I am now running Ubuntu 12.04 Desktop LTS, but with one minor difference, I am running a non-default kernel. I am running version 3.4-Precise Generic Kernel built with the direct kernel source, only using Ubuntus configuration during build. Here is the list of kernels available: http://kernel.ubuntu.com/~kernel-ppa/mainline/

(Note: I am once again fairly satisfied with my setup, there are a few bugs with Unity that I am unliking of. But not half as bad as my first dance with it. As expected, with time, the LTS is showing much strength.)

The reason for this is for better btrfs support, which is also the file system of choice for this setup. All 3 of my 640-GB SATA drives are in a RAID-1 configuration for both data and metadata. With the upcoming release of btrfs support for RAID-5 and RAID-6 I will be re-striping my HD to be at RAID-5 level I once was, but with the non-hardware btrfs file system.

The only major pain I had discovered while setting up Ubuntu was installing eclipse. This was not at fault of eclipse, but at Java for being removed from the repository. There are a handful of solutions to fix this problem, but the best/easiest for me was to download the Java *.deb files from the Debian repository through the website directly, and install them by hand. After this was completed, everything ran smoothly! I even now (once again) have an android development environment setup and working well.

I do hope to dive into btrfs user-tools in the future to allow time-travel like applications for directories, but this is nothing more than a pipe-dream as my current projects are far more prominent and feasible.

Hostmonster Provides SVN

Good news to those who use hostmonster and want to use SVN for a source code version control!

If you are looking for web hosting, I would strongly recommend hostmonster, one low price, all the features, no limits! (Take THAT GoDaddy!)

My email to Hostmonster:

It has come to my observation that both of the programs “svn” and “svnadmin” are installed and openly available to hosted users while using ssh access. This does not seem to be a highly publicized feature or benefit provided by hostmonster over other providers, which leads me to question the availability of such programs.

All of my websites are developed and hosted through hostmonster, I use svn to manage the website files durring development and deployment. So having a hosting provider also provide me with SVN tools truely cements my loyalty to that provider. The reason I ask about these tools is to verify that they were not installed by ‘mistake’ and that I can rely on them being persistently in place. I don’t want to start using the SVN tools you provide and then have them stripped away with a comment such as “they were not supposed to be there in the first place”.

Also, I am not sure if the use of an SVN repository would constitute as a form of backup and thus mark my account for termination.

I am a fan of hostmonster and have several clients go through me for hosting, and several others have started hostmonster due to my referrals. So I do want to stay on good terms with you guys!

Thanks much, Andy

Response from Hostmonster:

That service is made available to our customers, it is not a loophole or anything. You are able to use it for websites you have on the server. We do allow you to keep 1 backup of your websites on the server, and I believe this falls in that category. I don’t foresee us removing this feature but I can’t make any guarantee that it will always be available.

Thank you, Zachary

Terms of Service Compliance Department
1958 South 950 East
Provo, UT 84606
P: 866.573.4678 Option 5 | F: 801.765.1992

(Did you notice that it is Utah support? Based in the US? Another thing I like about Hostmonster. I can call them up, talk to them, understand them, and they don’t treat me like an idiot for the first half hour running me through a bunch of basic tests to which I have already tried before I contacted them in the first place.)

There ya have it folks… Can anyone say SCORE!! I was so excited when I found this out! Saves me money and gives me the ability to setup private SVN repositories!

And please, if you do decide to sign up, do it through this link here: Sign up for hostmonster.com

Yes, it is an affiliate plug. But it is not a reason for bias. I would not use (and then promote) a service that I disliked. It helps keeps the lights on around this place, doesn’t hurt you any, especially if you were going to sign up for a host(monster) account anyways!

SVN dump, rsync, and restore

This script will dump the repository, as a form of complete backup. This is one of the safest ways to ensure you have all of your revision history, and that it is restore-able . Using svnadmin’s ‘hotcopy’ is only really good for backing up that server at that instance. It is faster, but lets say you ditch that server/repo and want to, lets say, upload it to a hosted svn service. Well your hotcopy is gonna do you no good, whereas the dump is essentially an understood format snapshot.

Scipt:

svnadmin dump centerorbit.svn | gzip | split -d -b 20M – backups/centerorbit.svn/backup.

Great! Now you have a backup of your repo! Where is it? Oh its still on the same server/computer as the repo is. So in the case your computer gets lost/stolen/dropped of a cliff, your backup will do you no good.

No worries though! The reason we split it into 20 Meg chunks in the last script was so that we could easily use rsync to transfer our backup elsewhere! Just use this script:

 

rsync -e ssh user@domain.com:repository/backups/centerorbit.svn/* ./

In this script we tell rsync to go through ssh:
” -e ssh”

and to go to “user@domain.com”, but the ‘domain.com’ part could also be an IP address:
“user@domain.com:”

and once we are there (at the remote computer, this is the folder that we want to copy all of the files to the other computer:
“repository/backups/centerorbit.svn/*”

Note: The above command will start its folder reference from wherever your ssh session starts you. Usually this is your users home directory. If you want to start from the root of the filesystem, put a ‘/’ at the beginning of your folder location (right after the ‘:’).

Lastly, here is where we want rsync to place them on this computer:
./

Note: Which means “Put all the files in the exact same folder that the terminal is currently at”. You can see where this is by typing the command “pwd” which stands for “print working directory”. 

Now if we want to get the dump file extracted from the archive, in case we want to actually restore the dump:

cat backup.* | gunzip > dump.svn

and this command will produce a dump.svn file which can then be restored to an svn repo by using:

svnadmin load dump.svn

 

PHP generated image caching

So a recent challenge I had was storing binary data (a PNG image) in a MySQL database behind PHP, to which I would pull out upon request, format it and use it as a displayed image in the webpage.

My initial code looked very simple and easy.

header(“Cache-Control: private, max-age=10800, pre-check=10800”);
header(“Pragma: private”);
header(“Expires: ” . date(DATE_RFC822,strtotime(” 2 day”)));

header(‘Content-type: image/png’);
header(‘Content-MD5: ‘. base64_encode(pack(‘H*’, md5($row[‘Icon’]))));
header(‘Content-Length: ‘.filesize($row[‘Icon’]));
header(‘Content-Disposition: attachment; filename=”‘.$_GET[“ElementID”].’.png”‘);
echo $row[‘Icon’];

Now I wouldn’t suggest using this, as I found out Content-Length was way wrong, along with expires just set for 2 days. I needed to manually flush my browser cache to see any updates. Bad way to push out an image from MySQL through PHP.

The link below from rd2inc.com was the majority of my solution, but to that I had to change the way it got the additional header information. This was because apache_request_headers() wasn’t a function in my PHP. So in the link to php manual (below) I found and then had to slightly modify the code for the .htaccess file to this:

RewriteEngine on
RewriteRule (.*) – [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule (.*) – [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]

Now I can use:

$_SERVER[‘HTTP_IF_MODIFIED_SINCE’]
$_SERVER[‘HTTP_IF_NONE_MATCH’]

And how did I check for update change? Just set a hook in MySQL to update a timestamp  whenever that row is updated!

Links where I got info:

Sup?, Where ya been?

I haven’t posted much on here recently, it looks almost like I have given up coding altogether! Where actually it is quite the contrary! I have been very busy, almost too busy to be posting. Which is where a majority of the delay comes from. So there will be a quick flurry of posts to get some good nuggets out there before I call it a night tonight.

Just an FYI, I have taken a week off from my day-job to work on my programming projects during the what-would-be work hours. I have two projects (much related to one another) that are coming together very nicely. It is nothing I am willing to throw out into the public just yet, but in the next several posts you will get a glimpse at some of the code behind it!

Stay tuned!

AS3 Garbage Collection with Event Listeners

A quick word of warning to AS3 programmers. Don’t use anonymous functions with event listeners, because they WILL be garbage collected.

Took me forever to find this bug, it seemed that after 30 seconds or so all of a sudden my event listener would stop functioning. The event was never removed, still showed up in the debugger tools, everything. It wasn’t until after over 3 days of nailing my head against the keyboard that I finally figured it out.

Why use an anonymous function? Because that allowed me to pass variables seemlessly to my functions that I wanted to call. For example:

var aNumber:Number = 3;

aClip.addEventListener(
MouseEvent.ON_ClICK,
function(evt:Event):void {
callThisFunction(aNumber);
}
);

This is just a crude example snippit, but in this case if I have a MovieClip called “aClip” and I want it to call the function “callThisFunction” on the event of if it gets clicked, but I also want to pass it a parameter “aNumber”.

It was (in my eyes) a beautiful way to handle the situation, until the AS3 garbage collector stepped onto the stage (pun intended haha).

Hope this helps some desperate AS3 programmer that surfs Google like a starving vulture in a dessert looking for the smallest scrap of meat to appease their application from sporadic behavior.