1. C# / Говнокод #11013

    +156

    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
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    private static BigInteger result = 0;
            static BigInteger F1 = 1;
            static BigInteger F2 = 1;
            static BigInteger provv;
            static BigInteger provv2;
    
            static void Main(string[] args)
            {
                for (BigInteger number = 3; result == 0; number++)
                {
                    provv2 = F2;
                    F2 = F2 + F1;
                    F1 = provv2; ;
                    if (HasProperty(F2.ToString()))
                        result = number;
                }
            }
    
            private static bool HasProperty(string number)
            {
                if (number.Length < 9)
                    return false;
                if (IsPandigital(number.Substring(0, 9)))
                    if (IsPandigital(number.Substring(number.Length - 9, 9)))
                        return true;
                return false;
            }
    
            private static bool IsPandigital(string result)
            {
                int repetitions;
                for (int count = 0; count < 9; count++)
                {
                    repetitions = 0;
                    for (int count2 = 0; count2 < 9; count2++)
                    {
                        if (result.ElementAt(count).ToString() == "0")
                            return false;
                        if (result.ElementAt(count).ToString() == result.ElementAt(count2).ToString())
                        {
                            repetitions++;
                            if (repetitions == 2)
                                return false;
                        }
                    }
                }
                return true;
            }

    http://projecteuler.net/problem=104
    http://projecteuler.net/thread=104;page=6



    >brute force approach,solved aproximately in 24 hours
    >solved aproximately in 24 hours
    >24 hours
    >24
    >hours


    Терпеливый, сука!

    TheHamstertamer, 17 Июня 2012

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

    +137

    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
    [ExposeProperty]
    public bool Exhausted {
    	get {
    		if (this.State > FatigueConsts.globalNormalRange)
    			return true;
    		else
    			return false;
    	}
    	set {
    		if (this.State > FatigueConsts.globalNormalRange)
    			Exhausted = true;
    		else
    			Exhausted = false;
    	}
    }

    И потом полчаса сидел, понимал, почему Юнити зависает, когда я пытаюсь открыть инспектор с этим объектом ) Потом поставил в сеттер return;, ибо для костыля [ExposeProperty] требуются и геттер, и сеттер.

    sulnedinfind, 17 Июня 2012

    Комментарии (19)
  3. Си / Говнокод #10987

    +141

    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
    ...
        ASSERT( sizeof(L"SystemPartition") <= sizeof(nameBuffer) );
    /* Китайский код? Или по другому нельзя было запихнуть строку в ентот массив? */
        nameBuffer[0]  = L'S';
        nameBuffer[1]  = L'y';
        nameBuffer[2]  = L's';
        nameBuffer[3]  = L't';
        nameBuffer[4]  = L'e';
        nameBuffer[5]  = L'm';
        nameBuffer[6]  = L'P';
        nameBuffer[7]  = L'a';
        nameBuffer[8]  = L'r';
        nameBuffer[9]  = L't';
        nameBuffer[10] = L'i';
        nameBuffer[11] = L't';
        nameBuffer[12] = L'i';
        nameBuffer[13] = L'o';
        nameBuffer[14] = L'n';
        nameBuffer[15] = L'\0';
    
        nameString.MaximumLength = sizeof(L"SystemPartition");
        nameString.Length        = sizeof(L"SystemPartition") - sizeof(WCHAR);
    
    
    
        status = NtSetValueKey(setupHandle,
                                &nameString,
                                TITLE_INDEX_VALUE,
                                REG_SZ,
                                volumeNameString.Buffer,
                                volumeNameString.Length + sizeof(WCHAR)
                               );
    ...

    В Мелкософт китайцев пригласили?

    Кусок кода ядра Шindoшs ИТ
    файл ioinit.c, строка 3312

    Destinat1on, 16 Июня 2012

    Комментарии (55)
  4. PHP / Говнокод #10986

    +56

    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
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    <?php
    
    define(STATIC_SALT, "herz_salt");
    
    function generateRandChar()
    {
      $chars = 'abdefhiknrstyzABDEFGHKNQRSTYZ23456789';
      
      $numChars = strlen($chars);
      
      $string = '';
      
      for ($i = 0; $i < rand(1, 7); $i++) 
      {
          $string .= substr($chars, rand(1, $numChars) - 1, 1);
      }
      
      return $string;
    }
    
    $time = microtime(true) / 10000;
    
    $str = $time - floor($time);
    
    $str = (string)$str;
    
    $str = preg_replace('/0./', '', $str);
    
    $deleteNum = strlen($str);
    
    if($deleteNum  <= 5)
    {
        $str = substr($str, rand(0, 4));
    }
    elseif($deleteNum > 5 && $deleteNum  <= 10)
    {
        $str = substr($str, rand(5, 9));
    }
    else $str = substr($str, rand(7, 9));
    
    if(strlen($str) == 0)
    {
        $str = rand(0, 15000);
    }
    
    sleep(5);
    
    $str = sha1(md5($str . STATIC_SALT . microtime(true))) . generateRandChar();
    
    echo $str;
    
    ?>

    паранойя в действии :)

    Archont12, 16 Июня 2012

    Комментарии (36)
  5. Куча / Говнокод #10984

    +132

    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
    function rechargePubSession(age,sexe)
    {
      var url_pub_ban = "publicite_banniere";
      var url_pub_sky = "publicite_skyscrapper";
      var ext;
     
      if (age >0)
      {
      if (age < 18)
        ext="_A";
      else if (age < 33)
        ext="_G";
      else if (age >= 33)
        ext="_E";
        
      if (ext!="")
      {
        if (sexe == "F")
           ext+="_F";
        else if (sexe == "M")
           ext+="_M";
     
        if (sexe=="M" || sexe=="F")
        {
        url_pub_ban += ext;
        url_pub_sky += ext;
        }
      }
      }
     
      url_pub_ban+=".html";
      url_pub_sky+=".html";
      frame_pub_banniere.document.location= url_pub_ban;
      frame_pub_droite.document.location=url_pub_sky;
    }

    http://ru.akinator.com

    dos_, 16 Июня 2012

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

    +50

    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
    // $conn - mysqli_object
     $query = "insert into orders values
                ('0', '".$customerid."', '".$_SESSION['total_price']."',
                '".$date."', '".PARTIAL."', '".$ship_name."',
                '".$ship_address."', '".$ship_city."',
                '".$ship_state."', '".$ship_zip."',
                '".$ship_phone."', '".$ship_mail."')";
      $result = $conn->query($query) ;
      if (!$result) {
        return false;
      }
    //amount - float
      $query = "select orderid from orders where
              customerid = '".$customerid."' and
              amount > (".$_SESSION['total_price']."-.001) and
              amount < (".$_SESSION['total_price']."+.001) and
              date = '".$date."' and
              order_status = 'PARTIAL' and
              ship_name = '".$ship_name."' and
              ship_address = '".$ship_address."' and
              ship_city = '".$ship_city."' and
              ship_state = '".$ship_state."' and
              ship_zip = '".$ship_zip."' and
              ship_country = '".$ship_country."'";
      $result = $conn->query($query);
      if ($result->num_rows > 0) {
        $order = $result->fetch_object();
        $orderid = $order->orderid;
      } else {
        return false;
      }

    Источник: Люк Веллинг и Лора Томсон: Разработка веб-приложений с помощью PHP и MySQL(4 издание стр 594)

    Как выдрать last_insert_id? Очень просто: нужно составить запрос на select вставленного orderid с указанием всех вставленных значений в поля, а для флоата указать на всякий случай интервал, и только тогда можно из выборки извлечь вставленный id

    ps: констатна PARTIAL нигде не задаётся=)

    RedMonkey, 16 Июня 2012

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

    −78

    1. 1
    tg_hujak_v_zap_na_sklade

    Название триггера в промышленной системе.
    Hint: zap_na_sklade - таблица

    Xps, 16 Июня 2012

    Комментарии (34)
  8. C# / Говнокод #10975

    +139

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public static IEnumerable<T> QuickSort<T>(
    	this IEnumerable<T> source) where T : IComparable<T>
    	{
    		if (!source.Any()) return source;
    		var first = source.First();
    		return source
    			.AsParallel()
    			.GroupBy(i => i.CompareTo(first))
    			.OrderBy(g => g.Key)
    			.SelectMany(g => g.Key == 0 ? g : QuickSort(g));
    	}

    HaskellGovno, 16 Июня 2012

    Комментарии (27)
  9. PHP / Говнокод #10974

    +64

    1. 1
    2. 2
    3. 3
    4. 4
    $res = mysql_query(...);
    if($res == 'true'){
        .....
    }

    Может кому то покажутся знакомы эти строки, но те, кто не знают Е. Попова могут над ним поржать.

    BioMan, 15 Июня 2012

    Комментарии (68)
  10. Куча / Говнокод #10973

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    >>>+[[-]>>[-]++>+>+++++++[<++++>>++<-]++>>+>+>+++++[>++>++++++<<-]+>>>,<++[[>[
    ->>]<[>>]<<-]<[<]<+>>[>]>[<+>-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<<
    ]<]<[[<]>[[>]>>[>>]+[<<]<[<]<+>>-]>[>]+[->>]<<<<[[<<]<[<]+<<[+>+<<-[>-->+<<-[>
    +<[>>+<<-]]]>[<+>-]<]++>>-->[>]>>[>>]]<<[>>+<[[<]<]>[[<<]<[<]+[-<+>>-[<<+>++>-
    [<->[<<+>>-]]]<[>+<-]>]>[>]>]>[>>]>>]<<[>>+>>+>>]<<[->>>>>>>>]<<[>.>>>>>>>]<<[
    >->>>>>]<<[>,>>>]<<[>+>]<<[+<<]<]

    Yo dawg I heard you like brainfuck so we put brainfuck in your brainfuck so you can brainfuck while you brainfuck

    rat4, 15 Июня 2012

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