May 2009 Archives

If you're ever in a situation where you need to generate a cryptographically strong random number, then you might be interested in learning a little more about Java's java.security.SecureRandom. So, what's the difference between java.util.Random and java.security.SecureRandom?  Well, SecureRandom is special because it aims to make it more difficult to programatically predict the next random number in a sequence.  And, not surprisingly, guessing or predicting random numbers in an insecure random sequence is trivial.  So, any crypto-based code that requires a random number for digital signature generation, session key generation, etc., should always use SecureRandom.
alternating-rows-after.pngIn any web-application, there are always a few trivial and seemingly mundane enhancements the developer can implement that add significant value for the end-user.  And with the right tools in hand, implementing these enhancements can be down right simple.  Take alternating gray rows in a table for instance, or a slick mouseover highlighting effect when the user moves their mouse cursor over each row in a table.  Not surprisingly, you can easily implement these quick enhancements using jQuery.

A complete example can be found here, or continue reading for some screen shots.

twitter-logo.pngI recently stumbled across this awesome post via Twitter that explains how to Tweet from the command line like a pro using curl.  I tried it, and sure enough, it works!  If you want to Tweet a message from the command line using curl, here's how:

#/> curl -u mytwitterusername:mypassword \
-d status="from the cmd line!" \
http://twitter.com/statuses/update.json

Even cooler, if you want to pipe output into a Tweet (like your system uptime from the "uptime" command), you can run the following:

#/> curl -u mytwitterusername:mypassword \
-d status="my uptime:`uptime`" \
http://twitter.com/statuses/update.json

Note that if you are behind a corporate firewall at work, you will need to tell curl to use an HTTP web-proxy to communicate with the outside world.  This can be done using the -x option like so:

#/> curl -u mytwitterusername:mypassword \
-d status="from the cmd line!" \
-x web-proxy.example.com:8088 \
http://twitter.com/statuses/update.json

Or, if you wanted to pipe the output of a command into a Tweet, you can do so using the -d @- arguments which asks curl to read the POST input from <STDIN>.  Here's an example of piping the output of "df -h /" into a Tweet (to Tweet the usage of my root disk):

#/> echo "status=`df -h /`" | \
curl -u mytwitterusername:mypassword \
-d @- \
-x web-proxy.example.com:8088 \
http://twitter.com/statuses/update.json

For the HP-UX Tweeps out there (@HP_UX) ...

If you happen to be using a system without curl, you can easily install it.  On HP-UX, curl can be installed using the HP-UX 11i Internet Express package available from hp.com (HP-UX 11i v2 or HP-UX 11i v3).  As root on your HP-UX box, use the swinstall command to install your freshly downloaded .depot ...

swinstall -s /path/to/depot/internet_A.12.00.013_HP-UX_B.11.23_IA_PA.depot

Enjoy!
Thumbnail image for datacenter.jpgSeveral days ago I spent more than 5 hours setting up a fresh install of Windows Vista Enterprise on a desktop computer in my home office.  This setup process involved tweaking the system configuration, installing and configuring all of my required software for development, checking out a massive SVN code repository, etc.  Sadly, less than a week after I finished setting up this box, the SATA hard disk died.  As it turns out, the disk flat out overheated due to poor airflow around the disk chassis in my PC (that's a story/post/opinion piece for another day).  In short, I lost everything on the drive.  All of the blood, sweat and tears; for nothing.

I decided to never let this happen again (since it's a huge time suck sitting around waiting for software to install) and began investigating free, yet solid and reliable backup solutions suitable for a home office.  This post is an attempt to document what whole disk backup and recovery solution worked for me, using several freely available open-source tools.

NOTE: This backup and restore procedure has worked for me twice as of 6/11/09.  See the FOLLOWUP in red at the bottom of this post for details.
Here's a quick tip that might be useful to some Java nuts out there.  Often in Java, it can be helpful to save a stack trace as a String.  This is useful when an application (a web-app or standalone client application) needs to "report back" to a central server that an error occurred.  When the client app pings the server to alert it of an Exception case, it's very helpful to also include the stack trace in the ping.  If you ever find yourself needing to do this, here's how:

/**
* Given a Throwable, gets the full stack trace for the
* Exception or Error as a String. Returns an empty string
* if something went wrong (so the caller won't fail with a
* null pointer exception later).
* @param t
* @return
* @author kolichko Mark Kolich
*/
public static String getStackTraceAsString ( Throwable t ) {

final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw, true);
String trace = new String();

try {
t.printStackTrace( pw );
pw.flush();
sw.flush();
trace = sw.toString();
}
catch ( Exception e ) { }
finally {
try {
sw.close();
pw.close();
}
catch ( Exception e ) { }
}

return trace;

}

Enjoy.
anti-virus-small.pngAt home on my Vista machine, I run Symantec AntiVirus 10.2.0.276.  This version of Symantec AntiVirus, provided by my employer, forces me to run a full system scan every Thursday at 12-Noon.  This is very irritating for a number of reasons, but mostly because my computer is usually in use and I don't have the CPU cycles and system resources to spare in the middle of my workday.  This machine is a dedicated desktop at home that I share between work and my personal ventures, so it's a client that does not connect directly to my employer's network (via a VPN or otherwise).  As a result, the forced Thursday anti-virus scan is totally unnecessary.

Disclaimer: I'm an advanced power user so I know what I'm doing and I trust myself to do the right thing so that I don't contract and spread a computer virus.  If you know what you're doing, and you trust yourself and other PC's on your network to stay virus free, continue reading to find out how you can disable/unlock scheduled administrator scans in Symantec AntiVirus.  BTW, disabling a forced administrator scan on a PC provided to you by your employer is probably a violation of their IT-security policy and could get you into trouble.

insert-coin-printer.pngIt may be more than a month past April Fools' Day, but there's never a bad time for a little humor and laughter around the office.  After reading this post at kovaya.com, I decided to see if this innocent little trick with HP LaserJets actually works.  Sure enough, it does!  Using this Perl script, you can make the LCD screen on your HP LaserJet say whatever you want.  And to top it all off, I successfully ported the app to PHP and put a nice little front end on it for your added convenience (err, enjoyment).  Continue reading for the PHP code ...

dot-tel-nic-logo.pngFor my latest Web 2.0 experiment, I decided to shell out a few bucks and purchase kolich.tel via my registrar, Network Solutions.  The fundamental idea behind a .tel domain is quite interesting.  In a nutshell, a .tel (dot-tell) is designed to act as an advanced virtual white or yellow page listing for the owner (an individual, business, or organization).  In other words, it's a fancy online business card.  When you purchase a .tel domain, Telnic will setup and host a site for you that contains your contact information.  This might include your name, web-site address, email address, phone number, and even your physical mailing address.  Of course, you choose which pieces of information to share with the world; you can opt to only share your name, or go for the gold and share everything about yourself.

Continue reading for the details ...
I recently dove head first into ImageMagick with PHP.  Ignoring the fact that ImageMagick's PHP documentation is lagging, and there are only a few solid real-world ImageMagick PHP examples out there, it's really not that bad!  This post is an attempt to officially document what I did to get ImageMagick working with PHP on CentOS 5.3.  I also wanted to share a real-world PHP-ImageMagick example from an actual project I built for a client.

Twitter (@markkolich)

Translate

About this Archive

This page is an archive of entries from May 2009 listed from newest to oldest.

April 2009 is the previous archive.

June 2009 is the next archive.

Find recent content on the main index or look in the archives to find all content.