- 1
- 2
- 3
- 4
def a
print rand(1)
end
puts a
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−113
def a
print rand(1)
end
puts a
Попытался нагадить… короче, puts puts 0
−99
case klass
when "Subject"
case attr.to_sym
when :screening_num then :screening_num
when :subject_num then :subject_num
end
end
это чО на всякий пожарный чтоли ?
обратите внимание что klass это объект ActiveRecord а проверяется как стринг
писал русский паренёк Дима ) а вы говорите индусы )
−99
begin
# etc
rescue Exception => e
case e
when LinkedIn::Unauthorized
account.invalidate_token if !account.invalid_token?
raise InvalidTokenException.new(account.primary, provider_name)
when LinkedIn::InformLinkedIn, LinkedIn::Unavailable #LinkedIn::Unavailable represents 502..503 error codes & LinkedIn::InformLinkedIn represent 500
raise UnexpectedApiException.new(provider_name)
else
handle_api_exception(e, e.message)
end
end
элегантный отлов ексепшнов
−95
loop do
client = server.accept
otvet = []
while line = client.gets
otvet << line
break if line == "\r\n"
end
client.print "HTTP/1.1 200/OK\n"
client.print "Content-type: text/html\n\n"
client.print '"<meta http-equiv="refresh" content="0; url=http://www.google.ru">"' # переадресация
client.close
puts otvet
File.open('log.txt', 'a'){ |f| f.puts("#{otvet}")} # запись лога
end
творние юного кулхацкера
−104
def entities(model, params = {})
@entities ||= {}
@entities[model] ||= []
if @entities[model].blank? or parameters_changed?(model, params)
@entities[model] = []
include = params[:include] || nil
group = params[:group] || nil
order = params[:order] || nil
page = params[:page] || nil
entity_ids = []
model_role = nil
model_class = model.to_s.classify.constantize
if self.has_role_for?(model_class)
self.roles_for(model_class).uniq.each do |role|
if role.authorizable_id.blank?
raise "Authorization problem! Found more than one #{model_class} model permission!" unless model_role.blank?
model_role = role.name
next
end
if !role.authorizable_id.blank? && MerchantRole::MERCHANT_ROLES.include?(role.name)
entity_ids << role.authorizable.id
end
end
if entity_ids.blank? and MerchantRole::MERCHANT_ROLES.include?(model_role)
#WARNING! RECURSION! EVIL!
if MerchantRole.has_entity_parent?(model)
parent_model = MerchantRole.entity_parent(model)
parent_entities = self.entities(parent_model)
unless parent_entities.blank?
_params = {
:conditions => conditions_and_parameters(params, nil, ["`#{model.to_s}`.`#{parent_model.to_s.singularize}_id` IN (?)", parent_entities.map(&:id)]),
:include => include,
:order => order,
:group => group
}
_params.merge!(:page => page) if params.keys.include?(:page)
if block_given?
(self.is_reseller? ? self.reseller.send(model) : model_class).each(_params) do |o|
yield o
end
else
@entities[model] = (self.is_reseller? ? self.reseller.send(model) : model_class).send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
end
end
else
_params = {
:conditions => conditions_and_parameters(params, nil),
:include => include,
:order => order,
:group => group
}
_params.merge!(:page => page) if params.keys.include?(:page)
if block_given? #Find only merchants associated with the reseller or all merchants if we are no reseller.
(self.is_reseller? ? self.reseller.send(model) : model_class).each(_params) do |o|
yield o
end
else
@entities[model] = (self.is_reseller? ? self.reseller.send(model) : model_class).send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
end
end
else
_params = { :conditions => conditions_and_parameters(params, nil, ["`#{model.to_s}`.`id` IN (?)", entity_ids]),
:include => include,
:order => order,
:group => group }
_params.merge!(:page => page) if params.keys.include?(:page)
if block_given?
model_class.each(_params) do |o|
yield o
end
else
@entities[model] = model_class.send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
end
end
end
end
entities[@model]
end
This method does the following (you guessed it, right?):
#Fetch entities for which we have a read permission.
#This is now it should work:
#1. : If we don't have any role on the model, we won't get anything.
#2a.: Check roles we have for whole model. If no role for whole model we can only fetch instances we have assigned.
#2b.: Check all instances we have a role for and store them.
#3a.: We have roles for instances -> Goto(#7)
#3b.: We have no instance roles but have a role for the whole model.
#4. : Check recusively if we have roles fro a parent model (channels -> merchants).
#5a.: If we have a parent role and got parent entities returned we only fetch instances belonging to the parent entities.
#6a.: If we have a parent role and got no entities back, then we won't get anything since we are not supposed to.
#7. : Get all instances based on our reseller or globally for the system.
−95
session[:mark == md5(Time.now)]
это печально
−96
module AuthenticatedSystem
protected
def logged_in?
!!current_user
end
def current_user
@current_user ||= login_from_session unless @current_user == false
@current_user
end
−98
amount = ('-' + batch['settleAmount'].to_s).to_i
работа с платежными системами требует вдумчивости и оригинальности.
−104
@hands_by_value.each do |hand|
if @hands_by_value.slice(@hands_by_value.index(hand)+1..@hands_by_value.index(@hands_by_value.last)).include?(hand)
@hands_by_value.delete_at(@hands_by_value.index(hand))
end
end
Рукотворный array.uniq! похоже :)
−93
def self.enddayofmonth(year,month)
stdyear=[31,28,31,30,31,30,31,31,30,31,30,31]
visyear=[31,29,31,30,31,30,31,31,30,31,30,31]
if year%4>0
return stdyear[month-1]
else
return visyear[month-1]
end
end