Skip to content

Instantly share code, notes, and snippets.

@pfiller
Created February 6, 2012 16:51
Show Gist options
  • Save pfiller/1753255 to your computer and use it in GitHub Desktop.
Save pfiller/1753255 to your computer and use it in GitHub Desktop.
SuperGrid Filler
class fill_out_grid
constructor: (people_list, @target_el) ->
people_list += ", #{people_list}"
@people = people_list.split(", ")
@table = ""
this.shuffle()
data = this.table_data()
@target_el.find("tbody").html(data.join(""))
#shuffle up the names using Fisher–Yates, yo
shuffle: ->
times = @people.length
while times
i = Math.floor(Math.random() * times--);
temp = @people[times]
@people[times] = @people[i]
@people[i] = temp
table_data: ->
rows = for row in [0..10]
columns = for col in [0..10]
this.build_cell(row,col)
"<tr>#{columns.join("")}</tr>"
build_cell: (row,col) ->
if row is 0
this.first_row_cell(col)
else
if col is 0
"<th>#{row}</th>"
else
"<td>#{@people.pop()}</td>"
first_row_cell: (col) ->
if col > 0
"<th>#{col}</th>"
else
"<th>&nbsp;</th>"
harvest_people = "Karen, Karen, TJ's Homeschool, TJ's Homeschool, TJ's Homeschool, Harvest Systems Team Beer Fund LLC, Harvest Systems Team Beer Fund LLC, Harvest Systems Team Beer Fund LLC, Patrick, Eileen Filler, Patrick, Kristy, Kristy, Lettini, Lettini, Lettini, Uncle Christopher, Uncle Christopher, Uncle Christopher, Uncle Christopher, Uncle Christopher, Jae, Jae, Jae, Jae, Jae, Sarah, Sarah, Rhymes With Tree, Kim, Kim, Danny, Danny, Danny, Danny, Dear Leader, Dear Leader, Sammy, Sammy, Naama, Naama, Naama, Naama, Kyle Filler, Kyle Filler, Kyle Filler, Kyle Filler, Jay Filler, Eileen Filler, Jay Filler"
jQuery ->
grid = new fill_out_grid(harvest_people, $("#supergrid"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment