Three till Seven

Archive for May, 2006

5 May 06 quick update about apartment

I’m still around, I just don’t have the Internet at my apartment. I want to post some entries on Ruby and Ruby on Rails, though, as well as write a proper entry, so I’ll probably snag Todd’s PowerBook sometime this weekend. The apartment is coming along nicely. Todd, the girls, and I spent a few days hauling things in and unpacking, and now I have everything out of the dorm but am still unpacking boxes. Tonight I plan to go home, get my computer hooked up, and empty out the last box. I also happen to have a card that’ll get me a free pair of panties at Vicky’s Secret, so I’ll run by the mall after I go grocery shopping.

11 May 06 meetings, jobs, and Appalachia

Gosh, it feels like forever since I updated this, and I’ve been itching to, I just haven’t been on the Internet when I’ve had free time. I’m always online at work, but updating my blog is something I think Lexmark would frown upon.

Let’s see, here are some updates in my life since my last entry:

  • Todd and I are going to visit my family this weekend. He’s got this idea of chasing down one of our peacocks, which so isn’t going to happen. It will be the first meeting of my family and him, so we’re all pretty nervous. Well, Todd and I are, my parents probably aren’t, and I doubt my brother is concerned.
  • I just sent my resume to a possible future employer: Jess sent me this job posting she received in her engineering email account about a Linux administrator position on campus. Now I do enjoy earning money, so I emailed the guy and explained how this summer I wouldn’t be able to work much, as I’m going to be taking 6 hours of classes and working at Site Lab. He replied that demand at first would be maybe 10 hours a week and afterwards maybe 2-3, so it sounds manageable. He also talked of a web developer position where he would need several highly visually appealing pages created. Holy crap, does that sound up my alley! Besides getting to administer a Linux box (Fedora Core 4, why does everyone run FC4?), I would get to play around in Photoshop or GIMP or something and create pretty web pages. Heaven.
  • I helped out today at the STLP State Competition and my supervisor at Lexmark thought it was a worthwhile program, so I got paid for my time there. I spent the afternoon standing around, looking inviting beside a booth about an outreach program at UK for high school students in Appalachia or that were minorities anywhere in the state, if they planned on majoring in an engineering or other technical field in college. I explained the program to the parents, teachers, and high school kids that were interested and offered free key chains and pens to the elementary and middle school kids whose eyes glazed over when I began my spiel.

16 May 06 presentations and pots

I just returned from a job interview for a web developer position for this site. I think it went well; my interviewer told me he was very impressed with some of the things I’ve been working on (I showed him past sites I’ve done). I’ll know by the end of the week if I have it or not.

I’m over at Todd’s now but I’ve no idea where that boy is. I told him I’d be back from my interview around 7 p.m., so I figured he would be here but I haven’t seen him. He left his computer on, though, so I figure he just ran out on a quick trip. Plans for tonight include hanging out with him and then with Jess at 8p to watch American Idol. I’ve been a complete slacker when it comes to following that show this season because I’m always doing something other than watching TV when it’s on. I can’t believe there are already only three contestants left; what happened to Paris??

At work I’ve been preparing a presentation about what I’ve accomplished this semester. I hate giving presentations about that sort of thing, but fortunately it won’t have to be long and it won’t be to a large number of people. I’ll just rattle on about how I created my main project and how I improved an already-existing side project.

Todd met my family this past weekend and that went very well. He spent a long time Friday night just talking with my dad out in the garage while Mom and I were inside, then spent a while with my brother, talking about weight lifting. He’s now incorporating some lifts that my brother taught him into his daily routine, which is neat, and then he and Dad are conversing via email about various things.

I brought back a lot of stuff from my parents’ house, including a cherry coffee table that got a lot shinier after it got Pledge-d, various kitchen supplies (thank you, Mom—now I have knives!), books, and CD’s. Todd griped because he had to help haul all my things in, but the apartment is much nicer with them and, really, I don’t think I could have survived much longer without my Orson Scott Card books. ;)

27 May 06 movies and photos

I’m at my parents’ house for Memorial Day weekend. I got in yesterday afternoon earlier than expected because my manager, after a department meeting, let us out for the afternoon. It still counts as an 8-hour day, too. I watched Ice Age and Robots yesterday, both of which I enjoyed, but Robots was awesome, and then Batman Begins today with Dad. Man, was that a great movie. I’d been wanting to see it for a while but it always seemed like the guys would watch it whenever I wasn’t around. I’d be hanging out by myself, doing my own thing, and get a call from Todd. “Hey, what are you guys doing?” “Not a lot, watching Batman Begins.” *mental ‘damnit!’*

I finally put up some photos of the apartment:
living room

kitchen

bedroom

I ended up getting the job as web developer. I didn’t want the Linux admin. position after I heard the details of what I would be expected to do and for how much: set up and maintain a Subversion repository for $6/hour, the standard pay rate for sophomores at UK. I don’t think so. The web developer position they knocked me up to $8/hour, which is decent and the work will be more fun. I’ll be designing new front page designs for a few sites.

28 May 06 the power of yield

Note: If you enjoy this article, you might also check out the Geeky Stuff section.

…and super. These two keywords allow you to pass control back and forth between parent and child methods, to weave power between a more general method (in the parent class) and a more specific method (in the child class) with ease and logic. Using yield and super effectively can help you maintain the DRY (Don’t repeat yourself) principle, keeping your code easier to maintain.

Say you have three classes for image creation: a parent class, Image, and two children: Raster and Vector. Now for your raster images, you’re going to be using the GD2 library for Ruby, and for your vector images, you’re going to be creating SVG images. Some of the functionality used to create any given image will be different, naturally, since with the raster images, you’re creating an image object, and with the vector images, you’re concatenating strings of XML SVG code. However, a lot of the code will be the same, and should thus be shared between the two children to avoid duplication. For example, the logic used to determine what color some text should be, or what shape you should draw, can be shared between the two child classes. Any shared code should go in the one common class between the two children: the parent class, Image.

Accessing Shared Code

That is, accessing code in a parent class method from a child class method of the same name. The trick is with super.

write_text() in Raster

def write_text( text, color )
  super() do |width, height, left, top|
    image = Image.new( width, height )
    image.draw do |canvas|
      canvas.color = color
      canvas.font = Font::TrueType['/usr/share/fonts/times.ttf', 20]
      canvas.move_to( left, top )
      canvas.text( text )
    end
  end

  image
end

write_text() in Vector

def write_text( text, color )
  image = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
  image << '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/SVG/DTD/svg10.dtd">'

  super() do |width, height, left, top|
    image << '<svg viewBox="0 0 ' + width.to_s + ' ' + height.to_s + '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'
    image << '<text font-family="Times" x="' + left.to_s + '" y="' + top.to_s + '" fill="' + color.to_s + '">'
  end

  image << text.to_s
  image << '</text>'
  image << '</svg>'

  image
end

While these two methods accomplish the same thing, they do it differently. However, each of them has a call to super. That will access a method of the same name in the parent class:

write_text() in Image

def write_text
  yield( 300, 100, 5, 5 )
end

All that Image’s write_text() is doing is passing values back to the child method that called it. Each child method’s super call defines variables in the block: width, height, left, and top in the line that says super() do |width, height, left, top|. The yield call in Image defines those values to be width = 300, height = 100, left = 5, and top = 5. To Image’s write_text(), however, it’s just throwing some numbers at the child method: it doesn’t know that the child method is going to use those numbers to define the dimensions of the image and the starting position of its text.

The definition of write_text() in Image is very simple, but it doesn’t have to be that way. There could be a great deal of calculation involved in determining what values the child methods should use for whichever variables are being passed to it. The parent class’s shared method is a place to store shared logic and shared data; let the child classes do the specific stuff with that general data.

Shared Variables Sans yield

Values can also be reached in the child class methods without using yield if instance variables are defined in the parent method:

write_text() in Image

def write_text
  @width = 300
  @height = 100
  @left = @top = 5
end

Then write_text() in both Raster and Vector would be able to access Image’s @width, @height, @left, and @top, as defined in its write_text().

Multiple Calls to super

Sometimes it may be useful to let the parent class’s method do some work, then the child class’s, then the parent’s again. In this case, you can call super and yield as many times as necessary:

Method in Child Class

def my_method
  return1 = super( 'a string' ) do |my_var|
    # Do some stuff with my_var
  end

  return2 = super( ['array', 'of', 'strings'] ) do |my_other_var|
    # Do some stuff with my_other_var
  end
end

Method in Parent Class

def my_method( value )
  if value.class == String
    yield( 'this is my_var' )
  elsif value.class == Array
    yield( 'this is my_other_var' )
  end

  # Checks to see if value can work with the <<
  # method, which both Array and String objects
  # have, and if so, adds another string to it;
  # this value is returned since it's the last
  # line of the method
  value << ' appended to value' if value.respond_to?( :<< )
end

yield Returns Data to super

The child class method can also throw data back to the parent class method by returning a value from the super block:

Method in Child Class

def my_method
  value_from_parent = super do |my_var|
    'this gets thrown back to the parent class method'
  end
end

Method in Parent Class

def my_method
  value_from_child = yield( 'becomes my_var' )
  'this gets thrown back to the child class method'
end

More Information

28 May 06 little old lady in the hedge

A little old lady is walking down the street, dragging two plastic garbage bags with her, one in each hand. There’s a hole in one of the bags, and every once in a while a $20 bill flies out of it onto the pavement.

Noticing this, a policeman stops her, saying, “Ma’am, there are $20 bills falling out of that bag.”

“Damn!” says the little old lady, “I’d better go back and see if I can find some. Thanks for the warning!”

“Well, now, not so fast,” says the cop. “How did you get all that money? Did you steal it?”

“Oh, no,” says the little old lady. “You see, my backyard opens up to the parking lot of the football stadium. Every time there’s a game, a lot of fans come and pee in the bushes, right into my flower beds! So, I go and stand behind the bushes with a big hedge clipper, and each time someone sticks his little thingie through, I say: ‘$20 or off it comes!’”

“Hey, not a bad idea!” laughs the cop. “Good luck! Oh, but before you go, what’s in the other bag?”

“Well,” says the little old lady, “Not all of them pay.”

28 May 06 think before you speak

Have you ever spoken and wished that you could immediately take the words back, or that you could crawl into a hole? Here are the testimonials of a few people who felt that way:

  1. “I walked into a hair salon with my husband and three kids in tow and asked loudly, ‘How much do you charge for a shampoo and a blow job?’ I turned around and walked back out and never went back. My husband didn’t say a word… he knew better.”
  2. “I was at the golf store comparing different kinds of golf balls. I was unhappy with the women’s type I had been using. After browsing for several minutes, I was approached by one of the good-looking gentlemen
    who works at the store. He asked if he could help me. Without thinking, I looked at him and said, ‘I think I like playing with men’s balls.’”
  3. “My sister and I were at the mall and passed by a store that sold a variety of candy and nuts. As we were looking at the display case, the boy behind the counter asked if we needed any help. I replied, ‘No, I’m just looking at your nuts.’ My sister started to laugh hysterically. The boy grinned, and I turned beet-red and walked away. To this day, my sister has never let me forget.”
  4. “While in line at the bank one afternoon, my toddler decided to release some pent-up energy and ran amok. I was finally able to grab hold of her after receiving looks of disgust and annoyance from other patrons. I told her that if she did not start behaving ‘right now’ she would be punished. To my horror, she looked me in the eye and said in a voice just as threatening, ‘If you don’t let me go right now, I will tell Grandma that I saw you kissing Daddy’s pee-pee last night!’ The silence was deafening after this enlightening exchange. Even the tellers stopped what they were doing. I mustered up the last of my dignity and walked out of the bank with my daughter in tow. The last thing I heard when the door closed behind me were screams of laughter.”
  5. “Have you ever asked your child a question too many times? My three-year-old son had a lot of problems with potty training and I was on him constantly. One day we stopped at Taco Bell for a quick lunch in between errands. It was very busy with a full dining room. While enjoying my taco, I smelled something funny, so of course I checked my seven-month-old daughter; she was clean. I realized that Danny had not asked to go potty in a while. I asked him if he needed to go, and he said no. I kept thinking ‘Oh Lord, that child has had an accident, and I don’t have any clothes with me.’ Then I asked, ‘Danny, are you sure you didn’t have an accident?’ ‘Yes,’ he replied. I just knew that he must have had an accident, because the smell was getting worse. So, I asked one more time, ‘Danny, did you have an accident?’ This time he jumped up, yanked down his pants, bent over, spread his cheeks and yelled ‘See Mom, it’s just farts!‘ While 30 people nearly choked to death on their tacos laughing, he calmly pulled up his pants and sat down. An old couple made me feel better, thanking me for the best laugh they’d ever had.”
  6. “What happens when you predict snow but don’t get any? We had a female news anchor that, the day after it was supposed to have snowed and didn’t, turned to the weatherman and asked: ‘So Bob, where’s that eight inches you promised me last night?’”

Pass it on to someone you know who needs a laugh and remember we all say things we don’t really mean, so think before you speak!