Last active
August 1, 2016 09:53
-
-
Save pabletecodes/abcd5ded29dea9153c9d to your computer and use it in GitHub Desktop.
Burrito Model Awards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require 'io/console' | |
require 'debugger' | |
require 'pygments' | |
def winsize | |
$stdout.winsize | |
end | |
def clear_screen | |
puts "\e[2J\e[H" | |
end | |
def cursor_at(row, col) | |
"\e[#{row};#{col}H" | |
end | |
def print_title | |
clear_screen | |
title = <<-eos | |
......:::~~~~.,,... . | |
..,==~=+==7?+?7+I??+7$?7=~::,.. | |
...~~~=~==????7+II??=??:+$+II+++=:::::.. | |
...,+++=====+~~=~===~~=I+:+=:~77?~,::I$$7$I+===?+???,::... | |
..==~==~=~~=~:~+?:~=:=~:,:~I=:,,::::,.Z$::=+O7:,,.I+==II++~:. | |
.=~=~~~~~~~~~~~?::~::,:~:,~~:,:~:,,+:I8DO$OZOOZ.=?=II+=OZ7+7?=:. | |
..,~~~~~::+:~~:~,~~::~:I+I?~I,ZZ7+=:,..+7$$ZZ88O777Z:,Z77+$OOZ7$$77~.. | |
..+~::=:::::~:~+=~:~,::,?+Z$O$OOOO$Z=,,7I$OZZO88Z$OZ,,:~$7IIZZI$::$?~,.. | |
.~~~~:~:::::~:?7:~:~:~~,::=OOO88888O$$ZOZ$=?IOD8OOOOON:~?7O$=88+=,:+7ZZZ, | |
..~~::::,,:::~+:~:::~::,::::?Z88O7,:$OOZO88=,?I7I$$$$O8NDZZOZZZ=.~.$=$ZZZ+~. | |
..~:::,,,:,,,?:,::::::,,:,,==ZODZI??,:OO$$I=+7I+=Z8$$O?+?$OZ7??Z7?++OOZ$OZ==:. | |
.:,::~,:,::?,,,:::::,,:,::+7?O777???+?:7II?8=+Z$I8O+=7$8??77~~$7:~=:O88Z+=~~~. | |
..::~:,,:=,,,,,:,,,,::,:~:Z+?II77$+I+??I+7?=~~?++$ZI7$$=77=++=++==,Z=8O8$Z:~+, | |
.:~,:::,=:,,,,=::,,:~:,:~:ZOZ$+$I?I+=?~~?=$++=:7?=??7I:$?I?I??I$I,?$?I+7I=+?==.. | |
.:~,,,:,,=,,,,=~,,,,~,,:~:$O$7++Z,~7=~++::~$O~=+7?++7$=,7+7~777Z$,$ZZO?$Z$$Z7?7. | |
::~,,:,,,~,,,,=:,,,,:::~~~+OZZ$+7:I$D7$~Z$,I~$?+=+7$7$$+:==$$~OOZ~ZZ~?IZZ+?ZZZ?. | |
::::,,:,,:,,,,~,:,,::~::~~~8O8OZO?++8DZ$$ZZZO$8O?=$$$$7O,O???+IZO8$$O+8I?~?78Z=. | |
~::::,:::::::,~::::,:~~==~+?8OZD8+88$I$ZZZZOOZDZ7Z$$$+O8$,$OZ$$7OZZZ?8$8I?:8O?.. | |
,=::::::::::~~~=::::::~=~~==OOOD$~7ZDDZOOO8O7$88D8O7$OZ$Z888DZZZII7ZOMZI$ZO:?Z | |
.===~:::~~~~~=~~=~~~~~~=+=~=,D$$7~DOZO$Z$+$$ZZOOIZOD8D8OI?88OZO7Z77?ZIO$7I??7~ | |
.+=~~~=============+~~=+==~=.Z7I?7?ZDO?O7Z$ZZ$7ZNZ$$7777IID$$87?7$$7I7$?7O77. | |
?+==?+==?+====+====~++=7===.I$$I$7$OI?Z$Z?I:?$O$$$7$Z7I7Z7IZZ+=?$7ZI+?Z??$. | |
.~???I+?++=++++++++=+++7+++=,7$7I7IIZ7?77$$I77III7III?7$$Z$I7+?777II?777. | |
. ....:=?7777I???II???++????+++=7$7$$77I77$$$$77I$$$7$$IIIOZ$7Z7$O7777?.. | |
.....,,:==+I7$+,......,.....,,,,::=?77III?++=~:,.... | |
BBBBB UU UU RRRRRR RRRRRR IIIII TTTTTTT OOOOO MM MM OOOOO DDDDD EEEEEEE LL | |
BB B UU UU RR RR RR RR III TTT OO OO MMM MMM OO OO DD DD EE LL | |
BBBBBB UU UU RRRRRR RRRRRR III TTT OO OO MM MM MM OO OO DD DD EEEEE LL | |
BB BB UU UU RR RR RR RR III TTT OO OO MM MM OO OO DD DD EE LL | |
BBBBBB UUUUU RR RR RR RR IIIII TTT OOOO0 MM MM OOOO0 DDDDDD EEEEEEE LLLLLLL | |
AAA WW WW AAA RRRRRR DDDDD SSSSS | |
AAAAA WW WW AAAAA RR RR DD DD SS | |
AA AA WW W WW AA AA RRRRRR DD DD SSSSS | |
AAAAAAA WW WWW WW AAAAAAA RR RR DD DD SS | |
AA AA WW WW AA AA RR RR DDDDDD SSSSS | |
eos | |
lines = title.split("\n") | |
width = winsize.last | |
lines.each do |line| | |
print line.center(width) + "\n" | |
end | |
$stdin.getch | |
end | |
def print_slide(text) | |
clear_screen | |
height, width = *winsize | |
print cursor_at(height/2, 1) + text.center(width) | |
$stdin.getch | |
end | |
def print_result(text) | |
clear_screen | |
height, width = *winsize | |
number_of_lines = text.split("\n").size | |
current_line = height/2 - number_of_lines/2 | |
text.split("\n").each do |line| | |
print cursor_at(current_line, 30) + line | |
current_line += 1 | |
end | |
$stdin.getch | |
end | |
def print_winner(filename) | |
clear_screen | |
code = File.read(filename) | |
new_code = Pygments.highlight(code, formatter: 'bbcode', lexer: 'ruby') | |
new_code.split("\n").each do |line| | |
puts line | |
sleep 0.08 | |
end | |
end | |
def print_credits | |
clear_screen | |
text = "CREDITS" | |
text << "\n=======" | |
text << "\n\nExecutive producer:" | |
text << "\n\n - Pablo Alonso" | |
text << "\n\nProgramming:" | |
text << "\n\n - Roger Jungemann" | |
text << "\n\n - Pablo Alonso" | |
text << "\n\nMusic idea:" | |
text << "\n\n - Mark Scholtz" | |
print_result(text) | |
end | |
def print_nominees | |
text = "NOMINEES" | |
text << "\n========" | |
projects.each do |project| | |
project_name = project.split('/').last | |
text << "\n - #{project_name}" | |
end | |
print_result(text) | |
end | |
WILDFIRE_PROJECTS_DIR = '/Users/pabloalonso/wildfire/' | |
def projects | |
Dir["#{WILDFIRE_PROJECTS_DIR}/*"].select do |file| | |
File.directory?(file) | |
end | |
end | |
def models(project) | |
models_folder = File.join(project, 'app/models') | |
return [] unless File.exists?(models_folder) | |
Dir[File.join(models_folder, '**/*')].select do |file| | |
File.extname(file) == '.rb' | |
end | |
end | |
def number_of_lines(filename) | |
IO.readlines(filename).size | |
end | |
print_title | |
print_credits | |
print_slide("What project has the FATTEST model?") | |
print_nominees | |
print_slide "Are you guys ready?" | |
projects_with_models = {} | |
projects.each do |project| | |
models_with_lines = {} | |
max_numer_of_lines = 0 | |
if (models = models(project)).any? | |
models.each do |model| | |
number_of_lines = number_of_lines(model) | |
models_with_lines[model] = number_of_lines | |
max_numer_of_lines = number_of_lines if number_of_lines > max_numer_of_lines | |
end | |
end | |
projects_with_models[project] = [max_numer_of_lines, models_with_lines] | |
end | |
places = [ | |
'And as a WINNER, in 1st place', | |
'Secondly, in 2nd place', | |
'In 3rd place' | |
].reverse | |
projects_with_models_sorted_by_fattest_models = projects_with_models.sort_by{|project, wadus| wadus[0]}.reverse[0..2] | |
projects_with_models_sorted_by_fattest_models.reverse.each_with_index do |items, i| | |
project, wadus = *items | |
max_numer_of_lines = wadus[0] | |
models_with_lines = wadus[1] | |
project_name = project.split('/').last | |
print_slide "#{places[i]} we have..." | |
text = "#{project_name}" | |
text << "\n" | |
text << "=" * project_name.length | |
text << "\n" | |
if max_numer_of_lines > 0 | |
models_with_lines.sort_by {|model, number_of_lines| number_of_lines}.reverse[0..2].each do |model_with_lines| | |
model_name = model_with_lines[0] | |
number_of_lines = model_with_lines[1] | |
model_path = model_name.gsub("#{WILDFIRE_PROJECTS_DIR}/#{project_name}/", '') | |
text << "\n#{model_path} ===> #{number_of_lines} Lines of code" | |
end | |
end | |
print_result(text) | |
end | |
pair = projects_with_models_sorted_by_fattest_models.first.last.sort_by {|model, number_of_lines| number_of_lines}.reverse[0..2] | |
line_count = pair.last | |
biggest_model = nil | |
pair.first.each do |path, count| | |
biggest_model = path if line_count == count | |
end | |
print_slide("#{number_of_lines(biggest_model)} LINES OF CODE!") | |
print_slide "Let's see this PUPPY..." | |
print_winner biggest_model | |
print_credits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment