Animated Box

I’m very, very early on in the effort of this graphics/game test. But essentially I wanted to write down where I’m at with Xcode, OpenGL and learning C++.

Learning C++ by starting with OpenGL is very stupid. I admit this. It’s the wrong way to start out. It’s like learning how to walk by jumping out of a Dodge Viper. But I want to get beyond the Hello World books and after trying for two or three years in my limited spare time, I’m finding that being thrown into the fire is somewhat motivating. I learned Java the same way (not that I’m a master of that either), I gave myself a goal that I really wanted to accomplish and the rest just fell into place because I couldn’t think about anything else.

Such is my animated box. I want to move a box in a really smart way. Not just some Box.setX(i++); Box.setY(j++) in the main() method but something smarter that would enable me to move two, four or one-thousand boxes in the future.

animated box

More coming…

xcode glclearcolor

Chapter 4

Going through the Oreilly book Practical C++ Programming, which may be an arguable title, and I’m just trying to go through all of the examples and save them somewhere so I know where I left off the next time I’m feeling recklessly productive.

Specifically, Chapter 4 asks

Exercise 4-2: Write a program to print a block E using asterisks (*), where the E is 7 characters high and 5 characters wide.

Of course the easy way would be to just print out a bunch of strings. But I consider that cheap. So I played around with struct and typedefs but I don’t know what the hell I’m doing with those so I instead forced myself to learn about passing by value vs. passing by reference.

First, the function makeE() creates an integer array which in my world of goals could be a game model, or x,y,z points for some game object. Then printE() prints out the array, but only an array of 7. If I wanted to do this whole thing much better I’d use a vector.

It’s rough shifting gears back to C++. I don’t know if I’ll ever get really good with it and be able to get to the fun stuff. You can see below that another version just printed out way too many *’s.

e messedup

/*
 *  4-2.cpp
 *  Practical C++ Exercises
 *
 *  Created by Chris on 1/21/07.
 *  Copyright 2007 hexameter.com. All rights reserved.
 *
 */
// write a program to print a block E using *, where e is 7 high and 5 wide.
#include <iostream>

void makeE(int int_array[])
{
	int_array[0]=5;
	int_array[1]=1;
	int_array[2]=1;
	int_array[3]=5;
	int_array[4]=1;
	int_array[5]=1;
	int_array[6]=5;
}

void printE(int e[])
{

	for (int i = 0; i < 7 ; i++)
	{
		for (int j=0; j

But then finally, it worked suddenly after I made some adjustments.

e success

This is all just beginner stuff. :(

Old Email Syntax

I ran into a 1994 post from Jeff Liebermann, very funny, very interesting read because he’s ranting about computer support. It has historical significance because he’s talking about the early days of the net and PCs. He’s talking about 2400 baud modems, 3.5 floppy drives, losing the CMOS disk geometry on an IDE drive and all this 1990 tech. But right at the end he had something that sent me off on a trail.


# Jeff Liebermann Box 272 1540 Jackson Ave Ben Lomond CA 95005
# 408.336.2558 voice wb6ssy@ki6eh.#nocal.ca.usa wb6ssy.ampr.org [44.4.18.10]
# 408.699.0483 digital_pager 73557,2074 cis [don’t]
# jeffl@comix.santa-cruz.ca.us scruz.ucsc.edu!comix!jeffl

In his signature he has that bit in red. It’s completely foreign to me. Of course, searching for the name of something on Google, when you don’t know the name of what you are searching for, is a near-impossible task. Luckily, wikipedia came to my rescue in a very simple way. I looked up exclamation mark and lo and behold wikipedia says

Early e-mail systems also used the exclamation point as a separator character between hostnames for routing information, usually referred to as “bang path” notation.

Ah, of course, bang is another term for exclamation point. So I looked this up and found that this bang path notation is also related to UUCP notation. Which makes sense because it’s a list of hosts to route to and then at the end of it, a user name.

I also reflected that this process of routing to machines and then delivering to a user account is not gone. The modern user@domain SMTP styled does this same thing with MX records. When you email to domain.com, a MX query is done (perhaps many times) and SMTP can forward mail indefinitely (checking for loops) until finally a user is found and the email is delivered. But the complicated syntax is gone. Certainly user@domain is much more intuitive than domain!user, email clients can autocomplete the address easier because you’re likely starting out with a friendly name like joe@yahoo, people aren’t really intending to email the machine anyway. The joe@yahoo SMTP syntax is more friendly than yahoo!joe for these ease of use reasons.

But even with all this digging, I wonder if this is the real reason that UUCP died out. Wikipedia says that SLIP and PPP services offered by ISPs killed UUCP but is that directly related to the bang-path notation? SLIP and SMTP aren’t technically related, but maybe just timing and convenience related.

Here we go!

Read the rest of this entry »

SWAT

pagination
Swat, a nice PHP toolkit at silverorange.com has caught my attention a few times.

First, they (or someone in their group) designed the firefox and thunderbird vector icons. Next, they’ve released a few webapps (PHP). I ran into a demo they have online that showcases some widgets they’ve built.

It’s a fantastic little page full of good UI components that would really help out usability. Unfortunately, I’m not using PHP really anymore but I hope to find (or build) something similar to this in Ruby and Java. And not ugly components either, similar quality. I’m sure there are widgets and components that are not up to this quality.

x.succ

x.succ

[ "H", "A", "L" ].collect {|x| puts x.succ }

Prints out:

HAL, plus one letter up, equals IBM. Pretty funny.

Dave Thomas on Rails

dave_thomas.jpg

A while ago I ordered a Ruby book entitled, “Programming Ruby by Dave Thomas” off amazon (bookpool was close on price). I read the first few chapters, got hung up on syntax and my interest was peaked.

One week later, a coworker says “Hey! Dave Thomas is speaking at NovaJUG!” (northern virginia java users group). It was uncanny and I had to go. To be fair, the opening act (as he called it) was on PMD Applied, by Tom Copeland. He has written a book on PMD. Essentially what I got out of it was a normalization process for code. No duplicate code, no logical duplication and a Java tool to help detect it all. I think Tom discredited himself a bit (understandably) by feeling like everyone was there for the Ruby bits. This was only mostly true for me. I wanted to see what the Java end of the JavaJUG was like. I enjoyed his presentation although I felt he could have been more confident even if he was just the ‘opening band’. Tom knows his stuff for sure.

Dave Thomas got up and explained what Ruby on Rails is, what Ruby is and why he’s even attempting to give his talk to a Java Users Group. He explained that his talks are becoming more and more popular at Java seminars. Why? Probably because it’s not a 300lbs hammer like Java is. He had a good point about Programmers aren’t Programmers anymore. They are “Java Enterprise Programmers with XYZ framework experience”. A carpenter with only one tool.

Ok point taken. But onto the gritty details. Where does Ruby not work? Where does it break? How can it be perfect? He did a good job of answering all of these common questions and explaining that Rails works for an estimated 70% of projects and the remaining 30% it might work 50% of the time if you changed the requirements or pushed back on the customers.

A really depressing part of the talk was when he explained that this Java programmer he talked to rewrote an app in Rails at night and in his free time. The XML configuration of his Java app was 400+ lines, just the XML config. Took him 4 months for the Java piece. The same app in Ruby was less than 400 lines of Ruby code and he did it in 4 nights (spare time). Now, obviously if you rewrite something you already know requirements, how the app works, domain experience and all the other stuff you already did. So Dave said “double the time! why not! 8 days!”.

I’m still not convinced. So he starts talking about JCP. Said something like, “Take a good idea and put it into a Java committee where a bunch of vendors all influence the direction of a new spec to make the most money. JSF was written so humans can’t write it! So you’d have to buy a tool! Sun has killed Java. If you look at C# and Java5, it’s a checkbox contest. Generics, check. Autoboxing, check.”

Ruby has configuration files that are written in Ruby. No XML (unless you want to). Ruby makes a lot of assumptions to make your life easier. You can override the assumptions but could as easily take the defaults to make it quicker.

Dave then started coding on his mac laptop and we all watched. He used MySQL as a database, YourSQL as a MySQL frontend (to create tables quick), TextMate as a text editor (did Ruby syntax autocompletion a bit) and a standard OSX terminal. He created a database table and with one line of code ’scaffold’ had the table on the web with ’show’, ‘edit’, ‘destroy’ functionality per row. Basic functionality. He had run some scripts to generate the controller (comes with unit test). But what he hadn’t done was the killer. He had URL rewriting (Rails does that), he had a simple database mapping (Rails I think) and he had a server running on port 3000 with no jboss or tomcat config deployment etc.

Everyone was excited. I was excited.

He talked about how you can freeze your Ruby interpreter to your vendor/ directory within your development directory. So if a new version of Ruby or Rails comes along you aren’t screwed if you try out the new version.

He talked about a free ruby tool called SwitchTower that lets you control versions of Ruby apps (not Ruby only) on deployment. SwitchTower can roll back versions if a bug is found. Looks neat.

He continued on at the end by talking about the future of Ruby. He talked about JRuby. Ruby running a Java VM. You can call java objects from Ruby natively, way cleaner than that JNI crap. He talked about possible verions of Ruby with bytecode like Perl6. It’s all very new.

It was a great talk, he graciously signed my book. Dave Thomas is excited, honest, charmingly English (he forced him to pronounce status like us yanks — Stah-tuss vs Stay-tuss) and approachable. I could tell he’s done lots of these talks, he’s invested in Ruby, he’s selling his book. But that’s his job for now. Ruby speaks for itself upfront and I’m just going to have to explore the rest. Dave Thomas and others were also invested in Java. But they aren’t throwing it away (maybe some are). His point is to not use Java for everything. Not to use Ruby for everything. Anyone who says one tool to bind them all is a salesman.

Don’t use one tool for everything. If I want to quickly parse XML in Java, what do I have to do … get Xerces, Xalan, a million jars with the right version. XML, Webservices, Unit Tests, AJAX, real object oriented stuff is just built into Ruby. It’s new. It’s improved. You might like it for a side tool project. Or a Java side-helper.

Don’t drop Java he said. Don’t force and sell this to your boss. Try it out. Make an app quick and when people ask, “how the hell did you do that?” you say, “oh it was nothing”.

What I’m doing.
I’m reading his book. I’m going to try it out. I’m going to see if I can write something quickly and use all these neat features. So far the syntax is weird, I miss my curly braces. But even without a book the commands and scripts are fairly self explanatory. Emerging rails was a cinch under gentoo:

ACCEPT_KEYWORDS="~amd64 ~x86" emerge rails

And then I just mkdir “ruby” and “cd ruby” and “rails myproject”. I ran “script/server” and I had a rails server running on port 3000. That was easy. Like 5 minutes.

The rest of it is the kicker I think.

A courier4 upgrade snag.

I ran into a weird error with Thunderbird. When I would reply to all in an email, some people were CC’d. When I hit send, I got a relay error. I restarted courier-imap and did all sorts of stuff and eventually decided to update all my mail software on my gentoo server.

It was a long shot but it actually fixed the CC: problem. Whether or not it directly fixed the CC: problem, I cannot prove.

I did a

# emerge courier-imap postfix

without enabling ~x86 unstable packages or bleeding edge stuff. It happily emerged and didn’t work. I couldn’t log into IMAP but postfix ran fine.

I was running courier3 and emerge picked up courier4.0.1. Postfix went from 2.0.4 to 2.2.5. Postfix did some upgrade bits on databases and config files (I think). But courier-imap was dead in the water.

I had (and still have) a problem getting courier to log a bit more, like more debug messages.


imapd: authentication error: Input/output error

That wasn’t quite enough. But luckily this message was enough to run into a forum post:


authdaemond: /usr/lib/courier-authlib/libauthpam.so.0: undefined symbol: nscd_flush_cache

This is a shared library problem. Someone linked against a file I don’t have, so it bombs at runtime. I found this bit via Google cache (the original hint has been removed..weird).

Now test the POP3 using any MUA. If you get an error message (with DEBUG_LOGIN=2)

libauthpam.so.0: undefined symbol: nscd_flush_cache

you are using broken version of courier-libpam. Try this:

# echo “>=net-libs/courier-authlib-0.57″ >> /etc/portage/package.mask
# emerge courier-authlib

I have had problems with 0.57 versions, version 0.55 works fine.

I did exactly that. Masked 0.57 and re-emerged. I restarted a few services:

# /etc/init.d/courier-authlib restart
# /etc/init.d/courier-imapd restart

And was able to get to my IMAP mail again.

Strip off tabs in vim

When you paste a block of text into a Putty window, many times you’ll get an increasing number of leading tabs. Not so if you use gnome-terminal (IIRC). Quite annoying in a Windows world.

Strip tabs and spaces out from current position to the end of the file with:

:.,$s/^[<tab>]*\s*//

Or perhaps you only want a small block in the middle of the file changed. First, turn on line numbers.


:set number

Then search and replace on specific line numbers (in this example lines 15 through 41).

:15,41s/^[<tab>]*\s*//

Then use Ctrl-V (down arrow or h,j,k,l keys to select block) and hit “>” to re-indent. Works much better than reformatting by hand.

Data Structures Book

On a slashdot thread I was discussing whether I should roll my own data structure or try to use one of the many, many Sun data structures.

Someone recommended this book.