- 1
- 2
- 3
def route_match? origin, destination
origin.iata == origin and destination.iata == destination
end
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−102
def route_match? origin, destination
origin.iata == origin and destination.iata == destination
end
В классе конечно определены методы origin и destination
−100
File.basename(File.basename(name, '.jpg'), '.png')
Файл либо с расширением .png, либо .jpg
−107
require File.expand_path(File.dirname(__FILE__) + '/../../../../../../usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/sqlite3_adapter.rb')
−97
hash.to_a.select{|elem| elem[1].map{|st| st.from}.include? state}.map{|elem| elem[1].map{|inner| inner.to}.uniq}.flatten
−106
Dir["#{Rails.root}/lib/**/*"].select { |f| File.directory? f }.join(' ')
Рекурсивный список каталогов lib проекта Rails.
−99
Было (плохо):
<% @collection.each_with_index do |item, counter| -%>
<%= "<div class='group'>" if ((counter)/items_in_block).to_i*items_in_block == (counter) %>
<%= render :partial => 'item', :locals => { :item => item} %>
<%= "</div>" if (counter > 0 and (((counter+1)/items_in_block).to_i*items_in_block == (counter+1)) or ((counter+1) == @collection.size)) %>
<% end -%>
Стало (чуть лучше ;):
<% @collection.in_groups_of(items_in_block).each do |items| %>
<div class="group">
<% items.each do |item| %>
<%= render :partial => 'item', :locals => { :item => item} %>
<% end %>
</div>
<% end %>
Группировка элементов в группы div'ов.
−106
# progress bar
width = 60 # width of bar
com = 540 # input data
pr = com * 0.01
i = 0
j = width
v = 1
puts
while pr <= com
print "\r#{v}% [#{"|"*i}#{" "*j}]"
pr += com * 0.01
i += width * 0.01
j -= width * 0.01
v += 1
sleep(0.01)
end
puts
Консольный прогресс-бар.
−104
def query(sql)
begin
@mysql.query(sql)
rescue StandardError => err
@log.error("Mysql query: '#{sql}\n#{err}'") if @log.class == LoggerHandler
end
end
Говнообертка. LoggerHandler - класс, наследующийся от Logger.
Говнонюанс в том, что Logger.error возвращает true/false в зависимости от того была ли запись в лог успешной, что приводит потом к ошибкам вида NoMethodError: undefined method `each' for true:TrueClass
−100
N = 5
$mas = (1..N).to_a
$c = 0
def generate(l = 0)
if l == N-1
for i in 0..N-1 do
print("#{$mas[i]} ")
end
$c += 1; print("\n")
else
for i in l..N-1 do
t = $mas[l]; $mas[l] = $mas[i]; $mas[i] = t;
generate(l+1)
t = $mas[l]; $mas[l] = $mas[i]; $mas[i] = t;
end
end
return $c
end
p generate(0);
−110
require "date"
#Конвертируем массив цифр в двухмерный масив для отображения
def get_numbers(numbers)
output = []
one = [["-","-","-","*","*"],["-","-","*","-","*"],["-","*","-","-","*"],["*","-","-","-","*"],["-","-","-","-","*"],["-","-","-","-","*"],["-","-","-","-","*"]]
two = [["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","-","*"],["*","*","*","*","*"],["*","-","-","-","-"],["*","-","-","-","-"],["*","*","*","*","*"]]
three = [["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","-","*"],["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","-","*"],["*","*","*","*","*"]]
four = [["*","-","-","-","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","-","*"],["-","-","-","-","*"]]
five = [["*","*","*","*","*"],["*","-","-","-","-"],["*","-","-","-","-"],["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","-","*"],["*","*","*","*","*"]]
six = [["*","*","*","*","*"],["*","-","-","-","-"],["*","-","-","-","-"],["*","*","*","*","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","*","*","*","*"]]
seven = [["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","*","-"],["-","-","*","-","-"],["-","*","-","-","-"],["*","-","-","-","-"],["*","-","-","-","-"]]
eight = [["*","*","*","*","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","*","*","*","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","*","*","*","*"]]
nine = [["*","*","*","*","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","-","*"],["*","*","*","*","*"]]
zero = [["*","*","*","*","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","*","*","*","*"]]
seperator = [["-","-","-","-","-"],["-","*","-","*","-"],["-","-","-","-","-"],["-","-","-","-","-"],["-","-","-","-","-"],["-","*","-","*","-"],["-","-","-","-","-"]]
for i in numbers
case i
when "0"
output += [zero]
when "1"
output += [one]
when "2"
output += [two]
when "3"
output += [three]
when "4"
output += [four]
when "5"
output += [five]
when "6"
output += [six]
when "7"
output += [seven]
when "8"
output += [eight]
when "9"
output += [nine]
when ":"
output += [seperator]
end
end
return output
end
#Получаем массив с текущим временем
def get_time
t = Time.new
if t.hour.between?(0,9)
hour = "0" + t.hour.to_s
else
hour = t.hour.to_s
end
if t.min.between?(0,9)
min = "0" + t.min.to_s
else
min = t.min.to_s
end
if t.sec.between?(0,9)
sec = "0" + t.sec.to_s
else
sec = t.sec.to_s
end
time = [hour[0],hour[1],":",min[0],min[1],":",sec[0],sec[1]]
end
#Рисуем с заменой символов на в
def display_time(symbols = {:star => "0", :line => " "})
color_taf = 0
color_tab = 7
loop do
#Для очитки экрана в UNIX
if RUBY_PLATFORM == "i386-mingw32" then
system("cls")
else
system("tput reset")
end
#Цвет и фон
#system("tput setaf #{color_taf}")
#system("tput setab #{color_tab}")
m = get_numbers(get_time)
#Посимвольная прорисовка
for j in 0..6
for i in 0..m.size-1
for z in m[i][j]
case z
when "*"
print symbols[:star]
when "-"
print symbols[:line]
#sleep(0.01) Для просмотра прорисовки
end
end
print " "
end
print "\n"
end
sleep(1)
end
end
#Рисуем
display_time :star => "0", :line => " "
Фух... урезал до 100 строк :)