1. PHP / Говнокод #6956

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    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;}

    Были даты, есть дата, будут даты.
    Привожу в первозданном виде.

    De-Luxis, 15 Июня 2011

    Комментарии (13)
  2. C# / Говнокод #6955

    +128

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    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;
                }

    Пишут друзья из Норвегии

    jenik15, 15 Июня 2011

    Комментарии (8)
  3. Java / Говнокод #6954

    +70

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    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?

    guest2011, 14 Июня 2011

    Комментарии (13)
  4. Java / Говнокод #6953

    +92

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public Boolean checkPermission(String login) {
        if (login == null && login.trim().length() == 0)
            throw new Exception("Не указан логин пользователя.");
        /* ... */
    }

    Чудесное условие. Есть в этом Exception что-то неуловимое - его никто никогда не поймает.

    roman-kashitsyn, 14 Июня 2011

    Комментарии (26)
  5. C# / Говнокод #6952

    +126

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    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);
    }

    jenik15, 14 Июня 2011

    Комментарии (21)
  6. PHP / Говнокод #6951

    +154

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    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;
    		}
    	}

    hellow, 14 Июня 2011

    Комментарии (9)
  7. C# / Говнокод #6950

    +127

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    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 вычисление декады. нашел в исходниках индусов

    overberk, 14 Июня 2011

    Комментарии (8)
  8. SQL / Говнокод #6949

    −121

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    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: Кто ж тебя открыть-то успел?!

    dwinner, 14 Июня 2011

    Комментарии (3)
  9. SQL / Говнокод #6948

    −121

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    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;

    Если запись одна, тогда уж точно нечего в цикле делать.

    dwinner, 14 Июня 2011

    Комментарии (4)
  10. bash / Говнокод #6947

    −127

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    am=`cat $file | wc -l`
    for ((i=1;i<=$am;i++))
    do
        read z
        imsi=`echo $z | sed -e "s/^[0-9]*[ ]*//" `
    done < $file

    berezhinskiy, 14 Июня 2011

    Комментарии (6)