published over 4 years ago
(31.01.2006 23:25)
this chunk of code is completely useless, apart from the fact that it let me practise how ruby does arrays, objects, constants, observers and singletons. and how to pass a variable number of arguments to a function method and set defaults for arguments that weren’t passed. plus it had me thinking about “what-goes-where” and coupling in object oriented programming.
maybe not so useless after all!
`93113537’ could not be displayed because:
File does not exist: .
require 'observer'
require 'singleton'
class StickFigure
MALE = 0
FEMALE = 1
attr_reader :name
def initialize(attrs)
@name = attrs[:name] ||= 'Anonymous Coward'
@sex = attrs[:sex] ||= MALE
@is_lazy = attrs[:is_lazy] ||= false
@in_peril = false
end
def in_peril!
@in_peril = true
puts @name + ' is in peril!'
end
def to_s
puts "\nHi! I'm " + @name + ' and I am ' + (@is_lazy == true ? 'a little' : 'not') + ' lazy.'
end
alias :introduce_self :to_s
end
class CoffeeDrinkingStickFigure < StickFigure
def have_coffee
puts @name + ' has a cup of coffee.'
pot = get_coffee_pot
pot.pour_coffee
if pot.needs_refill?
make_more_coffee unless @is_lazy
end
return_to_desk
end
def return_to_desk
puts @name + ' returns to ' + (@sex == FEMALE ? 'her' : 'his') + ' desk.'
get_coffee_pot.notify_observers(get_coffee_pot, self)
end
def make_more_coffee
puts @name + ' refills the coffee pot.'
pot = get_coffee_pot
pot.refill
end
private
def get_coffee_pot
CoffeePot.instance
end
end
class CoffeePot
include Singleton
include Observable
attr_reader :cups_left
CUPS_WHEN_FULL = 2.5
def initialize
@cups_left = 0
self.refill
self.add_observer(BigBrother.new)
end
def pour_coffee
@cups_left -= 1
changed
end
def refill
@cups_left = CUPS_WHEN_FULL
changed
end
def is_empty?
@cups_left == 0
end
def needs_refill?
@cups_left < 1
end
end
class BigBrother
def update(pot, who_got_coffee)
if pot.needs_refill?
puts 'The coffee pot needs a refill and ' + who_got_coffee.name + " didn't refill it!\n"
who_got_coffee.in_peril!
else
cup_string = pot.cups_left == 1 ? 'is 1 cup' : 'are ' + pot.cups_left.to_s + ' cups'
puts "There #{cup_string} of coffee left."
end
end
end
stick_figures = [
CoffeeDrinkingStickFigure.new(:name => 'Miss Piggy', :sex => StickFigure::FEMALE),
CoffeeDrinkingStickFigure.new(:name => 'Bert'),
CoffeeDrinkingStickFigure.new(:name => 'Kermit', :is_lazy => true),
CoffeeDrinkingStickFigure.new(:name => 'Ernie', :is_lazy => true)
]
stick_figures.each do |stick_figure|
stick_figure.introduce_self
stick_figure.have_coffee
end
Posted in ruby, coding, photography | Tags flickr, oop, ruby
published over 4 years ago
(30.01.2006 15:53)
what’s wrong with this javascript?
function showDetailInNewWindow()
{
// set new window properties
top = 200;
left = 250;
width = 680;
height = 300;
// ... proceed to open new window
}
the error message ie gave me: “not implemented, line 26, character 7”. in _which _of the included js files, you ask? well if it gave that information out, the error would be too easy to find, wouldn’t it?! and when you finally debugged which file it was, the line number was a couple of lines off.
this error message is as useful as asking your grandma’s parrot what was wrong with the code. except the parrot’s reply would be more intelligent.
2 hours lost. talk about efficient development. i’ll consider writing my front-ends in xul.
the error was (i figure): you shouldn’t use “top” inside a function. JS has all global vars in function scope as well, and ie allows you to omit “window” in some expressions. i.e. ie thought i was trying to say “window.top = 200”. which it
- should have just done
- complained that it’s a read-only property
- complained that the object window doesn’t have that (public) property
or maybe top is a completely reserved keyword, why didn’t it tell me???
of course i only had to resort to opening the details in a new browser window since IE first needed loads of hacks and javascript expressions to get the data table i am displaying to look it as i wanted, and then, second completely messed up the while document when dynamically embedding the detail information into the current page (“ajax”).
ie 6 is definitely web 1.0.
Posted in firefox, css & javascript, coding
published over 4 years ago
(29.01.2006 22:37)
some time ago i started making a list of countries and cities i want to visit. maybe not in the near future, but in this life. i keep adding to it … just today, another eight places joined the list.
maybe i should rather put together a list of places i don’t want to see – it might end up being shorter.
p.s.: i’ll start working off the travel list this july :-)
Posted in travel, wisdom & quotes, the rest
published over 4 years ago
(27.01.2006 16:26)
“You are never dedicated to something you have complete confidence in. (No one is fanatically shouting that the sun is going to rise tomorrow. They *know* it’s going to rise tomorrow.)
When people are fanatically dedicated to political or religious faiths or any other kinds of dogmas or goals, it’s always because these dogmas or goals are in doubt.”
from “Zen and the Art of Motorcycle Maintainance” by Robert M. Pirsig
Posted in wisdom & quotes
published over 4 years ago
(27.01.2006 16:17)
… wasn’t too hard, thanks to the rake migrate command and typo’s nice upgrading system, which slash7 had pointed to.
conversion of all mysql tables to InnoDB didn’t work at first. since i’m still on mysql 4.0 the upgrade script 15 and the ruby on rails’ create_table method failed. they both use the ENGINE keyword for specifying the table type to use. in order to get things to work, i had to replace ENGINE with TYPE.
btw. typo claims that running off the latest trunk revision is no problem thanks to the extensive test coverage. however most of those tests had some failures on my box; well, let’s see what happens - typo seems to be running fine. it _is_ a little awkward that you have to keep tests up to date with the latest code changes; maybe they just forgot.
warning: before running tests, make sure you have configured different databases for test and production environments, otherwise you production database will be gone!
Posted in ruby, coding
published over 4 years ago
(26.01.2006 14:03)
“A language that doesn’t affect the way you think about programming is not worth knowing” – Alan Perlis
Posted in coding, wisdom & quotes
published over 4 years ago
(25.01.2006 01:05)
Stereo Total’s Diskotheque

françoise cactus and brezel göring deliver finest trash, as always. who else could fit a rolling stones cover version, christiane f, chelsea girls and rendezvous with marsmen onto one single album? this time more electro than ever though; which sounds good.
for a first taste, just read the song names. for a second one – samples of every song available in the itunes music store.
- Everybody In The Discotheque (I Hate) We Love Motor Nark Mix
- Europa Neurotisch
- Mother’s Little Helper (We Love Polyphonic Size-Doctor Pleeease Mix)
- Mars Rendezvous (We Love Jacno Mix)
- Je reve encore de toi (We Love Taxigirl Mix)
- Babystrich (We Love Christiane F.Mix)
- Bad News From The Stars
- Everybody In The Discotheque (I Hate) Version By Echokrank
- Chelsea Girls (Thieves Like Us Remix)
- Das erste Mal (Vredus Remix)
- Troglodyten (Munk Edit)
- Das erste Mal (Justus Köhnke Remix)
- Das erste Mal (Mad Professors Dub Trip 1)
- Das erste Mal (Mad Professors Dub Trip 2)
- Das erste Mal (Mad Professors Dub Trip 3)
- Das erste Mal (Mad Professors Dub Trip 4)
Posted in music
published over 4 years ago
(21.01.2006 13:48)

switched to typo
today i migrated my site from a home-brewn php/one-html-page solution to the ruby on rails powered weblog typo (which is not to be confused with typo3). what had to be done:
- locally update ruby on rails to version 1.0 and install typo.
- parse the existing html page with all the log entries, and feed the extracted posts into the ruby on rails database.
- find a nice template and tweak the stylesheet here and there.
- fix all image links to be absolute, convert the log entries to utf-8 (had to install the iconv library for ruby).
- upload the locally prepared installation to the webserver, create and fill the online database.
- compile ruby, ruby-iconv, ruby-fcgi, ruby-mysql, pcre and lighttpd on the webserver; then install ruby on rails.
- configure apache to forward (proxy) all requests to lighttpd, configure lighttpd to embed ruby via fcgi
- write a start/stop-script for lighttpd and make sure lighttpd is run on startup.
all of this took about twelve hours to complete. more than half of the time was spent preparing the webserver — finding out what was needed to get ruby and lighttpd work together over fcgi.
if you’d like to see conversion scripts, take a look at the extended content of this post.
(i am) happy rubying!
try ruby if you like – an interactive ruby shell that runs directly your web browser.
you could also visit why’s hilarious blog, or his poignant guide to ruby, where you’ll find many more cartoon foxes!
Read more...
Posted in ruby, coding