[QUIZ] LSRC Name Picker (#129)

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.rubyquiz.com/

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.

···

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

As most of you have probably heard, the Lone Star Rubyconf is on the horizon:

  http://lonestarrubyconf.com/

What you haven't heard before now is that the conference organizers need our
help. As is typical for these events, several gifts will be given away to the
attendees. Names for the prize recipients need to be selected at random.

That's where this quiz comes in.

The LSRC organizers would like us to build name picking applications they can
choose from. The functionality is very basic:

  * Your application needs to accept input as a list of attendees.
    At a minimum, you should accept names, but it might be nice to
    allow for additional details like the attendee's organization.
  
  * Each time your application is run, it should select and display
    a single name from the list. Your application should remember
    previously selected names and not choose them a second time.

The real quiz is how fancy you can make that process. The LSRC organizers are
looking for a lot of sex appeal in their name picker. Solutions that
incorporate the conference name or stars will be given extra consideration. The
goal is something that will have a room full of attendees entranced when run on
the projector. Any interface that meets the above criteria will do.

The conference organizers will recognize the author(s) of any selected
solution(s) at the event (your output can also include a byline), which will
surely lead to unending fame. Fortune may have to follow at a later date.

Sorry the quiz was late this week.

James Edward Gray II

Ruby Quiz wrote:

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.rubyquiz.com/

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

As most of you have probably heard, the Lone Star Rubyconf is on the horizon:

  http://lonestarrubyconf.com/

What you haven't heard before now is that the conference organizers need our
help. As is typical for these events, several gifts will be given away to the
attendees. Names for the prize recipients need to be selected at random.

That's where this quiz comes in.

The LSRC organizers would like us to build name picking applications they can
choose from. The functionality is very basic:

  * Your application needs to accept input as a list of attendees.
    At a minimum, you should accept names, but it might be nice to
    allow for additional details like the attendee's organization.
  
  * Each time your application is run, it should select and display
    a single name from the list. Your application should remember
    previously selected names and not choose them a second time.

The real quiz is how fancy you can make that process. The LSRC organizers are
looking for a lot of sex appeal in their name picker. Solutions that
incorporate the conference name or stars will be given extra consideration. The
goal is something that will have a room full of attendees entranced when run on
the projector. Any interface that meets the above criteria will do.

The conference organizers will recognize the author(s) of any selected
solution(s) at the event (your output can also include a byline), which will
surely lead to unending fame. Fortune may have to follow at a later date.

Questions:

1. Does it *have* to run on a Macintosh? I don't have one to test on!
2. Does it *have* to run on a command line? It's really hard to entrance
a room full of people without *some* eye candy?

How is the list stored/ input? CSV? Or is it undetermined

···

On Jun 23, 2007, at 11:28 PM, Ruby Quiz wrote:

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.rubyquiz.com/

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

As most of you have probably heard, the Lone Star Rubyconf is on the horizon:

  http://lonestarrubyconf.com/

What you haven't heard before now is that the conference organizers need our
help. As is typical for these events, several gifts will be given away to the
attendees. Names for the prize recipients need to be selected at random.

That's where this quiz comes in.

The LSRC organizers would like us to build name picking applications they can
choose from. The functionality is very basic:

  * Your application needs to accept input as a list of attendees.
    At a minimum, you should accept names, but it might be nice to
    allow for additional details like the attendee's organization.

There are two ways to interpret 'run':

1. The app has a Pick button and a new winner is selected each time it is clicked.

2. The app automatically runs each time it is started up and it picks one winner. To pick another, the app is relaunched.

Which behavior is wanted? I ask because remembering previous winners between launches makes the quiz somewhat more difficult. Extra points for the 1st behavior combined with the winner list persistence of the 2nd?

Regards, Morton

···

On Jun 24, 2007, at 12:28 AM, Ruby Quiz wrote:

  * Each time your application is run, it should select and display
    a single name from the list. Your application should remember
    previously selected names and not choose them a second time.

I assume the 48 hour deadline is over. I made a fun little camping
app, however its 300k zipped up (has a couple images). I assume it
would be poor form to post it to the list, but I currently don't have
a publicly facing server where I can put it. What shall I do?

Carl Porth

···

On Jun 23, 9:28 pm, Ruby Quiz <j...@grayproductions.net> wrote:

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.rubyquiz.com/

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=-=

As most of you have probably heard, the Lone Star Rubyconf is on the horizon:

       http://lonestarrubyconf.com/

What you haven't heard before now is that the conference organizers need our
help. As is typical for these events, several gifts will be given away to the
attendees. Names for the prize recipients need to be selected at random.

That's where this quiz comes in.

TheLSRCorganizers would like us to build name picking applications they can
choose from. The functionality is very basic:

        * Your application needs to accept input as a list of attendees.
          At a minimum, you should accept names, but it might be nice to
          allow for additional details like the attendee's organization.

        * Each time your application is run, it should select and display
          a single name from the list. Your application should remember
          previously selected names and not choose them a second time.

The real quiz is how fancy you can make that process. TheLSRCorganizers are
looking for a lot of sex appeal in their name picker. Solutions that
incorporate the conference name or stars will be given extra consideration. The
goal is something that will have a room full of attendees entranced when run on
the projector. Any interface that meets the above criteria will do.

The conference organizers will recognize the author(s) of any selected
solution(s) at the event (your output can also include a byline), which will
surely lead to unending fame. Fortune may have to follow at a later date.

My solution uses SQLite to store a DB of names, and RMagick to display chosen
names. Consider the display part a first draft - I think I'll redo it, maybe
in a completely different way - and submit again later, though the backend
shouldn't change.

There are 4 files that roughly follow MVC:

names_db.rb: Wrapper around a SQLite::Database (M)
pick.rb: Main script (C)
pickerface.rb: Interface stuff (V)
name_image.rb: RMagick stuff (V)

The DB stores just one thing: names. When a name is chosen, its simply deleted.
I thought of marking the names as either picked or unpicked, or storing chosen
names in another table, but I'm not sure if that would be used, and in any
event it would be easy enough to add if needed.

When pick.rb is run without a command option, it either creates a DB and starts
adding names if the DB doesn't exist, or picks and displays a name if it does.
See the top of pick.rb, or run pick.rb --help for a full usage message.

For all text-mode-only operations, names can be Unicode, but RMagick doesn't
seem to like that, so they can't be displayed nicely. Magick::ImageList.animate
is used for displaying, so it won't work for any name on Windows.

I bracket chosen names in stars taken from:

I'm not sure this list will accept messages containing graphics, so you'll
have to fetch this image and place it in the same directory as my code:

http://www.jessemerriman.com/images/ruby_quiz/129_lsrc_name_picker/star_small.png

names_db.rb (2.21 KB)

pickerface.rb (1.95 KB)

pick.rb (2.14 KB)

name_image.rb (2.21 KB)

···

--
Jesse Merriman
jessemerriman@warpmail.net
http://www.jessemerriman.com/

My design goals were:

* What can I do in an hour?
* How can I avoid graphics design, which I suck at?
* How can I minimize (to zero, if possible) gems, add-ons, etc?

My solution is a dead simple WEBrick servlet thingy that poaches the
stylesheet and images from the conference website. It uses a YAML
input file of names and attributes, and an ERB template to display the
result. Every time you reload the page you get a new name.

It keeps track of the names that have been served (saved to a file, so
it survives a restart of the app). I wasn't sure what to do when it
ran out of names, so I'm currently just clearing the save file and
restarting the serving of names (if there are more door prizes than
attendees?).

Here's the app: http://pastie.caboo.se/73618 (save as name_picker.rb)

Here's a sample data file: http://pastie.caboo.se/73619 (save as names.yml)

Run the app: ruby name_picker.rb names.yml

Point your browser to http://localhost:4242/

···

On 6/24/07, Ruby Quiz <james@grayproductions.net> wrote:

The LSRC organizers would like us to build name picking applications they can
choose from. The functionality is very basic:

Hi,

my minimalistic approach uses the main.rb as data storage with the
__END__ keyword. So I don't need any 3rd party libs doing the
persistence stuff for me. I also tried to build a GUI but shattered a
whole day on wxRuby.

Features:
* persitence + test suite
* multiple picks
  > ruby main.rb --pick 2

* eats everything, not just names, just needs TSV with header (see
example.tsv)

* no sql, no extra files
* reads Tab-Separated-Values from stdin or file
  > cat example.tsv | ruby main.rb --list unlucky
  > ruby main.rb --list unlucky --from example.tsv

* ...

What so ever, have a try... :smiley:

Cheers
Florian

lucky_filter.rb (1.94 KB)

main.rb (424 Bytes)

test_suite.rb (4.11 KB)

view.rb (484 Bytes)

controller.rb (1.97 KB)

example.tsv (152 Bytes)

Here is my sollution, using Tk. It is not very fancy, as uses very
basic GUI, but is what I had time for. I will probably make it fancy,
I hope I can get it on time. If someone wants to add some eye'candy,
go on (as long as it credits the original). After all, it's for a good
cause for Ruby ;D.

···

On Jun 23, 11:28 pm, Ruby Quiz <j...@grayproductions.net> wrote:

The three rules of Ruby Quiz:

______________________

#! /usr/bin/ruby

# Ruby Quiz 129 - Name Picker
# Author: Ruben Medellin <chubas7@gmail.com>

require 'csv'

def read_names_csv( filename )
  table = CSV::parse(File.read(filename)) rescue table =
CSV::parse( filename )
  titles = table.shift
  return titles, table
end

def get_name( data_row )
  # Override if the format is different.
  data_row[0..1].join(' ')
end

class TkRoulette

  require 'tk'

  attr_accessor :prizes
  attr_accessor :contestants

  COLORS = [:blue, :red, :green, :orange, :yellow, :pink]

  def initialize( contestants = , prizes = nil )
    @contestants = contestants
    @prizes = prizes
    @winners =
    initialize_gui
    Tk.mainloop
  end

  def initialize_gui
    @root = TkRoot.new {
      title "Ruby Quiz 129 - Name Picker"
    }
    @name = TkLabel.new {
      text 'Press PLAY to start'
      relief :groove
      width 100
      height 10
      font :size => 60, :weight => :bold
      pack :side => :top, :expand => true, :fill => :x
    }
    @play = TkButton.new {
      text 'PLAY!'
      width 100
      height 3
      font :size => 30, :weight => :bold
      pack :side => :bottom, :fill => :x
    }.command method(:play).to_proc
  end

  def play( category = nil )
    if @contestants.empty?
      show_message( "No more contestants" )
      return
    end
    @tick_time = 200
    pick_winner
  end

  def pick_winner
    if @tick_time <= 0
      winner = @contestants.delete_at(rand(@contestants.size))
      @winners << winner
      show_name( "Winner is: " + get_name(winner) + "!!" )
      return
    end
    Tk.after(200 - @tick_time, method(:pick_winner).to_proc )
    @tick_time -= 5
    show_name( get_name( @contestants[rand(@contestants.size)]) )
  end

  def show_name( name )
    @name.fg COLORS[rand(COLORS.size)]
    @name.text name
  end

  def show_message( message )
    @name.fg :black
    @name.text message
  end

end

titles, data = read_names_csv( <<-CSV )
"First name","Last name","Organization","Mail"
"Fred","Flinstone","Slate Rock and Gravel
Company","fred@yabbadabbadoo.com"
"Homer","Simpson","Sprinfield's Nuclear Power Plant","homer@duh.com"
"George","Jetson","Spacely's Space
Sprockets","george@hoobadoobadooba.com"
"Elmer","Food","Acme","elmer@wabbits.com"
CSV
#read_names_csv('attendants.csv')

if __FILE__ == $0
  roulette = TkRoulette.new(data)
end

____________________________________

I tried to submit my solution but the mailing list rejected it as too big (216 KB). What do I do now? Anybody got a suggestion for a work-around?

Regards, Morton

P.S. The reason it's so big is because it has a GUI that uses several of GIF files to do a little animation.

\Questions:

1. Does it *have* to run on a Macintosh? I don't have one to test on!

I don't see any mention of a Macintosh in the quiz description. What moves you to ask this?

2. Does it *have* to run on a command line? It's really hard to entrancea room full of people without *some* eye candy?

You could do some neat stuff with the Curses library -- good change to show off your ASCII art abilities.

I'm not sure I'm going to do this quiz, but if I do, I'll use Ruby/Tk. Should run on any platform and the potential for eye candy would only be limited by my imagination and time available for implementation.

Regards, Morton

···

On Jun 24, 2007, at 12:51 AM, M. Edward (Ed) Borasky wrote:

James,

The Lone Star Ruby Conf looks interesting, particularly yours and Evan Shorts' sessions. Will these be available in some form after the conference? I'd love to be there, but I'm half a world away.

Cheers,
Dave

···

On 24/06/2007, at 2:29 PM, James Edward Gray II wrote:

Sorry the quiz was late this week.

James Edward Gray II

And sorry for violating the Spoiler Period, here comes my solution:

puts "Robert Dober"

Cheers
Robert

···

On 6/24/07, James Edward Gray II <james@grayproductions.net> wrote:

Sorry the quiz was late this week.

James Edward Gray II

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Questions:

1. Does it *have* to run on a Macintosh? I don't have one to test on!

I would think it's always an advantage to have your program run on as many platforms as possible.

2. Does it *have* to run on a command line? It's really hard to entrance
a room full of people without *some* eye candy?

Not at all. As the quiz mentions, any interface will do.

James Edward Gray II

···

On Jun 23, 2007, at 11:51 PM, M. Edward (Ed) Borasky wrote:

You can determine a suitable input format. Just make it easy to produce and document what you need, please.

James Edward Gray II

···

On Jun 24, 2007, at 9:53 AM, John Joyce wrote:

  * Your application needs to accept input as a list of attendees.
    At a minimum, you should accept names, but it might be nice to
    allow for additional details like the attendee's organization.
  
How is the list stored/ input? CSV? Or is it undetermined

Those of you following along closely have probably noticed that Ruby Quiz launches have been pretty problematic these last couple of weeks. The reason is that a bug in Ruby 1.8.6-p36 had crippled the Ruby Quiz software and launches were pretty much happening by hand. That wasn't working out well.

I've upgraded to the head of the Ruby 1.8 branch this morning and the problem seems to be resolved. So hopefully, things will improve in the coming weeks.

It's my fault this week's quiz was two days late, so it will run for an extra week to give people the time they need.

Sorry for the inconveniences.

James Edward Gray II

···

On Jun 23, 2007, at 11:29 PM, James Edward Gray II wrote:

Sorry the quiz was late this week.

I meant each time your application is started (#2). I can see where #1 might be attractive for something like a web application, but I have a hard time imagining that the program will run non-stop for two days.

James Edward Gray II

···

On Jun 24, 2007, at 12:40 PM, Morton Goldberg wrote:

On Jun 24, 2007, at 12:28 AM, Ruby Quiz wrote:

  * Each time your application is run, it should select and display
    a single name from the list. Your application should remember
    previously selected names and not choose them a second time.

There are two ways to interpret 'run':

1. The app has a Pick button and a new winner is selected each time it is clicked.

2. The app automatically runs each time it is started up and it picks one winner. To pick another, the app is relaunched.

Which behavior is wanted?

Honestly I am rude Morton, because I am jealous ;). I have read your
recent quiz submissions, they are lightyears above my level, what are
you asking here?
Just solve the problem :wink:

Seriously now:
I read the Quiz in a way that winner persistence is explicitly asked
for and I really like this part.

Cheers
Robert

···

On 6/24/07, Morton Goldberg <m_goldberg@ameritech.net> wrote:

1. The app has a Pick button and a new winner is selected each time
it is clicked.

2. The app automatically runs each time it is started up and it picks
one winner. To pick another, the app is relaunched.

Which behavior is wanted? I ask because remembering previous winners
between launches makes the quiz somewhat more difficult. Extra points
for the 1st behavior combined with the winner list persistence of the
2nd?

Regards, Morton

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

You may email it to me off-list and I'll host it for you.

James Edward Gray II

···

On Jun 26, 2007, at 3:40 AM, Carl Porth wrote:

I assume the 48 hour deadline is over. I made a fun little camping
app, however its 300k zipped up (has a couple images). I assume it
would be poor form to post it to the list, but I currently don't have
a publicly facing server where I can put it. What shall I do?