- 1
boolean ROLLBACK = new Boolean(false).booleanValue();
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+85
boolean ROLLBACK = new Boolean(false).booleanValue();
И это пишет тимлид (сеньор) в моей конторе
+157
function date_preobr($date, $ind=0) {
$date1=substr($date, 8, 2); $date21=substr($date, 5, 2); $date3=substr($date, 0, 4);
if ($ind==0) $data=$date1.".".$date21.".".$date3;
elseif ($ind==1) $data=$date1.".".$date21.".".substr($date3, 2, strlen($date3)-2);
elseif ($ind==2) {switch ($date21) {case "01":$date21="января";break;case "02":$date21="февраля";break;
case "03":$date21="марта";break;case "04":$date21="апреля";break;case "05":$date21="мая";break;
case "06":$date21="июня";break;case "07":$date21="июля";break;case "08":$date21="августа";break;
case "09":$date21="сентября";break;case "10":$date21="октября";break;case "11":$date21="ноября";break;
case "12":$date21="декабря";break;} $data=$date1." ".$date21." ".$date3;}
return $data;}
Были даты, есть дата, будут даты.
Привожу в первозданном виде.
+128
if (body.ToLower().Contains("pr") ||
subject.Contains("PM") ||
subject.Contains("pm") ||
subject.Contains("Pm") ||
subject.Contains("pM") ||
subject.Contains("PMR") ||
subject.Contains("prs") ||
subject.ToLower().Contains("prt") ||
subject.ToLower().Contains("prm") ||
subject.ToLower().Contains("pmt") ||
subject.ToLower().Contains("pmk") ||
subject.ToLower().Contains("pml") ||
subject.ToLower().Contains("pal"))
{
result = true;
}
Пишут друзья из Норвегии
+70
import java.util.Random;
public class A {
public static void main(String args[]) {
int minimalSuccessTime = Integer.MAX_VALUE;
int maximalSuccessTime = Integer.MIN_VALUE;
for(int i = 0; i < 10000; i++) {
Random rnd = new Random();
boolean state = rnd.nextBoolean();
final byte prisonersCount = 100;
boolean prisoners[] = new boolean[prisonersCount];
byte prisonersCounted = 1;
int daysPassed = 0;
while(true) {
daysPassed++;
int tmp = rnd.nextInt(prisonersCount);
if(tmp == 0) {
if(state) {
state = false;
prisonersCounted++;
if(prisonersCounted == prisonersCount) {
break;
}
}
} else {
if(!state && !prisoners[tmp]) {
state = true;
prisoners[tmp] = true;
}
}
}
if(daysPassed < minimalSuccessTime) {
minimalSuccessTime = daysPassed;
}
if(daysPassed > maximalSuccessTime) {
maximalSuccessTime = daysPassed;
}
}
System.out.println("Minimal success time ~= " + minimalSuccessTime/365 + " years!");
System.out.println("Maximal success time ~= " + maximalSuccessTime/365 + " years!");
}
}
One hundred prisoners have been newly ushered into prison. The warden tells
them that starting tomorrow, each of them will be placed in an isolated cell,
unable to communicate amongst each other. Each day, the warden will choose
one of the prisoners uniformly at random with replacement, and place him in
a central interrogation room containing only a light bulb with a toggle switch.
The prisoner will be able to observe the current state of the light bulb. If he
wishes, he can toggle the light bulb. He also has the option of announcing that
he believes all prisoners have visited the interrogation room at some point in
time. If this announcement is true, then all prisoners are set free, but if it is
false, all prisoners are executed.
The warden leaves, and the prisoners huddle together to discuss their fate.
Can they agree on a protocol that will guarantee their freedom?
+92
public Boolean checkPermission(String login) {
if (login == null && login.trim().length() == 0)
throw new Exception("Не указан логин пользователя.");
/* ... */
}
Чудесное условие. Есть в этом Exception что-то неуловимое - его никто никогда не поймает.
+126
public static bool ValidateEmailAddress(string emailAddress)
{
try
{
string TextToValidate = emailAddress;
// test email address with expression
if (emailExpression.IsMatch(TextToValidate))
{
// is valid email address
return true;
}
else
{
// is not valid email address
return false;
}
}
catch (Exception)
{
throw;
}
}
public static bool ValidateEmailAddress(string emailAddress)
{
if(string.IsNullOrEmpty(emailAddress))
return false;
return emailExpression.IsMatch(TextToValidate);
}
+154
public function setIndex() {
$lang = '';
switch($this->data['find_in']) {
case '1' :
$this->indexes = Indexes::COMPANIES.$lang;
break;
case '2' :
$this->indexes = Indexes::PRODUCTS.$lang;
break;
case '3' :
$this->indexes = Indexes::PROMOS.$lang;
break;
default:
$this->indexes = Indexes::COMPANIES.$lang;
break;
}
}
+127
private string CalculateDecadeOrYear(string year)
{
string decade = year.Remove(3) + "0";
string currentYear = DateTime.Now.Year.ToString();
string currentDecade = currentYear.Remove(3) + "0";
string prevDecade = ((Convert.ToInt32(currentYear.Remove(3)) - 1)).ToString() + "0";
if (!(decade == currentDecade) && !(decade == prevDecade))
{
return decade;
}
return year;
}
stringly typed вычисление декады. нашел в исходниках индусов
−121
create or replace procedure rout_cancel (
p_sql varchar2
) is
v_curs sys_refcursor;
begin
if v_curs%isopen then
close v_curs;
end if;
begin
open v_curs for p_sql;
exception
when others then
raise_application_error(-20000, 'Unable to open cursor');
end;
rout_cancel_details(v_curs);
close v_curs;
end;
6-8: Кто ж тебя открыть-то успел?!
−121
declare
v_curs sys_refcursor;
v_on number;
begin
open v_curs for 'select rout_num from rout_orders_promotion';
fetch v_curs into v_on;
loop
exit when v_curs%notfound;
if v_curs%rowcount = 1 then
null;
end if;
fetch v_curs into v_on;
end loop;
close v_curs;
end;
Если запись одна, тогда уж точно нечего в цикле делать.