1. Си / Говнокод #17231

    +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
    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
    bool bitmap_to_24bit_string(bitmap *bmp, char **str, uint32_t *len)
    {
        if (!bmp || !bmp->pixels)
        return false;
        int I, J;
        uint32_t size = ((bmp->width * 24 + 31) / 32) * 4 * bmp->height;
        rgb24 *pixels = malloc(size);
        if (pixels)
        {
            for (I = 0; I < bmp->height; ++I)
            {
                for (J = 0; J < bmp->width; ++J)
                {
                    pixels[I * bmp->width + J].b = bmp->pixels[I * bmp->width + J].r;
                    pixels[I * bmp->width + J].g = bmp->pixels[I * bmp->width + J].g;
                    pixels[I * bmp->width + J].r = bmp->pixels[I * bmp->width + J].b;
                }
            }
            uint32_t destlen = compressBound(size);
            *str = malloc(destlen);
            if (*str)
            {
                if (compress((Bytef *)*str, (uLongf *)&destlen, (Bytef *)pixels, size) == Z_OK)
                {
                    free(pixels);
                    pixels = NULL;
                    char *b64str;
                    uint32_t b64_len;
                    if (base64encode((const uint8_t *)*str, destlen, &b64str, &b64_len))
                    {
                        free(*str);
                        *str = b64str;
                        *len = b64_len + 2;
                        b64str = malloc(*len);
                        if (b64str)
                        {
                            b64str[0] = 'm';
                            strncpy(&b64str[1], *str, b64_len);
                            free(*str);
                            *str = b64str;
                            (*str)[b64_len + 1] = '';
                            return true;
                        }
                    }
                }
                free(*str);
                *len = 0;
                *str = NULL;
            }
            free(pixels);
        }
        return false;
    }

    Ещё подкину в общую копилку

    Cynicrus, 01 Декабря 2014

    Комментарии (1)
  2. JavaScript / Говнокод #17229

    +153

    1. 1
    2. 2
    3. 3
    var getSelectedTabName = function() {
      return $('#costs-category').find('.tabs-v4-i_active').find('.tabs-v4-l').data('category_alias');
    };

    Кто-то ниасилил селекторы в jquery

    fake, 01 Декабря 2014

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

    +101

    1. 1
    2. 2
    string indate =  "01/" + ("0" + CalcActDatePicker.Value.Date.Month.ToString().Trim()).Substring(CalcActDatePicker.Value.Date.Month.ToString().Trim().Length - 1)
                                + "/" + CalcActDatePicker.Value.Date.Year.ToString().Trim();

    Нашел код в проекте, который передал мне уволившийся работник

    progrb, 01 Декабря 2014

    Комментарии (18)
  4. Си / Говнокод #17227

    +136

    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
    char *stringFromDTM(MDTM *dtm)
    {
        if (dtm->count < 1)
        return "";
        uint32_t size = (sizeof(MDTMPoint) + sizeof(uint32_t)) * dtm->count;
        void *data = calloc(1, size);
        uint32_t *ptr = data;
        *(ptr++) = size;
        uint32_t index;
        for (index = 0; index < dtm->count; index++)
        *(ptr++) = dtm->points[index].x;
        for (index = 0; index < dtm->count; index++)
        *(ptr++) = dtm->points[index].y;
        for (index = 0; index < dtm->count; index++)
        *(ptr++) = dtm->points[index].color;
        for (index = 0; index < dtm->count; index++)
        *(ptr++) = dtm->points[index].tol;
        for (index = 0; index < dtm->count; index++)
        *(ptr++) = dtm->points[index].size;
        for (index = 0; index < dtm->count; index++)
        *(ptr++) = dtm->points[index].x;
        bool *bptr = (bool *)ptr;
        for (index = 0; index < dtm->count; index++)
        *(bptr++) = dtm->points[index].bad;
        uint32_t len = compressBound(size);
        char *buffer = malloc(len);
        if (compress((Bytef *)buffer, (uLongf *)&len, data, size) == Z_OK)
        {
            free(data);
            char *compressed = malloc(len + sizeof(uint32_t));
            *((uint32_t *)(compressed)) = len;
            strcpy(compressed + sizeof(uint32_t), buffer);
            free(buffer);
        }
        free(buffer);
        free(data);
        return "";
    }

    Я так и не раскурил, почему так, а не иначе.

    Cynicrus, 01 Декабря 2014

    Комментарии (13)
  5. Python / Говнокод #17226

    −108

    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
    __author__ = 'КотейКККин'
    
    # Комментарий неуместен.
    # О странности автора код сам все скажет.
    
    import random
    the_number = random.randint(1, 20867248)
    print("Поиграем? Я загадал число от 1 до 20867248.")
    print("У вас 1 попытка")
    guess = int(input("Ваше предположение: "))
    if guess != the_number:
        print("Лошара, даже число угадать не можешь. И какой ты 'мужик' после этого...?")
    else:
        print(" O_O ты угадал??? По-любому вангуешь ;)")

    Приобрел недавно ноутбук с рук, но чувак не почистил систему. Нашел на просторах его жестка в папках "обучение"...автор действительно имел незаурядное мышление о_О
    P.S. Минусы ставьте за код, а не мне))

    Nubia_Y, 01 Декабря 2014

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

    +159

    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
    public function asSize($value, $decimals = null, $options = [], $textOptions = [])
        {
            if ($value === null) {
                return $this->nullDisplay;
            }
            list($params, $position) = $this->formatSizeNumber($value, $decimals, $options, $textOptions);
            if ($this->sizeFormatBase == 1024) {
                switch ($position) {
                    case 0:  return Yii::t('yii', '{nFormatted} {n, plural, =1{byte} other{bytes}}', $params, $this->locale);
                    case 1:  return Yii::t('yii', '{nFormatted} {n, plural, =1{kibibyte} other{kibibytes}}', $params, $this->locale);
                    case 2:  return Yii::t('yii', '{nFormatted} {n, plural, =1{mebibyte} other{mebibytes}}', $params, $this->locale);
                    case 3:  return Yii::t('yii', '{nFormatted} {n, plural, =1{gibibyte} other{gibibytes}}', $params, $this->locale);
                    case 4:  return Yii::t('yii', '{nFormatted} {n, plural, =1{tebibyte} other{tebibytes}}', $params, $this->locale);
                    default: return Yii::t('yii', '{nFormatted} {n, plural, =1{pebibyte} other{pebibytes}}', $params, $this->locale);
                }
            } else {
                switch ($position) {
                    case 0:  return Yii::t('yii', '{nFormatted} {n, plural, =1{byte} other{bytes}}', $params, $this->locale);
                    case 1:  return Yii::t('yii', '{nFormatted} {n, plural, =1{kilobyte} other{kilobytes}}', $params, $this->locale);
                    case 2:  return Yii::t('yii', '{nFormatted} {n, plural, =1{megabyte} other{megabytes}}', $params, $this->locale);
                    case 3:  return Yii::t('yii', '{nFormatted} {n, plural, =1{gigabyte} other{gigabytes}}', $params, $this->locale);
                    case 4:  return Yii::t('yii', '{nFormatted} {n, plural, =1{terabyte} other{terabytes}}', $params, $this->locale);
                    default: return Yii::t('yii', '{nFormatted} {n, plural, =1{petabyte} other{petabytes}}', $params, $this->locale);
                }
            }
        }

    Yii продолжает свой крестовый поход против логики. Вам нужно немного другое форматирование, получить именно килобайты вместо кибибайтов? Выставьте какую-то ссаную внутреннюю переменную в значение, отличное от 1024. Да, двойка подойдет, не ссы, ставь.

    Fike, 30 Ноября 2014

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

    −407

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

    Очень жаль всех этих людей, которые вынуждены писать на этом выхлопе от Apple.
    "Мыши плакали, кололись, но продолжали грызть кактус."

    cyperh, 30 Ноября 2014

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

    +160

    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
    <script language=php>
    
    use function yolo\y;
    
    yolo\yolisp(y('yolo\yolo',
        y('lambda', y('request'), 
            y('new', YoLo\resPONsE::clASS, y(
                y('quote', 'yolo')
            ))
        )
    ));
    
    %>

    Микрофреймворк будущего: https://github.com/igorw/yolo

    volter9, 30 Ноября 2014

    Комментарии (0)
  9. JavaScript / Говнокод #17222

    +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
    function kevinTheNumberMentioner(_){
      l=[]
      /* mostly harmless --> */ with(l) {
      	
      	//Sorry about all this, my babel fish has a headache today...
      	for (ll=!+[]+!![];ll<_+(+!![]);ll++) {
      	  lll=+!![];
      	  while (ll%++lll);
      	  //I've got this terrible pain in all the semicolons down my right-hand side
      	  (ll==lll)&&push(ll);
      	}
      	forEach(alert);
      	
      }
      
      //You're really not going to like this...
      return [!+[]+!+[]+!+[]+!+[]]+[!+[]+!+[]];
    }

    Открыл твитор, а там - это.

    http://arstechnica.com/information-technology/2014/11/holiday-reading-for-a-certain-sort-if-hemingway-wrote-javascript/

    Xom94ok, 30 Ноября 2014

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

    +154

    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
    <?
    
    class user
    {
    function login($name, $password)
    {
    $name = mysql_real_escape_string($name);
    $name = htmlspecialchars($name);
    $password = mysql_real_escape_string($password);
    $password = htmlspecialchars($password);
    $sql = mysql_query("SELECT id FROM students WHERE Names='$name' AND Pass='$password'");
    if (mysql_num_rows($sql) == 1)
    {
    $_SESSION['Name'] = $name;
    return 1;
    }
    else
    {
    return 0;
    }
    }

    Код от ТЫЖпрограммиста.

    Mobac, 29 Ноября 2014

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