- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
class SomeModel < ActiveRecord::Base
after_save :some_method
def some_method
self.save
end
end
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−157
class SomeModel < ActiveRecord::Base
after_save :some_method
def some_method
self.save
end
end
Рекурсивная рекурсия рекурсивна.
+57
function GetOrderSkidka(&$arrData)
{
if($this->flag_opt){
$arrData['skidka'] = ($this->admin_mode) ? $arrData['skidka'] : 0;
$arrData['allsum'] = $arrData['sum'] - $arrData['skidka'];
return;
}
if(!$this->flag_in_action){
$arrData['cnt_s_prod'] = $arrData['cnt'];
}elseif(in_array($this->flag_action_type,array(2,3))){
$this->calcCntProd($arrData);
}else{
$arrData['cnt_s_prod'] = 0;
}
$this->discount->GetOrderSkidka($arrData);
}
Работаю с сайтом, в котором все методы классов работают со своими параметрами таким образом.
Метод может ничего не возвращать, а вызывать другие методы (которые также могут вызывать какие-то методы),
которые в зависимости от множества условий меняют переданные по ссылке параметры.
Итог работы модифицированный параметр- массив. Только XDebug выручает.
+121
try {
repository.saveAll(entities);
} catch (final ConstraintViolationException e) {
throw new SettingsServiceException(ErrorFormatter.formatValidationErrors(
"Errors have been detected when saving", e));
} catch (final PersistenceException e) {
for (val t: Throwables.getCausalChain(e)) {
if (t instanceof EntityExistsException) {
val failedObject = (IEntity) ((ExceptionInfo) t).getFailedObject();
// failedObject is returned with the state in which it is in the database.
// Let's find the version that we tried to save, instead.
for (val entity: entities) {
if (entity.getId() != null && entity.getId().equals(failedObject.getId())) {
throw new SettingsServiceException("Attempted to save duplicate value: " + entity);
}
}
}
}
throw e;
}
Попытка вернуть пользователю человеко-читаемое сообщение о том, где, собственно, дубликат.
Костыли вы мои, костыли...
+54
<?php
class SimpleController extends Zend_Controller_Action
{
public function init()
{
$action = $this->_request->getActionName();
$is_action_available = in_array($action, explode(',', 'terms,privacy,about,copyright,support,legal,features,help,refund'));
$is_incorrect_action = CR_Settings::siteIsFree() && $action == 'refund';
if (!$is_action_available || $is_incorrect_action)
$this->_helper->redirector->setGotoRoute(array('action' => 'index'), 'default', true);
}
public function termsAction(){
}
public function privacyAction(){
}
public function aboutAction(){
}
public function copyrightAction(){
}
public function supportAction(){
}
public function legalAction(){
}
public function featuresAction(){
}
public function helpAction(){
}
public function refundAction(){
}
}
Zend Framework проверка на существование action :)
+26
result.push_back(TVector<2>
(
(A-√(D))/C,
(E-Line.K()*√(D))/C
));
result.push_back(TVector<2>
(
(A+√(D))/C,
(E+Line.K()*√(D))/C
));
+131
if (http_status_code == 200 || http_status_code == 500) {
.... //success!!
} else {
.... // error!!
}
Было замечено в одном андроид приложении.
+141
var number = new Random();
if (number.Next(10)%2 == 0)
{...}
else
{...}
Нашёл такой шедевр в индокоде, которые мне дали модернизировать.
+57
function SetImage($row=array())
{
foreach($row as $property=>$value)
{
eval("\$this->".$property." = '".$value."';");
}
}
+107
if (_appliesTo.Contains("CH"))
{
depElig &= true;
}
else
{
depElig &= false;
}
Вроде такого boolshit тут ещё не было.
+153
var num_normalize = function (num) {
if (typeof num == 'string') {
if (num.test('.')) {
return parseFloat(num).toFixed(2);
}
else {
return parseInt(num);
}
}
else if (parseInt(num) == parseFloat(num)) {
return parseInt(num);
}
else return parseFloat(num).toFixed(2);
};
Привод стринги в numeric, проблема была в том что приходила значение в string, но могло быть с точками. естественно parseInt не годится и parseFloat тоже, ибо число не красивое визуально