1. Лучший говнокод

    В номинации:
    За время:
  2. C# / Говнокод #19388

    −2

    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
    float PriceByProductID(string product_id)
    	{
    		if(product_id == RUBY_PILE)
    			return 1.99f;
    		else if (product_id == RUBY_BAG)
    			return 4.99f;
    		else if (product_id == RUBY_SACK)
    			return 9.99f;
    		else if (product_id == RUBY_BOX)
    			return 19.99f;
    		else if (product_id == RUBY_CHEST)
    			return 39.99f;
    		else if (product_id == RUBY_TRUNK)
    			return 99.99f;
    		else if (product_id == GOLD_PILE)
    			return 0.99f;
    		else if (product_id == GOLD_BAG)
    			return 2.99f;
    		else if (product_id == GOLD_SACK)
    			return 7.99f;
    		else if (product_id == GOLD_BOX)
    			return 14.99f;
    		else if (product_id == GOLD_CHEST)
    			return 29.99f;
    		else if (product_id == GOLD_TRUNK)
    			return 79.99f;
    		return 0f;
    	}

    kschingiz, 03 Февраля 2016

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

    +3

    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
    /*
    =============
    TempVector
    
    This is just a convenience function
    for making temporary vectors for function calls
    =============
    */
    float  *tv (float x, float y, float z)
    {
      static  int    index;
      static  vec3_t  vecs[8];
      float  *v;
    
      // use an array so that multiple tempvectors won't collide
      // for a while
      v = vecs[index];
      index = (index + 1)&7;
    
      v[0] = x;
      v[1] = y;
      v[2] = z;
    
      return v;
    }

    LispGovno, 13 Сентября 2015

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

    +4

    1. 1
    static const int s_extend_offset[16] = { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };

    Это я нашел в libJPG (они там в конец двинулись сдвигать отрицательные числа)

    maxis11, 16 Августа 2015

    Комментарии (28)
  5. JavaScript / Говнокод #18540

    +1001

    1. 1
    'used strict'

    Уже "попользовался" strict

    Оригинал: https://github.com/tischenkoa/portfolio-front-end-javascript/blob/master/24_task_(Ajax_loading_comics)/loadimg.js#L4

    volter9, 27 Июля 2015

    Комментарии (28)
  6. Lua / Говнокод #18346

    −85

    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
    local sol_lines = {}
    local i = 1; local j = 0;
    	
    while (i <= solution:len()) do
    	local begin_pos = i
    	while(i <= solution:len() and solution:sub(i, i) ~= '\n') do
    		i = i + 1
    	end
    
    	if i > solution:len() then
    		i = solution:len()
    	end
    
    	local cur_line = solution:sub(begin_pos, i)
    	sol_lines[j] = trim(cur_line)
    	i = i + 1
    	j = j + 1
    end

    Lua
    Как я разбивал строку на отдельные линии. Вместо того, чтобы использовать string.find(s, "\n", i + 1). Так я писал код 0.027397 года назад назад.

    Janycz, 15 Июня 2015

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

    +144

    1. 1
    2. 2
    $testing[$i]['ddate'] = ((substr("$departureDate", 0, -4)) . "/" . (substr("$departureDate", -4, 2)) . "/" . (substr("$departureDate", -2))) . "(" . ((substr("$departureTime", 0, -2)) . ":" . (substr("$departureTime", -2))) . ")";
    $testing[$i]['adate'] = ((substr("$arrivalDate", 0, -4)) . "/" . (substr("$arrivalDate", -4, 2)) . "/" . (substr("$arrivalDate", -2))) . "(" . ((substr("$arrivalTime", 0, -2)) . ":" . (substr("$arrivalTime", -2))) . ")";

    из реального проекта, который писал индус.

    форматирование даты. это все еще и в цикле

    namreg, 05 Июня 2015

    Комментарии (28)
  8. PHP / Говнокод #18253

    +143

    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
    class Security{
        
        private $workFactor, $salt;
        
        public function __construct(){
            $this->setWorkFactor();
            $salt = $this->getSaltBytes();
            $this->setSalt($salt);
        }
        
        public function hash($password, $workFactor = 6){
            $options = [
                'cost' => (int)$workFactor,
                'salt' => $this->getSalt()
            ];
            $hash = password_hash($password, PASSWORD_BCRYPT, $options);
            return $hash;
        }
    
        public function checkHash($password, $passwordHash, $options = []){
            if( isset($options['salt'])){
                $this->setSalt($options['salt']);
            }
            $workFactor = isset($options['workFactor']) ? 
                    $options['workFactor'] : $this->getWorkFactor();
            return $passwordHash === $this->hash($password, $workFactor);
        }
        
        public function isLegacyHash($passwordHash){
            return strlen($passwordHash) === 60;
        }
        
        public function getSalt(){
            return $this->salt;
        }
        
        public function setSalt($salt){
            $this->salt = $salt;
        }
        
        public function getSaltBytes($lenght = 24){
            return $this->getRandomBytes($lenght);
        }
    
        public function getRandomBytes($lenght = 24){
            $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            $charactersLength = strlen($characters);
            $randomString = '';
            for ($i = 0; $i < $lenght; $i++){
                $randomString .= $characters[rand(0, $charactersLength - 1)];
            }
            return $randomString;
        }
        
        public function setWorkFactor($workFactor = 6){
            $this->workFactor = (int)$workFactor;
        }
        
        public function getWorkFactor(){
            return $this->workFactor;
        }
        
    }

    Besmer, 28 Мая 2015

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

    +96

    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
    protected override void OnSourceInitialized(EventArgs e)
    {
        base.OnSourceInitialized(e);
        var hWndSource = (HwndSource)PresentationSource.FromVisual(this);
        Handle = hWndSource.Handle;
        hWndSource.AddHook(WndProc);
    }
    
    private const int WM_ACTIVATE = 0x0006;
    private const ushort WA_INACTIVE = 0;
    
    static ushort LOWORD(IntPtr I)
    {
        unchecked
        {
            return (ushort)(((uint)I) & 0xFFFF);
        }
    }
    
    protected IntPtr WndProc(IntPtr hWnd, int iMsg, IntPtr wParam, IntPtr lParam, ref bool bHandled)
    {
        switch (iMsg)
        {
            case WM_ACTIVATE:
                Opacity = LOWORD(wParam) == WA_INACTIVE ? 0.4 : 1.0;
                bHandled = true;
                return (IntPtr)1;
        }
    
        return IntPtr.Zero;
    }

    Из моего проекта. Так я писал код 0.8 год назад.
    Вместо того, чтобы использовать OnActivated и OnDeactivated.

    Janycz, 18 Января 2015

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

    +123

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    KoKoKoKoKoKoKoKoKoKo Kud-Kudah KoKoKoKoKoKoKoKo kudah kO kud-Kudah Kukarek
    kudah KoKoKo Kud-Kudah kOkOkOkO kudah kO kud-Kudah Ko Kukarek
    kudah KoKoKoKo Kud-Kudah KoKoKoKo kudah kO kud-Kudah kO Kukarek
    kOkOkOkOkO Kukarek Kukarek
    kOkOkOkOkOkOkO Kukarek

    Публикации уже два дня, а на говнокоде ни одного упоминания. Ну как так?

    https://github.com/Ky6uk/PETOOH
    http://habrahabr.ru/post/245443/

    Xom94ok, 12 Декабря 2014

    Комментарии (28)
  11. Python / Говнокод #17277

    −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
    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
    66. 66
    #!/usr/bin/env python
    # encoding: utf-8
    
    import os
    import sys
    
    from sets import Set
    
    class OutputSplitter(object):
        """ splitter """
        
        def __init__(self, out_splitter):
            self.__pipes=None
            if isinstance(out_splitter, OutputSplitter):
                    self.__pipes = Set(out_splitter.pipes)
            elif out_splitter:
                print out_splitter
                if type(out_splitter) == list : #
                    for pn in out_splitter:
                        self.add_pipe(pn)
                else:
                    self.add_pipe(out_splitter)
                       
        @property
        def pipes(self):
            return self.__pipes
        
        def add_pipe(self, pn):
            if isinstance(pn, basestring):
                if pn == 'stderr': x = sys.stderr
                elif pn == 'stdout': x = sys.stdout
                else: 
                    p = os.path.dirname(pn)
                    if p and not os.path.exists(p):
                        os.makedirs(p)
                    try: 
                        x = open(pn,'w+')
                    except IOError:
                        raise
                        
            else: x = pn
            
            if hasattr(x, 'write') and hasattr(x, 'flush'):
                if self.__pipes is None:
                    self.__pipes=Set()
                self.__pipes.add(x)
        
        def write(self,s):
            if self.__pipes:
                for p in self.__pipes:
                    p.write(s)
        
        def flush(self):
            if self.__pipes:
                for p in self.__pipes:
                    p.flush()
        
        #def __enter__(self):
        #    pass         
        #def __exit__(self, exc_type, exc_value, traceback):
        #    pass
    
    if __name__ == '__main__':
        cout=sys.stdout if True else sys.stderr
        o=OutputSplitter(cout)
        pass

    Испаравленная версия по монивам http://govnokod.ru/17181. Учтены замечания некого Анонимус http://govnokod.ru/17181#comment256577. Надеюсь что будут еще замечания, такие же конструктивные и полезные.

    apgurman, 08 Декабря 2014

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