1. Objective C / Говнокод #12452

    −90

    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
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    - (void)movementScreenUp
    {
        int shift;
        switch (_numberCell) {
            case 3:
                if (clickButtonGameCells.tag == 1 || clickButtonGameCells.tag == 10) {
                    shift = startPosition.y;
                    break;
                }
                if (clickButtonGameCells.tag == 2 || clickButtonGameCells.tag == 20) {
                    shift = - 50;
                    break;
                }
                if (clickButtonGameCells.tag == 3 || clickButtonGameCells.tag == 30) {
                    shift = - 90;
                    break;
                }
                
            case 4:
                if (clickButtonGameCells.tag == 1 || clickButtonGameCells.tag == 10) {
                    shift = startPosition.y;
                    break;
                }
                if (clickButtonGameCells.tag == 2 || clickButtonGameCells.tag == 20) {
                    shift = - 25;
                    break;
                }
                if (clickButtonGameCells.tag == 3 || clickButtonGameCells.tag == 30) {
                    shift = - 90;
                    break;
                }
                if (clickButtonGameCells.tag == 4 || clickButtonGameCells.tag == 40) {
                    shift = - 90;
                    break;
                }
                
            case 5:
                if (clickButtonGameCells.tag == 1 || clickButtonGameCells.tag == 10) {
                    shift = startPosition.y;
                    break;
                }
                if (clickButtonGameCells.tag == 2 || clickButtonGameCells.tag == 20) {
                    shift = - 1;
                    break;
                }
                if (clickButtonGameCells.tag == 3 || clickButtonGameCells.tag == 30) {
                    shift = - 40;
                    break;
                }
                if (clickButtonGameCells.tag == 4 || clickButtonGameCells.tag == 40) {
                    shift = - 86;
                    break;
                }
                if (clickButtonGameCells.tag == 5 || clickButtonGameCells.tag == 50) {
                    shift = - 86;
                    break;
                }
            
            case 6:
                if (clickButtonGameCells.tag == 1 || clickButtonGameCells.tag == 10) {
                    shift = startPosition.y;
                    break;
                }
                if (clickButtonGameCells.tag == 2 || clickButtonGameCells.tag == 20) {
                    shift = startPosition.y;
                    break;
                }
                if (clickButtonGameCells.tag == 3 || clickButtonGameCells.tag == 30) {
                    shift = - 2;
                    break;
                }
                if (clickButtonGameCells.tag == 4 || clickButtonGameCells.tag == 40) {
                    shift = - 52;
                    break;
                }
                if (clickButtonGameCells.tag == 5 || clickButtonGameCells.tag == 50) {
                    shift = - 105;
                    break;
                }
                if (clickButtonGameCells.tag == 6 || clickButtonGameCells.tag == 60) {
                    shift = - 105;
                    break;
                }
                
            default:
                break;
                 
        }
    
        [UIView animateWithDuration:0.25 animations:^{
            CGRect view_frame = self.frame;
            view_frame.origin = CGPointMake(self.frame.origin.x, shift);
            self.frame = view_frame;
        }];
    }

    Магия цифр

    tyler, 20 Января 2013

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

    −109

    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
    - (void)countDown
    {
        NSDate *currentDate = [NSDate date];
        NSTimeInterval timeInterval = ([currentDate timeIntervalSinceDate:startDate]);
        NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"ss"];
        [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
        NSString *timeString=[dateFormatter stringFromDate:timerDate];
        
        if ([timeString isEqualToString:@"02"])
        {
            [logoTimer invalidate];
            logoTimer = nil;
            // some other code
        }
    }
    
    - (void)updateCounter
    {
        startDate = [NSDate dateWithTimeIntervalSinceNow:00];
        logoTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
                                                     target:self
                                                   selector:@selector(countDown)
                                                   userInfo:nil
                                                    repeats:YES];
    }

    Вот так незатейливо можно поставить задержку на 2 секунды

    tyler, 19 Января 2013

    Комментарии (31)
  3. ActionScript / Говнокод #12450

    −120

    1. 1
    2. 2
    3. 3
    4. 4
    private function uncaughtError (e:UncaughtErrorEvent):void {
    			// be a good girl and swallow
    			e.stopImmediatePropagation ();
    		}

    написал какую-то хуету и сижу, радуюсь как маленький. да, я хочу поговорить об этом.

    makc3d, 19 Января 2013

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

    +8

    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
    #include <iostream>
     
    struct Reader_msg;
    template<class T>struct TMsg;
     
    struct IMsg
    {
        virtual ~IMsg(){}
        virtual void SendCast(Reader_msg& obj) = 0;
    };
     
    struct Some{}; 
     
    struct Reader_msg
    {
        template<class T> void ReadMsg(T& msg)
        {
            //Здесь можно приляпать статик_ассерт
            std::cout<<"ERROR UNKNOW TYPE \n";
        }
        void ReadMsg(int msg)   { (void)msg; std::cout<<"TYPE IS INT\n";   }
        void ReadMsg(float msg) { (void)msg; std::cout<<"TYPE IS FLOAT\n"; }
        void ReadMsg(Some msg)  { (void)msg; std::cout<<"TYPE IS SOME\n";  }
     
        template<class T>void TakeMsg(T& msg) { msg.SendCast(*this); }
    };
     
    template<class T>struct TMsg:IMsg
    {
        T data;
        void SendCast(Reader_msg& obj){ obj.ReadMsg(data); }
    };
     
     
    int main()
    {
        Reader_msg reader;
        TMsg<int>    msg1;
        TMsg<float>  msg2;
        IMsg& msg3 = msg1;
        IMsg& msg4 = msg2;
        TMsg<Some>   msg5;
        TMsg<double> msg6;
        
     
        reader.TakeMsg(msg1);
        reader.TakeMsg(msg2);
        reader.TakeMsg(msg3);
        reader.TakeMsg(msg4);
        reader.TakeMsg(msg5);
        reader.TakeMsg(msg6);
    }

    http://liveworkspace.org/code/4FHDTq$6

    LispGovno, 18 Января 2013

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

    +47

    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
    function executeNewsRightRelated(sfWebRequest $request)
      {
        $siteId = $request->getParameter('site')->id;
        $tNewsList = $this->object->News;
    
        $newsList = array();
        foreach ($tNewsList as $news) {
    
          $ids = array();
          foreach ($news->Sites as $idModel) {
            $ids[] = $idModel->id;
          }
    
          if (in_array($siteId, $ids)) {
            $newsList[] = $news;
          }
        }
    
        $this->newsList = $newsList;
      }

    Skiv, 18 Января 2013

    Комментарии (7)
  6. Си / Говнокод #12447

    +110

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    int strnlen(const char *s, int size)
    {
            int i;
            for(i=0; i<size; i++) if(!*s) break;
            return i;
    }

    tz-lom, 18 Января 2013

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

    +139

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    List<string> duplicities = new List<string>();
    
          foreach (var localItem in FileCollectionLocal)
          {
            foreach (var remoteItem in FileCollectionRemote)
            {
              if (localItem.FileName == remoteItem.FileName)
              {
                duplicities.Add(localItem.FileName);
              }
            }
          }

    taburetka, 18 Января 2013

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

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    > echo 1 >1.cp
    > echo 1 >1.cpp
    > echo 1 >1.cppp
    > dir /b *.cp
    1.cp
    > dir /b *.cpp
    1.cpp
    1.cppp

    Баг в FindFirstFile/FindNextFile, показан на виндовом dir для простоты демонстрации. Призрак DOS'а жив даже в семерке...

    bormand, 18 Января 2013

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

    −161

    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
    create temp table data (id serial, o1 money(16,2) default 0, o2 money(16,2) default 0,
    o3 money(16,2) default 0, o4 money(16,2) default 0, o5 money(16,2) default 0,
    o6 money(16,2) default 0, o7 money(16,2) default 0, o8 money(16,2) default 0,
    o9 money(16,2) default 0, o10 money(16,2) default 0, o11 money(16,2) default 0,
    o12 money(16,2) default 0, o13 money(16,2) default 0, o14 money(16,2) default 0,
    o15 money(16,2) default 0, o16 money(16,2) default 0, o17 money(16,2) default 0,
    o18 money(16,2) default 0, o19 money(16,2) default 0, o20 money(16,2) default 0,
    o21 money(16,2) default 0, o22 money(16,2) default 0, o23 money(16,2) default 0,
    o24 money(16,2) default 0, o25 money(16,2) default 0, o26 money(16,2) default 0,
    o27 money(16,2) default 0, o28 money(16,2) default 0, o29 money(16,2) default 0,
    o30 money(16,2) default 0, o31 money(16,2) default 0, f1 money(16,2) default 0,
    f2 money(16,2) default 0, f3 money(16,2) default 0, f4 money(16,2) default 0,
    f5 money(16,2) default 0, f6 money(16,2) default 0, f7 money(16,2) default 0,
    f8 money(16,2) default 0, f9 money(16,2) default 0, f10 money(16,2) default 0,
    f11 money(16,2) default 0, f12 money(16,2) default 0, f13 money(16,2) default 0,
    f14 money(16,2) default 0, f15 money(16,2) default 0, f16 money(16,2) default 0,
    f17 money(16,2) default 0, f18 money(16,2) default 0, f19 money(16,2) default 0,
    f20 money(16,2) default 0, f21 money(16,2) default 0, f22 money(16,2) default 0,
    f23 money(16,2) default 0, f24 money(16,2) default 0, f25 money(16,2) default 0,
    f26 money(16,2) default 0, f27 money(16,2) default 0, f28 money(16,2) default 0,
    f29 money(16,2) default 0, f30 money(16,2) default 0, f31 money(16,2) default 0,
    ftot money(16,2) default 0)

    ... must be funny in the rich man's world ...

    bormand, 18 Января 2013

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

    +54

    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
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    <?php
    
        class ArrObj implements ArrayAccess, Countable, Iterator
        {
    
            protected $_data = array();
            protected $_indexes = array();
            protected $_pos = 0;
    
            public function __construct($data = array())
            {
                $this->_data = $data;
            }
    
            public function offsetGet($name)
            {
                if($isset = isset($this->_data[$name])) return $this->_data[$name];
                $this->_data[$name] = new self();
                return $isset ? $this->_data[$name] : null;
            }
    
            public function offsetSet($name, $value)
            {
                if(is_array($value)) $value = new self($value);
                $this->_data[$name] = $value;
                $this->_indexes[] = $name;
                return $value;
            }
    
            public function offsetUnset($name)
            {
                unset($this->_data[$name]);
                $this->_indexes = array_merge(array_diff($this->_indexes, array($name)));
            }
    
            public function offsetExists($name)
            {
                return isset($this->_data[$name]);
            }
    
            public function count()
            {
                return count($this->_data);
            }
    
            public function rewind()
            {
                $this->_pos = 0;
            }
    
            public function current()
            {
                return $this->_data[$this->_indexes[$this->_pos]];
            }
    
            public function key()
            {
                return $this->_indexes[$this->_pos];
            }
    
            public function next()
            {
                ++$this->_pos;
            }
    
            public function valid()
            {
                return isset($this->_indexes[$this->_pos]);
            }
    
        }
    
    ?>

    Sarkian, 18 Января 2013

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