Wednesday, June 04, 2008
What am I doing here??
Friday, May 02, 2008
That which is lost is now found.
–noun
1. a central point, as of attraction, attention, or activity: The need to prevent a nuclear war became the focus of all diplomatic efforts.
2. Physics. a point at which rays of light, heat, or other radiation, meet after being refracted or reflected.
3. Optics.
a. the focal point of a lens.
b. the focal length of a lens.
c. the clear and sharply defined condition of an image.
d. the position of a viewed object or the adjustment of an optical device necessary to produce a clear image: in focus; out of focus.
Last weekend I had my inlaws in town. It was a great time and we had lots of wonderful family outings. During there visit my mother-in-law saw a few of my photos and commented on wanting a few of them for Mothers day. So in the spirit of sharing I took her to my computer to show her a few things I didn't have prints of. In that process she saw a picture that I had never really liked or given much thought to. Because so many people have liked it I figured I would share it with you.
Post processing:
- Slight Orton Effect added
- Adjusted the lighting and color balance
- Added a darkened halo effect to draw the attention to the flower.
Camera: Canon EOS 10D
Exposure: 0.05 sec (1/20)
Aperture: f/4
Focal Length: 29 mm
ISO Speed: 400
Exposure Bias: 0/2 EV
Labels: orton, photography, photoshop, post, rose
Thursday, May 01, 2008
Breaking up an Address (Perl)
–adjective
1.twisted; coiled.
2.complicated; intricately involved: a convoluted way of describing a simple device.
Still working on this API. For some strange reason they require that all address be submitted to them in parts. So for example 164 N Cherry Lane would have to be submitted to them as:
Number: 164
Direction: N
Street: Cherry
Type: Ln
Other then the reasoning behind this boggles my mind, I pressed forward and found a wonderful perl module to accomplish the desired task. See my sample code below.
use Geo::StreetAddress::US;
my $full_address = "164 N Cherry Ln, 84660";
my $address_parts = Geo::StreetAddress::US->parse_address($full_address);
my $xml = ' <address streetno="'.$address->{number}.'" streetDir="'.$address->{prefix}.'" streetName="'.$address->{street}.'" streetType="'.$address->{type}.'" unit="" zip="'$address->{zip}'" yearsAtAddress=""/&rt;'
;
Make sure that you include city/state or Zip. Without it it will return undefined every time.
Thats it kiddies. Good luck and I hope that you never have to build an api for this client.
Labels: api, GEO, GEO::STREETADDRESS::US, perl, programming, STREETADDRESS, user, XML
Wednesday, April 30, 2008
In Deep Waters with Perl API's
–noun
1. | clearness or lucidity as to perception or understanding; freedom from indistinctness or ambiguity. |
2. | the state or quality of being clear or transparent to the eye; pellucidity: the clarity of pure water. |
For those of you that don't know what an API is. Then please move onto a post about photography, because this will mean nothing to you. But if you do lets jump in with both feet.
Last week I was asked to write an API with another software Client. I don't like to name names so we will keep it on the low down. But there instructions where this:
The general process for making a request of an XYZ system is:
1) Gather information from user
2) Construct an XML data structure for request with REQUEST root element
3) Open HTTP 1.1 connection to XYZ ‘service’ URL
4) Send XML request to XYZ with content type “text/xml”
5) Get XML response from XYZ
6) Close connection
I figured that with perl this was going to be easy. So I create a perl script to do this. I was going to use my good old tools LWP and just submit a STRING over as the content of the lwp::useragent. Here is my code:
my $xml = '
SOME XML HERE
SOME XML HERE
SOME XML HERE
';
my $cgi_url= "http://THE_URL/DIR_OF_SERVICE";
my $ua = LWP::UserAgent->new(keep_alive =>1);
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->post($cgi_url, Content_Type => 'text/xml', Content=>$xml);
if ($response->is_success) {
$c->log->dumper($response->as_string);
} else {
$c->log->dumper($response->status_line);
}
Every time that I ran this code I would get a 200 code response and NO body back from the other service. So onto trouble shooting the problem. Here are a few things to keep in mind when working on an issue with a third party vendor api:
- Always Assume that the problem is in your code and fix that first.
- Start with the simplest of things.
- Warn, Warn, Warn the crap out of your code.
- Don't go changing the core of your code until you know it isn't a problem with the vendor.
- Contact the vendor to have them check there end of the code.
- When all else fails goto lunch.
- After lunch if you still don't know what is wrong then change how your doing it.
my $xml = '
SOME XML HERE
SOME XML HERE
SOME XML HERE
';
my $len = length($xml);
my $sock = IO::Socket::INET->new(PeerAddr =>'ROOT_DOMAIN_OR_IP',
PeerPort => '80',
Proto => 'tcp'
);
die "Could not create socket: $!\n" unless $sock;
if ($sock){
print $sock "POST PATH_FROM_ROOT HTTP/1.1\r\n ";
print $sock "HOST: ROOT_DOMAIN_OR_IP \r\n";
print $sock "Content-Type: text/xml \r\n";
print $sock "Content-Length: $len \r\n";
print $sock "Connection: close \r\n";
print $sock "\r\n";
print $sock $xml;
my $stuff ;
while (<$sock>){
$stuff .= $_;
}
close $sock;
$c->log->dumper($stuff);
When that was completed two days later, I got a 200 success and no body of the message. WTF. At this point I decided to follow my steps for trouble shooting the issue. So onto the simplest answers first. Maybe they can only get XML that doesn't have new lines. So I added
$xml =~ s/\n//ig;
Submitted the code and low and behold it worked. Got a response from there server.
THE PROBLEM:
There are two sides of this issue, mine and theres. Any good perl guy will have already caught my problem so lets start with theres.
There code will only respond when it received completed post, with a proper close. In other words if I say I am going to be sending a specific content_length then it will only respond if it gets it.
My problem is that when I was sending my $xml it would only send the first line tell it reached the first \n or new line. Had I submitted my xml one line at a time it would have been fine.
So todays lesson is, KISS. Keep it simple stupid. It could save your life.
Labels: agent, io, IO::socket, lwp, lwp::useragent, perl, php, programming, socket, user, useragent
Monday, April 28, 2008
Borders or not
Labels: black and white, blossoms, borders, photography, spring
Wednesday, March 19, 2008
Been a while (Mysqldump Replace into vs Insert into)
If you use the linux command sed you can change all of your insert statements into replace statements like this..
mysqldump -u DATABASE_USER -p DATABASE_NAME |sed -e "s|INSERT INTO|REPLACE INTO|" > OUTPUTFILE.EXT
Labels: database, development, insert into, mysql, mysql mysqldump insert into replace into replaceinto insertinto, mysqldump, replace into, replaceinto
Thursday, March 01, 2007
Flickr Explorer, The Quest.
Labels: explorer, Flickr, photo, photography, springs, sulfer