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

    +158

    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
    /*	С этого момента начинается чудо, не спрашивайте меня как это работает,
    				я сам не в курсе, но смысл вот в чём: Надо резануть строку по длине... 
    				Говоно вопрос?! А нет, надо чтобы резалось по пробелу... Фигня? Надо, чтобы 
    				нормально учитывались ссылки в тексте... Уже лучше? А это ещё не всё... надо, чтобы
    				Нормально обрабатывались теги в тексте, которые как оказалось могут присутствовать.
    				
    				Ну и работаем как обычно :) Дедлайн прошёл неделю назад, ТЗ по мере выполнения
    				менялось раза 3, пришлось ещё покреативить и поверстать... вот так и живём :)
    				
    				Вы не поверите... но чудо не пришлось по вкусу, придётся его выключить и забыть про него :(
    				
    				Вы снова не поверите, чудо опять нужно!!! Захотели опять спойлеры, 1000 символов и прочие 
    				плюшки *facepalm* Хорошо, что многое закомментил, не придётся заново всё делать
    				
    			*/
    			function cutfunct($string, $length) {
    				$cache = $string;
    				$string = mb_substr($string, 0, $length,'UTF-8');
    				$length += mb_strlen($string, "UTF-8")-mb_strlen(strip_tags($string), "UTF-8");
    				
    				if($string != $cache){
    					$position = mb_strrpos($string, ' ', 'UTF-8'); 
    					$string = mb_substr($string, 0, $position, 'UTF-8');
    				}
    				return $string;
    			}
    			/*ЧУДО OFF*/

    UncaughtException, 02 Декабря 2014

    Комментарии (22)
  2. PHP / Говнокод #17235

    +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
    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
    <? 
    if($res=='1') {  include('str/1.txt') ; } 
    if($res=='2') {  include('str/2.txt') ; } 
    if($res=='3') {  include('str/3.txt') ; } 
    if($res=='4') {  include('str/4.txt') ; } 
    if($res=='5') {  include('str/5.txt') ; } 
    if($res=='6') {  include('str/6.txt') ; } 
    if($res=='7') {  include('str/7.txt') ; } 
    if($res=='8') {  include('str/8.txt') ; } 
    if($res=='9') {  include('str/9.txt') ; } 
    if($res=='10') {  include('str/10.txt') ; } 
    if($res=='11') {  include('str/11.txt') ; } 
    if($res=='12') {  include('str/12.txt') ; } 
    if($res=='13') {  include('str/13.txt') ; } 
    if($res=='14') {  include('str/14.txt') ; } 
    if($res=='15') {  include('str/15.txt') ; } 
    if($res=='16') {  include('str/16.txt') ; } 
    if($res=='17') {  include('str/17.txt') ; } 
    if($res=='18') {  include('str/18.txt') ; } 
    if($res=='19') {  include('str/19.txt') ; } 
    if($res=='20') {  include('str/20.txt') ; } 
    if($res=='21') {  include('str/21.txt') ; } 
    if($res=='22') {  include('str/22.txt') ; } 
    if($res=='23') {  include('str/23.txt') ; } 
    if($res=='24') {  include('str/24.txt') ; } 
    if($res=='25') {  include('str/25.txt') ; } 
    if($res=='26') {  include('str/26.txt') ; } 
    if($res=='27') {  include('str/27.txt') ; } 
    if($res=='28') {  include('str/28.txt') ; } 
    if($res=='29') {  include('str/29.txt') ; } 
    if($res=='30') {  include('str/30.txt') ; } 
    if($res=='31') {  include('str/31.txt') ; } 
    if($res=='32') {  include('str/32.txt') ; } 
    if($res=='33') {  include('str/33.txt') ; } 
    if($res=='34') {  include('str/34.txt') ; } 
    if($res=='35') {  include('str/35.txt') ; } 
    if($res=='36') {  include('str/36.txt') ; } 
    if($res=='37') {  include('str/37.txt') ; } 
    if($res=='38') {  include('str/38.txt') ; } 
    if($res=='39') {  include('str/39.txt') ; } 
     if($res=='42') { include('guest_moder.php');} 
    ?>

    Подключение файла ресурса.
    http://phpforum.su/index.php?showtopic=0&view=findpost&p=29 91766
    Товарисч продает сайт за 90 тыщ рубрей.

    kamanch, 02 Декабря 2014

    Комментарии (74)
  3. Си / Говнокод #17234

    +133

    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
    bool findImageToleranceIn(CTSInfo *info, bitmap *imageToFind, int32_t *x, int32_t *y, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint16_t tolerance)
    {
        int I, J, XX, YY;
        info->tol = tolerance;
        int dX = (x2 - x1) - (imageToFind->width - 1);
        int dY = (y2 - y1) - (imageToFind->height - 1);
        for (I = 0; I < dY; ++I)
        {
            for (J = 0; J < dX; ++J)
            {
                for (YY = 0; YY < imageToFind->height; ++YY)
                {
                    for (XX = 0; XX < imageToFind->width; ++XX)
                    {
                        rgb32* pixel = &imageToFind->pixels[YY * imageToFind->width + XX];
                        rgb32* targetPixel = &info->targetImage->pixels[(YY + I) * info->targetImage->width + (XX + J)];
                        if (pixel->a != 0)
                        {
                            if (!(*info->ctsFuncPtr)(info, pixel, targetPixel))
                            {
                                goto Skip;
                            }
                        }
                    }
                }
                *x = J + x1;
                *y = I + y1;
                return true;
                Skip:
                continue;
            }
        }
        *x = -1;
        *y = -1;
        return false;
    }

    В чём здесь сакральный смысл GoTo?

    Cynicrus, 01 Декабря 2014

    Комментарии (4)
  4. Pascal / Говнокод #17233

    +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
    Procedure ArrDataToRawImage(Ptr: PRGB32; Size: TPoint; out RawImage: TRawImage);
    Begin
    RawImage.Init; { Calls raw.Description.Init as well }
    RawImage.Description.PaletteColorCount:=0;
    RawImage.Description.MaskBitsPerPixel:=0;
    RawImage.Description.Width := Size.X;
    RawImage.Description.Height:= Size.Y;
    RawImage.Description.Format := ricfRGBA;
    RawImage.Description.ByteOrder := riboLSBFirst;
    RawImage.Description.BitOrder:= riboBitsInOrder; // should be fine
    RawImage.Description.Depth:=24;
    RawImage.Description.BitsPerPixel:=32;
    RawImage.Description.LineOrder:=riloTopToBottom;
    RawImage.Description.LineEnd := rileDWordBoundary;
    RawImage.Description.RedPrec := 8;
    RawImage.Description.GreenPrec:= 8;
    RawImage.Description.BluePrec:= 8;
    RawImage.Description.AlphaPrec:=0;
    RawImage.Description.RedShift:=16;
    RawImage.Description.GreenShift:=8;
    RawImage.Description.BlueShift:=0;
    RawImage.DataSize := RawImage.Description.Width * RawImage.Description.Height
    * (RawImage.Description.bitsperpixel shr 3);
    RawImage.Data := PByte(Ptr);
    End;

    with ... do? Не. не слышал.

    Cynicrus, 01 Декабря 2014

    Комментарии (45)
  5. Pascal / Говнокод #17232

    +90

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    function TMFinder.FindDTMs(DTM: TMDTM; out Points: TPointArray; x1, y1, x2, y2, maxToFind: Integer): Boolean;
    var
      Len: integer;
      DPoints: PMDTMPoint;
      b: array of array of Integer;
      ch: array of array of integer;
      W, H: integer;
      MA: TBox;
      MaxX, MaxY: integer;
      xx, yy: integer;
      i, xxx, yyy: Integer;
      StartX, StartY, EndX, EndY: integer;
      cd: TPRGB32Array;
      PtrData: TRetData;
      pc: Integer = 0;
      Found: boolean;
      goodPoints: array of Boolean;
      col_arr, tol_arr: array of Integer;
      ctsinfoarray: TCTSInfoArray;
      compare: TCTSCompareFunction;
    label
      theEnd;
    begin
      MA := ValidMainPointBox(DTM, x1, y1, x2, y2);
      Len := dtm.Count;
      DPoints := dtm.PPoints;
      setlength(goodPoints, Len);
      for i := 0 to Len - 1 do
        goodPoints[i] := not DPoints[i].bp;
      W := x2 - x1;
      H := y2 - y1;
      setlength(b, (W + 1));
      setlength(ch, (W + 1));
      for i := 0 to W do
      begin
        setlength(ch[i], (H + 1));
        FillChar(ch[i][0], SizeOf(Integer) * (H + 1), 0);
        setlength(b[i], (H + 1));
        FillChar(b[i][0], SizeOf(Integer) * (H + 1), 0);
      end;
      PtrData := TClient(Client).IOManager.ReturnData(x1, y1, W + 1, H + 1);
      SetLength(col_arr, Len);
      SetLength(tol_arr, Len);
      for i := 0 to Len - 1 do
      begin
        col_arr[i] := DPoints[i].c;
        tol_arr[i] := DPoints[i].t;
      end;
      ctsinfoarray := Create_CTSInfoArray(col_arr, tol_arr);
      compare := Get_CTSCompare(Self.CTS);
      cd := CalculateRowPtrs(PtrData, h + 1);
      MA.x1 := MA.x1 - x1;
      MA.y1 := MA.y1 - y1;
      MA.x2 := MA.x2 - x1;
      MA.y2 := MA.y2 - y1;
      MaxX := x2 - x1;
      MaxY := y2 - y1;
      for yy := MA.y1 to MA.y2 do
        for xx := MA.x1 to MA.x2 do
        begin
          for i := 0 to Len - 1 do
          begin
            Found := false;
            StartX := max(0, xx - DPoints[i].asz + DPoints[i].x);
            StartY := max(0, yy - DPoints[i].asz + DPoints[i].y);
            EndX := Min(MaxX, xx + DPoints[i].asz + DPoints[i].x);
            EndY := Min(MaxY, yy + DPoints[i].asz + DPoints[i].y);
            for xxx := StartX to EndX do
            begin
              for yyy := StartY to EndY do
              begin
                if ch[xxx][yyy] and (1 shl i) = 0 then
                begin
                  ch[xxx][yyy] := ch[xxx][yyy] or (1 shl i);
                  if compare(ctsinfoarray[i], @ cd[yyy][xxx]) then
                    b[xxx][yyy] := b[xxx][yyy] or (1 shl i);
                end;
                if (b[xxx][yyy] and (1 shl i) <> 0) then
                begin
                  if GoodPoints[i] then
                  begin
                    Found := true;
                    break;
                  end
                  else
                    goto AnotherLoopEnd;
                end;
              end;
              if Found then
                Break;
            end;
            if (not found) and (GoodPoints[i]) then
              goto AnotherLoopEnd;
          end;
          ClientTPA[pc] := Point(xx + x1, yy + y1);
          Inc(pc);
          if (pc = maxToFind) then
            goto theEnd;
        end;
      TheEnd: Free_CTSInfoArray(ctsinfoarray);

    Охх...читать такое - можно и мозг повредить.

    Cynicrus, 01 Декабря 2014

    Комментарии (0)
  6. Си / Говнокод #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)
  7. 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)
  8. 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)
  9. Си / Говнокод #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)
  10. 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)