Reason #902,423 why Java sucks
I've grown increasingly annoyed at Java over the years. I've taken to describing the language designer's philosophy as "If there's two ways of doing anything, pick the one that involves more typing".
All I want to do in take an array of numbers and convert it into a comma separated list, e.g. 1,2,3,4. Most modern languages make this easy:
- PHP:
implode(',', $data) - Perl:
join(",", $data) - Python:
",".join(data) - Ruby:
data.join(",") - .Net:
String.Join(",", data)
So how do you do it in Java? Well there's no built in method so you end up getting to write your own:
public static String join(String[] a, String separator) {
StringBuffer result = new StringBuffer();
if (a.length > 0) {
result.append(a[0]);
for (int i=1; i<a.length; i++) {
result.append(separator);
result.append(a[i]);
}
}
return result.toString();
}Maybe sometime around Java 9 they'll get around to adding it...
A smaller update
Been keeping busy. The dog keeps getting bigger and smarter. She's able to jump over the baby gates I've been using to pen her in the kitchen. She's also figured out how to stretch up and reach the counter so she can steal treats off of it while I'm not looking. But she's a great dog and I love her even when she is being a jerk.
Nick from NYC was out to visit last week. We had a good time and he was able to get all his stuff out of the basement of the old Russell Street house and mail it home. One of the highlights for me was last Friday when I hosted, what my friend Asia termed, Drew's Brews. Basically I invited a bunch of people over to help me drink the four gallons of porter that Steven and I brewed up. I'm hoping to repeat it again this weekend with a batch of pale ale.
This evening I went to Ignite Portland at the Bagdad Theater with Nick's friend Ingrid (who has a nice food blog). I was really impressed with the event, the speakers with the except the snake oil peddler who was trying to convince everyone that biodiesel is going to save us from our energy problems were all wonderful. I had a hard time picking favorites (though the history of the stick figure and why Germany loves David Hasselhoff stand out in my mind). I can't wait for the next one.
I just finished reading Queen of Candesce by Karl Schroeder. I'd read the prequel, Sun of Suns, last New Year's and loved it. I don't have the words to describe how amazing these books are. I'm just awestruck at the way he's able to construct a space opera that's convincing at every level; from the cloak and dagger intrigue of politics to the physics of constructing a city on the inside of a cylinder floating in air. In many ways it reminds me of the sweeping imagination and vision of the first Matrix movie (the big difference being that this sequel didn't suck).
A big update
It's been a while since I posted anything here. I'm a fan of bulleted lists so I'll just resort to one of those.
- Went to New York City. Stayed from Christmas to the 3rd and had a nice New Year's. Etta and I had some pretty major drama leading to...
- An un-engagement and break-up. No need to worry about planning a wedding now. Still need to call all the relatives... That said we're still talking, maybe we'll end up out on a date this weekend. What happens with Shasta and the house are open questions.
- Got a MacBook. The trusty old ThinkPad died. I'd sworn I wouldn't buy a Mac until they had a trackpad that you could right click. Someone had convinced me that the new Macs had two separate buttons in their trackpad but you and to enable the right clicking. Turns out they were full of shit and I'm left ctrl+clicking but it's still the best laptop I've ever owned. If you like UNIX then MacPorts.org is your new best friend.
- Booked a ticket to DruaplCon Boston. I used some frequent flyer miles. I don't have a place to stay or conference reservation but that kind of thing works itself out. When I went to the BeOS Developers Convention in Palo Alto back in '99 I ran out of money for a hotel room and slept in a park in the rain. I'm hoping to crash on someone's hotel room floor this time.
First post from the OLPC
I ordered one of the OLPC laptops through the G1G1 program back in November and after some miscommunication from the OLPC and screwups by FedEX it finally arrived. Several things--like opening it or connecting to a network--have been non-obvious but I'm pretty impressed overall. The keyboard is tiny.
Flex stops building the foo.html and foo-debug.html files
I've been trying to get up to speed on Adobe Flex for my CS Capstone project. I should mention, by some surprisingly enlightened decision, Adobe offers a free Flex license to students.
Everything was going great until I it suddenly stopped building the foo.html and foo-debug.html files that launch the foo.swf and foo-debug.swf files. Apparently other people ran into this too. I didn't figure out the proper fix for this but I developed a workaround based on a blog post by one of the Flex developers.
Basically, just rename the index.template.html to ${swf}.template.html and then do a clean rebuild. You should end up with bar.html and foo-test.html and be able to get back to work.
Replacing tabs with spaces in files
I've got a bunch of source code that I'd written with 4-character wide tabs. I needed to replace them with spaces. I'm ashamed to admit how long it took me to figure out.
#!/bin/sh
for i in *.[c,h]
do
expand -t4 $i > tabfree.txt && mv tabfree.txt "$i"
doneHopefully by posting this I'll save someone (read: me in six months) some time.
Lost my phone
I lost my cell phone last week. No idea where it went, probably in pieces in a gutter someplace. After seeing what a new, "cheap" phone was going to cost I said fuck it and threw down on a BlackBerry Pearl. After loading up the GMail and Google Talk apps I've gotta say it's the best phone I've ever owned. It's got a great interface and I'm sure I'll get used to their keyboard soon enough.
With dog
Etta and I picked up our new puppy from the Oregon Humane Society today. Her new name is Shasta and OH MY FING GOD IS SHE CUTE!

Portland Marathoned

As you can probably see my feet are pretty beat up... if you can't see that then click on the photo and check out the bigger version of Flickr. I won't claim to have run all 26 miles but I did move myself under my own power without using any wheels.
My half-marathon time was probably pretty good. I think I actually beat Etta to that point. She whooped up on me in the second half. I walked a big part of it and I think she finished a half hour or so ahead of me. I really don't remember what my final time was, I managed a sprint for the last three blocks and about all I could see was the orange timing pad I had to cross and Etta smiling at me. It was great having her there waiting for me. There's no way that I could or would have done this without her. And now I never have to run again.
Getting busy
I do so much better when I've got a full schedule. When the day is wide open it's so easy for me to just put things off. The two big time eaters are school starting up, and buying a house with Etta and her mom. School's the normal pain in the ass, but with only two semesters left it's easy to be motivated. The house has been cool because I'm learning a bunch.
Sorting numeric values stored in character fields with views.module
I spent a good chunk of time this morning trying to figure out how to get the views module to sort a character field with numeric data correctly. The audio module has a normalized table of meta-data meaning that there's one column for the tag name and one for the value. The value is stored as a character string which causes problem when sorting numeric data like the track numbers or years. If you've got a SELECT value FROM audio_metadata ORDER BY value that returns the range of numbers 1...13 it ends up sorted as 1,10,11,12,13,2,3...9. The trick as I discovered is to add zero to the field to coerce it to a numeric value: SELECT value + 0 AS v FROM audio_metadata ORDER BY v.
The problem then is to figure out how to get the views module to generate this bit SQL to get the sorting right. The solution I came upon is when defining the field set 'notafield' to TRUE and provide a 'query_handler' to generate the correct SQL. I've included the relevant parts of the audio module below to demonstrate how it works. You can see the complete code here.
Burning Man Burned... LOL
In a bout of great, some guy set the Burning Man on fire. Laughing Squid has an excellent round up. I hope that guy has a defense fund setup because I'd love to chip in $10.
Using SimpleXML with HTML
PHP 5's SimpleXML module is one of the the biggest reasons to upgrade to 5. If you're parsing RSS feeds or the results of webservice requests it works beautifully and saves a ton of time. The only problem with it is that it'll only load valid XML. I banged my head against it for way to long before coming up with the following:
<?php
$doc = new DOMDocument();
$doc->strictErrorChecking = FALSE;
$doc->loadHTML($html);
$xml = simplexml_import_dom($doc);
?>Using PHP and CURL to do an HTML file POST
After scouring the internet to find out how to do multipart post operations and finding nothing nothing, I decided to save someone else some time. The trick is that @ before the file name:
<?php
$fullflepath = 'C:\temp\test.jpg';
$upload_url = 'http://www.example.com/uploadtarget.php';
$params = array(
'photo'=>"@$fullfilepath",
'title'=>$title
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);
?>Originally posted here: http://drewish.com/blogger/archives/2005/01/27/using_php_and_curl_to_do_...
in nicaragua!
from: Etta Mo
date: Jun 20, 2007 4:47 PM
subject: in nicaragua!
hola! andrew and i are in grenada, nicaragua right now, enjoying the
muggy, wet, warm weather. grenada is beautiful although the colonial
architecture and breathtaking views are in stark contrast to the
overall poverty of the country and city. The Casa Chandler, where we
are staying, has a very refreshing swimming pool located in the
courtyard, which is surrounded by the open-air kitchen and living
room. we are staying in the suite upstairs with a balcony that
overlooks the pool. our room is very nice but the mango tree above
the bedroom roof makes a lot of noise when the wind blows, which
happens to be whenever i am trying to sleep. andrew, the log that he
is, sleeps right through it. the manager of the Casa Chandler, John,
hired someone to come and take care of the problem today so i should
be able to sleep well tonight.we've already met lots of really nice people who have been incredibly
helpful and fun. we met a woman at the airport named melissa who we
continued to bump into in grenada. this chance encounter led to a
boat tour of the 365 isletas that are near the shore of Lake Nicaragua
(formed one of the many times that Volcan Mombacho blew up). The boat
tour began in the late afternoon and took several hours. By the time
we made it back to the dock, it was pitch black and the only light was
from the moon and the stars (this is a good example of the shoddy
infrastructure- grenada is perhaps the wealthiest and most developed
city in nicragua and yet is still subject to long power outages and
several hours of no running water per day. did i mention the
refreshing pool?) The isletas are private islands, some of which are
inhabited by people who make their living in Grenada or fishing.
others are obviously owned by people who have money. serious money.
even by american standards the homes are outrageously large and
somewhat ostentatious. however, in the middle of this is an island
"owned" by monkeys- cute, furry, monkeys that we took plenty of
pictures of. overall, the boat tour has been one of the best things
we've done while down here, but there have been so many amazing
experiences (in such a short period of time) that it's hard to say!we could go on and on about all the things we've already seen and
done, but we will save that for another email. for those of you who
heard about my most recent bout with illness, rest assured that
whatever was in my stomach before seems to have conferred (at least
temporarily) an immunity to the strange microbes down here. andrew
has a stomach of steel and, as such, has been eating with wild abandon
("oh, what's that? i'll eat it!")i hope you are all doing well!
love
etta and andrew