1. ActionScript / Говнокод #17062

    −91

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    [Embed(source = "/assets/video_preview/VideoSlideThumb.png")]
    public static const VIDEO_PREVIEW: Class;
    
    public static function get videoPreviewBD(): BitmapData
    {
    	var image : Bitmap = new VIDEO_PREVIEW ();
    	return image.bitmapData.clone();		
    }

    Когда-то давно бытовала такая пословица: What Intel giveth Microsoft taketh away. Но похоже что переходное красное знамя подхватили и в других организациях по-меньше.

    wvxvw, 04 Ноября 2014

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

    +135

    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
    void *list_find_data(struct node *llist, void *data, int (*cmp_func)(void *, void *))
    {
    	struct node* it_node = NULL;
    
    	if (NULL != cmp_func)
    	{
    		for(it_node = llist; (NULL != it_node); it_node = it_node->next)
    	    {
                if (NULL != it_node->data)
                {
                    if (0 == cmp_func(data, it_node->data))
                    {
                        break;
                    }
                }
            }
    	}
    	return ((NULL != it_node) && (NULL != it_node->data)) ? it_node->data : NULL;
    }

    Велосипедисты жгут. О glibопараше не наслышаны.

    codemonkey, 04 Ноября 2014

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

    −863

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    SELECT *
    	FROM session s
    	WHERE s.platform IS NOT NULL
    	GROUP BY s.user_id
    	HAVING MAX(s.open_utc)

    Но хоть можно понять что сказать пытались, и на том спасибо.

    Lowezar, 03 Ноября 2014

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

    +55

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    void input (char inpt [64])
    {
    	for (;;)
    	{
    		int i(0);
    		cin >> inpt;
    		i ++;
    		if (inpt[i] == '\n')
    			inpt[i] = '\0';break;
    	}
    }

    normbo, 03 Ноября 2014

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

    +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
    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
    <?php
        class view {
            protected $dir; //templates directory
            protected $lang; //language
            protected $authorized;
            protected $user;
    
            protected function getCache($template) {
                //return false; //uncomment for developing
                if (!isset($_SESSION['cache_' . $template])) return false;
                return $_SESSION['cache_' . $template];
            }
    
            protected function addCache($template, $content) {
                $_SESSION['cache_' . $template] = $content;
            }
    
            public function __construct($dir, localization $lang, user $user) {
                $this->dir = $dir; 
                $this->authorized = (bool) $user->authorized;
                $this->user = $user;
                $this->lang = $lang;
            }
    
            public function invoke($template, $params = [], $return = false, $quests = []) { //can be called w/o params
                $filename = ROOT . '/' . $this->dir . '/tpl/' . $template . '.tpl';
                $lang = $this->lang->getData();
                $content = $this->getCache($template);
                if (!$content) {
                    $f = fopen($filename, 'a+');
                    $content = fread($f, (filesize($filename) > 0 ? filesize($filename) : 1));
                    $this->addCache($template, $content);
                }
                foreach ($params as $key => $value) {
                    $content = str_ireplace('{{' . $key . '}}', $value, $content);
                } 
                preg_match_all("@{{:([a-z0-9_]+?)}}@sui", $content, $localization);
                $localization = $localization[1];
                foreach ($localization as $value) {
                    $content = str_ireplace('{{:' . $value . '}}', $lang[$value], $content);
                } //applying lang
    
                foreach ($quests as $key => $value) {
                    preg_match_all("@{\?$key=$value\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $matches);
                    while (!empty($matches[0])) {
                        $content = str_replace($matches[0][0], $matches[1][0], $content);
                        preg_match_all("@{\?$key=$value\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $matches);
                    }
                    preg_match_all("@{\?$key=((?!$value).+?)\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $matches);
                    while (!empty($matches[0])) {
                        $content = str_replace($matches[0][0], "", $content);
                        preg_match_all("@{\?$key=((?!$value).+?)\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $matches);
                    }
                }
    
                preg_match_all("@{\?access=([a-z0-9]+?)\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $perms);
                while (!empty($perms[0])) {
                    foreach ($perms[1] as $value) {
                        if ($this->user->canAccess($value))
                            $content = preg_replace("@{\?access=$value\?}(((?!{\?.+\?}).)*?){\?\?}@sui", "$1", $content);
                        else $content = preg_replace("@{\?access=$value\?}(((?!{\?.+\?}).)*?){\?\?}@sui", "", $content);
                    }
                    preg_match_all("@{\?access=([a-z0-9]+?)\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $perms);
                }
    
                $content = preg_replace("@{\?authorized=((?!" . (int) $this->authorized . ").+?)\?}(.+?){\?\?}@sui", "", $content);
                $content = preg_replace("@{\?authorized=" . (int) $this->authorized . "\?}(.+?){\?\?}@sui", "$1", $content);
                $content = preg_replace("@{\?(.+?)\?}(.+?){\?\?}@sui", "", $content);
    
                $content = str_ireplace('{{DIR}}', '/' . $this->dir, $content); //replacing DIR param
                $content = str_ireplace('{{URI}}', urlencode(other::filter($_SERVER['REQUEST_URI'])), $content); //replacing URI param
                $content = str_ireplace('{{HTTP_HOST}}', $_SERVER['HTTP_HOST'], $content); //replacing HTTP_HOST param
                $content = preg_replace("@{\?((.+?)|(.+?){0})\?}@sui", "", $content);
                if (!$return) echo $content;
                return $content;
            }
        }
    ?>

    Мой шаблонизатор. Детям и беременным женщинам не смотреть.

    Efog, 03 Ноября 2014

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

    +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
    <?php
    class ACL  
    {  
        var $perms = array();     // Массив : Содержит привилегия текущего пользователя
        var $userID = 0;          // Целое число : Содержит ID текущего пользователя
        var $userRoles = array(); // Массив : Содержат роли текущего пользователя
      
        function __constructor($userID = '')  
        {  
            if ($userID != '')  
            {  
                $this->userID = floatval($userID);  
            } else {  
                $this->userID = floatval($_SESSION['userID']);  
            }  
            $this->userRoles = $this->getUserRoles('ids');  
            $this->buildACL();  
        }  
        function ACL($userID='')  
        {  
            $this->__constructor($userID);  
        } 
    ?>

    Конструктор
    __constructor() предназначен для того, чтобы инициализировать объект при создании экземпляра класса ACL. Он вызывается автоматически после вот этой записи: new ACL();

    Не сразу понял, что логика тут есть, но какая-то кривая

    DmitryDick, 02 Ноября 2014

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

    +140

    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
    type func = function (x : real) : real;
    const
    	eps = 0.0000003;
    	pi = 3.14159265358979;
    function Integral (f : func; a, b : real) : real;
    var center : real;
    begin
    	center := (a + b) / 2;
    	if abs(b - a) < eps then
    		Integral := f(center) * (b - a)
    	else Integral := Integral(f, a, center) + 
    		Integral(f, center, b);
    end;
    function myFunc(x : real) : real;
    begin
    	myFunc := cos(x) / x;
    end;
    begin
    	writeln(Integral(myFunc, pi/2, pi));
    	readln;
    end.

    Толи я дурачек, толи автор кода - школьник....

    ShadowXX, 02 Ноября 2014

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

    +71

    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
    protected boolean valid_move(int from, int to, int aBoard[], int colorfor) {
      if(plainType(colorfor) == userColor) {
        return (to>=0 && to<=35 && from >=0 && from<=35 && plainType(aBoard[from])==colorfor && aBoard[to]==emptyType 
                && ((from-to == 4 || from-to==5) 
                    || ((from-to == 10 && plainType(aBoard[from-5])==oppositeType(colorfor)) 
                        || (from-to == 8 && plainType(aBoard[from-4])==oppositeType(colorfor))) 
                    || (aBoard[from]==kingType(colorfor) 
                        && ((to-from == 4 || to-from==5) 
                            || ((to-from == 10 && plainType(aBoard[from+5])==oppositeType(colorfor)) 
                                || (to-from == 8 && plainType(aBoard[from+4])==oppositeType(colorfor)))))));
      }
      else {
        return (to>=0 && to<=35 && from >=0 && from<=35 && plainType(aBoard[from])==colorfor && aBoard[to]==emptyType 
                && ((to-from == 4 || to-from==5) 
                    || ((to-from == 10 && plainType(aBoard[from+5])==oppositeType(colorfor)) 
                        || (to-from == 8 && plainType(aBoard[from+4])==oppositeType(colorfor))) 
                    || (aBoard[from]==kingType(colorfor) 
                        && ((from-to == 4 || from-to==5) 
                            || ((from-to == 10 && plainType(aBoard[from-5])==oppositeType(colorfor)) 
                                || (from-to == 8 && plainType(aBoard[from-4])==oppositeType(colorfor))))))); // =)))))
      }
    }

    https://github.com/haiming020/BBS-AKB48/blob/master/src/Checkers.java

    zadrot, 01 Ноября 2014

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

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    struct Counter{
    	static int k;
    	Counter(){ k++; }
    	~Counter() { k--; }
    };
    int Counter::k = 0;
    #define LOL(x) {string s = #x; Counter c##x; cout<<s.substr(0,1+s.find('['))<<Counter::k<<"]="<<x<<'\n'; }

    Abbath, 01 Ноября 2014

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

    +145

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function myscandir($dir){
    	if(!file_exists($dir)){
    		return false;
    	}
    
        $list = scandir($dir);
        unset($list[0],$list[1]);
        return array_values($list);
    }

    taras_shs, 31 Октября 2014

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