{ |one, step, back| } 5 of 5 articles Syndicate: full/short

New Blog Name   10 Mar 08
[ print link all ]

Ryan Tomayko has pointed out, my blog title does not conform to standard Ruby coding conventions. We need to fix this.

Ryan Tomayko has done a review of blogs using code snippets as there title and has pointed out that mine does not conform to generally accepted Ruby coding standards. You see, in “{ | one, step, back | }” I use spaces between the vertical bars and the argument names. Proper Ruby code would never be written that way.

He’s right. So in order to promote better Ruby coding practices, I’m renaming the blog to “{ |one, step, back| }”.

Let it never be said that I ignore standards.

An aside: The use of {||} in the title was inspired by a Smalltalk logo that used [|]. See the powered by banner at the bottom of the sidebar in James Robertson’s blog for an example.


comments

Innovative Identification   28 Sep 05
[ print link all ]

Dick Hardt’s OSCON 2005 keynote talked about how to identify yourself online. Here’s an IRC conversation the ensued after I accidently issued a sudo command on a friend’s system, one that is monitored very closely by the sysadmin.

[22:35] <paulv>    matthew immediately declared that we were already cracked. :)
[22:35] <matthew>  yeah, it's all good.  Although, can you prove you're Jim?
[22:35] <jweirich> yes
[22:35] <jweirich> ask me a Ruby question
[22:35] <paulv>    implement the Y-combinator!
[22:35] <matthew>  heh
[22:35] <paulv>    then I'll believe.
[22:36] <jweirich> p proc { |le|
[22:36] <jweirich>   proc { |f| f.call(f) } \
[22:36] <jweirich>   .call ( proc { |f|
[22:36] <jweirich>            le.call (proc { |x| f.call(f).call(x) }) })
[22:36] <jweirich> }.call(proc { |recurse|
[22:36] <jweirich>   proc { |n|
[22:36] <jweirich>     if n == 0 then
[22:36] <jweirich>       1
[22:36] <jweirich>     else
[22:36] <jweirich>       n * recurse.call (n-1)
[22:36] <jweirich>     end
[22:36] <jweirich>   }
[22:36] <jweirich> }).call(5)  
[22:37] <matthew>  wow.  This is better than gpg keys.
[22:37] <matthew>  I hope you had that laying around 
[22:37] <jweirich> nah, did it from memory ;)
[22:37] <paulv>    this *is* better than GPG keys.

(and for those that missed the winking smiley, no, I did not do this from memory)

Update

I see that Dick Hardt’s OSCON 2005 presentation on Identity 2.0 is available at http://www.identity20.com/media/OSCON2005. This is worth seeing.


comments

Cheating at Computer Games   27 Jan 05
[ print link all ]
One of the most enjoyable programming exercises is writing a computer program that plays a game.

Paper Rock Scissors …

The weeks Ruby quiz involves writing a simple program to play the game "Paper, Rock, Scissors". Soon after the comments started on the quiz, someone submitted this 12 line "cheating" program:

  class Cheater < Player
    def initialize opponent
      Object.const_get(opponent).send :define_method, :choose do
        :paper
      end
    end

    def choose
      :scissors
    end
  end

It cheats in that it dynamically modifies its opponent object so that it always returns :paper, making it trivial to beat. While it does cheat, it does show some clever "thinking outside the box" approach to playing Paper, Rock, Scissors.

This reminds me of a story …

Greed

A number of years ago, I used to teach C++ in GE’s after hours education program. One of the projects assigned to the class was writing a player for the game of Greed. Greed is a simple dice game where you score points by rolling a set of 5 dice. You can continue to roll as long as you continue to make points on each roll. However, a row that has no point value causes you to lose all the points for a turn, so there is some value in stopping while you are ahead (hence the name Greed).

The game framework handles the dice rolling. All the student’s prgram had to do was decide whether or not to roll again given the the current state of the dice.

As part of the course, I pointed out that the encapsulation and data hiding features of C++ made it difficult to "cheat" by effecting the framework or other player objects. One particular student took this as a challenge and announced that he had a "cheating" player program that stayed within the "rules" setup by the C++ langauge, but yet would always win.

How did he do it? This cheating player would record the state of the seed of the standard library’s random number generator. It would then do trial rolls of the dice until it got a high scoring roll. Then it would reset the random number seed to the value that produced the high scoring roll, and indicate to the game framework that it wanted to roll again. The framework would comply and give the player the high scoring roll that it was setup to do. The cheating player would win the game in a single turn.

The cheat was easily defeated (once the cheat was understood) by using a private random number generator that wasn’t accessible to the player programs. But I learned two things from this exercise:

  1. Programmers love challenges, especially the kind that say "You can’t do this …"
  2. Secure software is hard to create, particularly because of point 1.


comments

Geek Birthday Humor   20 Nov 04
[ print link all ]
I’ve had a lot of fun with my birthday this year. I tell people that …
I’m going to turn 30 this year.

Then I pause and let them do a double take at the graying color of my hair, and then finish with …

… hexadecimal.

The joke goes over pretty well amongst my geek and programmer friends. However, when used in non-geek company, they just look at me as if I lost my mind.

Perhaps I have.


comments

Saw this ...   23 Jan 04
[ print link all ]
in a UseNet signature:
  A: No.
  Q: Is top-posting okay?

comments

 

Formatted: 22-May-13 03:34
Feedback: jim@weirichhouse.org