Tech Tips

Various Tips and techniques discovered along the way that will hopefully be useful for other developers.

VMware Ubuntu Guest Add Harddrive without Rebooting

August 27th, 2010 No comments

Four steps to add a new hard-disk to a running Ubuntu virtualized session, using Vmware.

  1. Add the new hard-disk to the Ubuntu vmware image using Vsphere or VMWare Server.
  2. Ssh into ubuntu session and run
    “echo “- – -” > /sys/class/scsi_host/NUMBER/scan”
    NUMBER is the scsi host value.  It will not hurt rescanning a running host, so I simply keep incrementing till I reach a scsi host value that is not created in the system yet.
  3. Do an “fdisk -l” and voila your new disk should be available.
  4. Do what you want with it!  (Software Raid or create a new partition etc).


Ubuntu Vmware Server Guest Slow Network Speeds

August 12th, 2010 No comments

I recently setup a test VMWare server environment on my Windows 7 workstation to run Ubuntu LAMP development environments that mirror my production environments. After I install an Ubuntu (or any Nix) environment, I typically install Samba services so I can easily copy code/images back and forth from my workstation to the development box.

I noticed on my vanilla install of Ubuntu 10.04.1LTS, that I was getting horribly network transfer speeds just copying a 13.9 MB file from my workstation to my virtual machine. It was taking between 4-6 minutes for just a 13 MB file, which is utterly ridiculous!

My VMware Server said that my guest OS had the VMware Tools installed properly, so I assumed that everything was running fine. I ran tests on the cards, tweaked Win7 settings, but nothing seemed to work. I finally figured it out by chance.

While I was SSH’ed into the box I tried restart the Vmware guest tools (/etc/init.d/vmware-tools restart).
It restarted properly, but I received a message that my “Vmware tools” were not compiled properly for my kernel (2.6.32-24-server).
I simply ran:
/usr/bin/vmware-config-tools.pl
and said “Yes” to the all the questions except the “X” server install drivers and then rebooted.
My Vmware Server still happily showed that I was still running Vmware guest tools in the Ubuntu guest, but my network transfer speeds were 1000x (rough guess..) better than before. Now copying that 13.9 MB files is instantaneous.



PHP RGB Function for Excel or Word Document COM Manipulation

August 6th, 2010 No comments

Recently I had a project that needed to create and format a word document, based on data from a MySQL database. While the solution was on an MS platform that had Word available, I could only use PHP for the scripting language as it was a language that was used by the rest of the team. The system would call the Word com object, create a new word document and formatted a report, using the “word.application” COM object.

One issue I ran across was that that coloring a font object in any VBA Macro script often times used a simple built-in function called “RGB”. I translated a PERL version below that seems to work quite well in PHP. Hope this helps someone else. This can also be used in formated RGB values in Excel document manipulations.

function phpRGB ($r,$g,$b){ 
	return $r + (256*$g) + (65536*$b);
}
 
//example usage:
    $wobj->Selection->Font->Italic = 1;
    $wobj->Selection->Font->Color = phpRGB(153,204,255);


Dead Simple Java Web Services and Clients

March 11th, 2010 Comments off

If you are like me and have seen a ton of languages out there provide web services with a few simple instructions (Perl / PHP / Python), you may have the impression that it should be pretty easy in Java? Couple of lines of code and voila a server. A few more lines and voila a client that consumes said service. Unfortunately that does not seem to be the case in my experience. WDSL setup this…wimport that (but only with JDK’s greater than 1.6_05..).

Here is a dead simple way to setup clients and services in a few steps.
Read more…



Apache Cayenne – Simple Count Query

August 16th, 2009 Comments off

I’m currently working on a project involved with using Apache Cayenne, a pretty lightweight ORM (object relationship mapping framework). So far I have been very impressed with its ease of use over other framework such as Hibernate and the minimalistic approach it takes to the mapping. Configuration files are used at a minimum and they are extremely easy to understand.

The one thing that I have found a bit lacking, are straightforward real world examples. While, the Java documentation is fantastic and there are only a few minimal “Getting Started” pages on the main website, I really couldn’t find a good example of some more complicated logic examples.

In anycase, here is some code that hopefully will save someone else a bit of time. This is an example of how to call a “NamedQuery” in Cayenne that accepts a single parameter and returns a count of rows for a particular table. This assumes at least a basic understanding of the Cayenne system and that you have at least been through the tutorial.
Read more…



Netbeans 6.7 Database Explorer Timeout Workaround

August 12th, 2009 Comments off

I had small issue recently in that the Netbeans 6.7 database explorer was timing out just trying to connect to my production database. Apparently the Mysql server needs to respond back within a few mili-seconds and there are no configuration settings in Netbeans to increase this timeout. Our production database has an initial lag time when you first connect, but it is pretty zippy thereafter (I suspect my cheap home based switches or my Windows computer).
Read more…



Quick PHP RSS Feeds

August 10th, 2009 Comments off

Here is a snippet of code that I wish I had when I needed to write a small routine to output a PHP RSS feed.
RSS Feeds are XML-like so they need to be carefully crafted.

1.) Setup the main header of the rss feed. Remember to carefully escape all of your text going into string
fields using htmlentities().

Read more…

Tags: , , , , ,


Complex Perl Hashes

August 5th, 2009 Comments off

Perl is one of my absolute favorite languages to prototype in. While very easy to model complex object structures, the syntax of Perl Hashes can get a bit tricky to remember. This is just a quick “Get Started” guide that I hope will be useful to other developers.
Read more…



KML Placemark Updates in Google Earth

August 3rd, 2009 Comments off

While working on a prototyping project for a customer, I was having problems “updating” existing placemarks in Google Earth that had been created by a simple Network Link file. Granted I was writing a custom web server to server KML data, but it was not immediately clear why my KML data was not being interpreted correctly.  While Google Earth’s KML Documentation is fairly comprehensive, it seems to lack a good deal of simple examples.
Read more…