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

    +139

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    <?php
    function string_size($string){
    $temporary_file = md5(rand().rand()).".temporary";
    $a=fopen($temporary_file,"w+");
    fwrite($a,$string);
    $size = filesize($temporary_file);
    fclose($a);
    unset($temporary_file);
    return $size;
    }
    ?>

    Аналог функции filesize() для строк.

    angrybird, 11 Марта 2013

    Комментарии (16)
  2. Java / Говнокод #12723

    +76

    1. 1
    public static final String RANDOM_VALUE_QUERY = "select to_number(to_char(dbms_random.value(100,999),'999'),'999') from dual";

    Прогрессивный способ генерации случайных чисел=.

    nafania217518, 11 Марта 2013

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

    +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
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    <form action="/b/wakaba.pl" method="post" enctype="multipart/form-data">
        <input type="hidden" name="task" value="search" /> 
        <input id="dynamicNamed" name="scommsubj" value="" type="text" placeholder="Поиск" required /> 
        <select> 
              <option id="opt0" value="scommsubj">везде</option> 
              <option id="opt1" value="searchsubj">в любом заголовке</option>
               <option id="opt2" value="searchcomm">в любом сообщении</option>
               <option id="opt3" value="tscommsubj">в главном посте треда</option>
               <option id="opt4" value="tsearchsubj">в главном заголовке треда</option>
               <option id="opt5" value="tsearchcomm">в главном сообщении треда</option>
         </select>
         <input type="submit" value="GO" onclick="javascript: buttonOK(); this.submit;" />
     </form> 
    
    
    function buttonOK()
    {
    	$id('dynamicNamed').name = $id('opt' + select.selectedIndex).value;
    }

    Сосач.
    Новое слово в передаче параметров.

    7ion, 11 Марта 2013

    Комментарии (9)
  4. Куча / Говнокод #12721

    +124

    1. 1
    https://docs.google.com/forms/d/1mhNCSYPqeLT7pXJEV_BpRkV1sdKJsPdJZcagSafOLVc/viewform

    Опрос на тему того, кто и как сможет принять участие в разработке аналога говнокода.

    scriptin, 10 Марта 2013

    Комментарии (101)
  5. PHP / Говнокод #12720

    +146

    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
    class User {
    
      protected $login;
      protected $password;
      protected $email;
    
      public function __construct($login, $password, $email) {
        $this->login = $login;
        $this->password = $password;
        $this->email = $email;
      }
    
      public function __get($name) {
        $reflector = new ReflectionClass($this);
        return $reflector->hasProperty($name) ? $this->{$name} : null;
      }
    
    }

    __proto__, 10 Марта 2013

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

    +153

    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
    $statement = $pdo->prepare(
         "if not exists
          (select daily_serving_start, daily_serving_end,
                  weekly_service_off, one_time_service_off
          from menu_availability_rules
          where
            (daily_serving_start = :start0 or
             (daily_serving_start is null and :start1 is null)) and
            (daily_serving_end = :end0 or
             (daily_serving_end is null and :end1 is null)) and
            (weekly_service_off = :weekly0 or
             (weekly_service_off is null and :weekly1 is null)) and
            (one_time_service_off = :once0 or
             (one_time_service_off is null and :once1 is null)))
          begin
            insert into menu_availability_rules
             (daily_serving_start, daily_serving_end,
              weekly_service_off, one_time_service_off)
            values (:start2, :end2, :weekly2, :once2)
          end
    
          if not exists
          (select menu_id, daily_serving_start, daily_serving_end,
                  weekly_service_off, one_time_service_off
          from menu_availability
          where
           menu_id = :menu_id0 and
           (daily_serving_start = :start3 or
             (daily_serving_start is null and :start4 is null)) and
            (daily_serving_end = :end3 or
             (daily_serving_end is null and :end4 is null)) and
            (weekly_service_off = :weekly3 or
             (weekly_service_off is null and :weekly4 is null)) and
            (one_time_service_off = :once3 or
             (one_time_service_off is null and :once4 is null)))
          begin
            insert into menu_availability
             (menu_id, daily_serving_start, daily_serving_end,
              weekly_service_off, one_time_service_off)
            values (:menu_id1, :start5, :end5, :weekly5, :once5)
          end");

    Мое :( А что делать?

    wvxvw, 10 Марта 2013

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

    +113

    1. 1
    http://habrahabr.ru/post/172129/

    «Мне нужен был online-сервис для генерации GUID»

    Пожалуйста, подключитесь к интернету, чтобы сгенерировать гуид. Что дальше? Конкатенация строк через RESTful сервер в облаке амазона?

    vse_govno, 10 Марта 2013

    Комментарии (26)
  8. Куча / Говнокод #12717

    +128

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <style>
    a img, input, #hndl-show-loginpass-fields, .checkout_buttons, #shipping-method-7, #shipping-method-6, #shipping-method-5,  #shipping-method-4,  #shipping-method-3, #shipping-method-2, #shipping-method-1, #payment-method-7, #payment-method-6, #payment-method-5, #payment-method-4, #payment-method-3, #payment-method-2, #payment-method-1, #payment-method-8, #payment-method-9, #payment-method-12
    {
    	border: 0;
    }
    </style>

    Отрыл в проекте заказчика вот такую строчку CSS :)

    invision70, 10 Марта 2013

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

    +16

    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
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    class Context;
    
    class AbstractState
    {
    	Context * m_context;
    
    protected:
    	Context * context() const { return m_context; }
    
    public:
    	AbstractState(Context * context) : m_context(context) { };
    	virtual ~AbstractState() { }
    	virtual void doSomething() = 0;
    };
    
    class Context
    {
    	std::unique_ptr<AbstractState> m_state;
    
    public:
    	enum State
    	{
    		State1,
    		State2,
    	};
    	Context() { switchToState(State1); }
    	void switchToState(State newState);
    	void doSomething() { m_state->doSomething(); }
    	void someCleanup() { }
    };
    
    class ConcreteState1 : public AbstractState
    {
    public:
    	ConcreteState1(Context * context) : AbstractState(context) { }
    	virtual void doSomething()
    	{
    		context()->switchToState(Context::State2);
    		context()->someCleanup();
    	}
    };
    
    class ConcreteState2 : public AbstractState
    {
    public:
    	ConcreteState2(Context * context) : AbstractState(context) { }
    	virtual void doSomething()
    	{
    		context()->switchToState(Context::State1);
    		context()->someCleanup();
    	}
    };
    
    void Context::switchToState(State newState)
    {
    	switch(newState)
    	{
    	case State1:
    		m_state.reset(new ConcreteState1(this));
    		return;
    	case State2:
    		m_state.reset(new ConcreteState2(this));
    		return;
    	}
    }

    Бывает, на меня находит состояние "сначала делай, потом думай", благо результат был быстро обнаружен отладчиком.

    Xom94ok, 10 Марта 2013

    Комментарии (1)
  10. Python / Говнокод #12715

    −105

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    def f(x):
        return x.strip()
    
    lines = map(f, open("1.txt", "r"))
    open("1.txt", "w").write(" ".join(lines))

    ХАСКЕЛЕПРОБЛЕМЫ™. Теперь и в питоне.

    Исходный файл содержит 3 строчки:

    just
    as
    planned
    Питон 2.7:
    $ python2.7 1.py
    $ cat 1.txt
    just as planned
    Питон 3.0:
    $ python3.2 1.py
    $ cat 1.txt

    bormand, 09 Марта 2013

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