- 1
return payments.isEmpty() ? create ? store ? addPayment(serviceProvider) : createPayment(serviceProvider) : null : payments.iterator().next();
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+80
return payments.isEmpty() ? create ? store ? addPayment(serviceProvider) : createPayment(serviceProvider) : null : payments.iterator().next();
экономим на строчках
+130
;Дисассемблировано "Doctor Watson" для Windows Server 2003 R2 x64
00000000`004d3f4b 2448 and al,0x48
00000000`004d3f4d 488b742440 mov rsi,[rsp+0x40]
00000000`004d3f52 418b4008 mov eax,[r8+0x8]
00000000`004d3f56 4c8b642420 mov r12,[rsp+0x20]
00000000`004d3f5b 488b5c2430 mov rbx,[rsp+0x30]
00000000`004d3f60 ffc8 dec eax
00000000`004d3f62 498d54c00c lea rdx,[r8+rax*8+0xc]
00000000`004d3f67 666690 nop
00000000`004d3f6a 666690 nop
00000000`004d3f6d 666690 nop
FAULT ->00000000`004d3f70 0fb74202 movzx eax,word ptr [rdx+0x2] ds:00000008`01511086=????
00000000`004d3f74 443bc8 cmp r9d,eax
00000000`004d3f77 440f42c8 cmovb r9d,eax
00000000`004d3f7b 66837a0400 cmp word ptr [rdx+0x4],0x0
00000000`004d3f80 7415 jz bma+0xd3f97 (00000000004d3f97)
00000000`004d3f82 488d0cc500000000 lea rcx,[00000000+rax*8]
00000000`004d3f8a 488d0449 lea rax,[rcx+rcx*2]
00000000`004d3f8e 0f181442 prefetcht1 byte ptr [rdx+rax*2]
00000000`004d3f92 4803d1 add rdx,rcx
00000000`004d3f95 ebd9 jmp bma+0xd3f70 (00000000004d3f70)
00000000`004d3f97 488bc5 mov rax,rbp
HP Data Protection Manager 6.10, Windows x86-64, NDMP Media Agent. С первым патчем (не помню номер). Падал с Access Violation.
Явно ошибка в компиляторе. Если что, в rax в этот момент было 0x00000000ffffffff.
+160
class Claims
{
...
function ReadClaim(...)
{
...
if ($this) $this->claim = $claim;
$instance = $this ? $this : Claims::getInstance($claim);
...
}
...
}
+157
function __autoload($class)
{
global $CONFIG;
if (in_array($class,array('CorpNews','User','Passengers'))) include $CONFIG[site_dir].'common/scripts/classes/common/'.$class.'.php';
elseif (in_array($class,array('Claims','ClaimsAviaUser','ClaimsUser'))) include $CONFIG[site_dir].'common/scripts/classes/claims/'.$class.'.php';
elseif (in_array($class,array('OperatorClaim','UsersCommon'))) include $CONFIG[site_dir].'common/scripts/classes/users/'.$class.'.php';
elseif (strpos($class, 'Avia') === 0) include $CONFIG[site_dir].'common/scripts/classes/avia/'.$class.'.php';
elseif (strpos($class, 'Railway') === 0) include $CONFIG[site_dir].'common/scripts/classes/railway/'.$class.'.php';
}
+56
std::map<int, int> aSummator; //Массив частичных сумм
std::vector<int> v; //Исходный массив
void InitSummator()
{
aSummator[0] = v[0];
aSummator[-1] = 0;
for(int i = 1; i < int(v.size()); i++)
{
aSummator[i] = aSummator[i - 1] + v[i];
}
}
int GetSum(int l, int r)
{
return aSummator[r] - aSummator[l - 1];
}
Как я писал сумматор 0.1 года назад. Вместо того, чтобы написать один if, я использовал std::map, что увеличило ассимптотику алгоритма на запрос с O(1) до O(log(n)). Но задачу при тех ограничениях (в массиве до 100000 элементов, запросов не более 100000) алгоритм решил. Преподу, естественно, показывать забоялся.
−118
name = name.replace(u'c', u'с') # this is magia
+839
protected virtual string GetParentTableControlID()
{
try
{
if (this.Parent is BaseApplicationTableControl) return this.Parent.ID;
if (this.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.ID;
if (this.Parent.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.Parent.ID;
if (this.Parent.Parent.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.Parent.Parent.ID;
}
catch (Exception)
{
}
return "";
}
+57
#include <iostream>
#include <stdexcept>
template<std::size_t N>
static int constexpr date_component(const char (&s)[N], int i, bool last, int max) {
return
(i + 2 + (last ? 0 : 1) >= N)
? throw std::logic_error("Too short date string") :
(!last && s[i + 2] != ':')
? throw std::logic_error("Cannot find delimiter") :
(s[i] < '0' || s[i] > '9' || s[i + 1] < '0' || s[i + 1] > '9')
? throw std::logic_error("Not a number") :
((s[i] - '0') * 10 + (s[i + 1] - '0') > max)
? throw std::logic_error("Too large number") :
(s[i] - '0') * 10 + (s[i + 1] - '0');
}
struct time {
int hour; int minute; int second;
template<std::size_t N>
constexpr time(const char (&datestr)[N]) :
hour(date_component(datestr, 0, false, 24)),
minute(date_component(datestr, 3, false, 60)),
second(date_component(datestr, 6, true, 60))
{}
};
struct time constexpr midnight("00:00:00");
struct time constexpr afternoon("12:00:00");
int main(int argc, char* argv[]) {
std::cout << "Midnight hour is " << midnight.hour << std::endl;
std::cout << "Afternoon hour is " << afternoon.hour << std::endl;
}
C++ и даты времени компиляции
+152
// Наткнулся в коде на
try
{
throw new Provider_Exception($curl_error);
}
catch (Exception $e)
{
throw new Provider_Exception('No connection');
}
// и отрефакторил
try
{
throw new Provider_Exception($curl_error);
}
catch (Exception $e)
{
throw new Provider_Exception($e->getMessage());
}
PROFIT!
+157
<select multiple name="fields[]">
<option value="idblank" <?php echo in_array("idblank", $book_fields)?"selected":""; ?> >idblank</option>
<option value="n_dog" <?php echo in_array("n_dog", $book_fields)?"selected":""; ?> >n_dog</option>
<option value="n_failpay" <?php echo in_array("n_failpay", $book_fields)?"selected":""; ?> >n_failpay</option>
<option value="senior" <?php echo in_array("senior", $book_fields)?"selected":""; ?> >senior</option>
<option value="fio" <?php echo in_array("fio", $book_fields)?"selected":""; ?> >fio</option>
<option value="date_init" <?php echo in_array("date_init", $book_fields)?"selected":""; ?> >date_init</option>
<option value="fio_client" <?php echo in_array("fio_client", $book_fields)?"selected":""; ?>>fio_client</option>
<option value="date_plat" <?php echo in_array("date_plat", $book_fields)?"selected":""; ?>>date_plat</option>
<option value="pros_total" <?php echo in_array("pros_total", $book_fields)?"selected":""; ?>>pros_total</option>
<option value="summa_post" <?php echo in_array("summa_post", $book_fields)?"selected":""; ?>>summa_post</option>
<option value="ostatok" <?php echo in_array("ostatok", $book_fields)?"selected":""; ?>>ostatok</option>
<option value="effect" <?php echo in_array("effect", $book_fields)?"selected":""; ?>>effect</option>
<option value="ef" <?php echo in_array("ef", $book_fields)?"selected":""; ?>>ef</option>
<option value="idcolor" <?php echo in_array("idcolor", $book_fields)?"selected":""; ?>>idcolor</option>
<option value="inn" <?php echo in_array("inn", $book_fields)?"selected":""; ?>>inn</option>
<option value="n_schet" <?php echo in_array("n_schet", $book_fields)?"selected":""; ?>>n_schet</option>
<option value="dom_tel" <?php echo in_array("dom_tel", $book_fields)?"selected":""; ?>>dom_tel</option>
<option value="mob_tel" <?php echo in_array("mob_tel", $book_fields)?"selected":""; ?>>mob_tel</option>
<option value="work_tel" <?php echo in_array("work_tel", $book_fields)?"selected":""; ?>>work_tel</option>
<option value="reg_city" <?php echo in_array("reg_city", $book_fields)?"selected":""; ?>>reg_city</option>
<option value="reg_region" <?php echo in_array("reg_region", $book_fields)?"selected":""; ?>>reg_region</option>
<option value="reg_district" <?php echo in_array("reg_district", $book_fields)?"selected":""; ?>>reg_district</option>
<option value="reg_settlement" <?php echo in_array("reg_settlement", $book_fields)?"selected":""; ?>>reg_settlement</option>
<option value="reg_adress" <?php echo in_array("reg_adress", $book_fields)?"selected":""; ?>>reg_adress</option>
<option value="live_city" <?php echo in_array("live_city", $book_fields)?"selected":""; ?>>live_city</option>
<option value="live_region" <?php echo in_array("live_region", $book_fields)?"selected":""; ?>>live_region</option>
<option value="live_district" <?php echo in_array("live_district", $book_fields)?"selected":""; ?>>live_district</option>
<option value="live_settlement" <?php echo in_array("live_settlement", $book_fields)?"selected":""; ?>>live_settlement</option>
<option value="live_adress" <?php echo in_array("live_adress", $book_fields)?"selected":""; ?>>live_adress</option>
</select>
Проверка на выделенный пункт списка