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

    +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
    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
    <?php
    /* Подключаемые файлы */
    require_once('data/config.test.php');
     
    /**
    * Сохранение настроек модуля
    */
    if ($action == "dosave") {
        $find[]     = "'\r'";
        $replace[]  = "";
        $find[]     = "'\n'";
        $replace[]  = "";
     
    if ($member_db[1] != 1) {
        msg ("error", $lang['opt_denied'], $lang['opt_denied']);
    }
    $handler = @fopen('data/config.test.php', "wb");
    fwrite ($handler, "<?php \n\n//Test configurations
                             \n\n\$config_test = array(
                             \n\n'version' => \"v.1.0\",\n\n");
     
    foreach ($save_con as $name => $value) {    
        $value = trim(stripslashes ($value));
        $value = htmlspecialchars  ($value, ENT_QUOTES);
        $value = preg_replace($find, $replace, $value);
        fwrite($handler, "'{$name}' => \"{$value}\",\n\n");
    }
        
    fwrite($handler, ");\n\n?>");
    fclose($handler);
     
    msg ("info", "Строка изменена",
         "{$lang['opt_sysok_1']}<br /><br />
          <a href=\"{$PHP_SELF}?mod=test_adm\">{$lang['db_prev']}</a>");
    }
    echo"Шапка";
    echo<<<HTML
    <form action="" method="POST">
    <table width="100%">
      <tr>
        <td class="option" style="padding:4px;">
          <b> Текст выводимой строки: </b><br />
          <span class="small"> например: Hello world </span>
        <td align="middle" width="400">
          <input class="edit" style="text-align:center" size="40" value="{$config_test['text']}" name="save_con[text]"></td>
      </tr>
      
      <tr>
        <td class="option" style="padding:4px;">
           <b> Комментарий к тексту: </b><br />
           <span class="small"> например: Это ваш первый пример модуля с админпанелью </span>
        <td align="middle" width="400">
           <input class="edit" style="text-align:center" size="40" value="{$config_test['detail']}" name="save_con[detail]"></td>
      </tr>
    
      <tr>
        <td class="option" style="padding-bottom:10px; padding-top:10px; padding-left:10px;" colspan="2">
          <input class="buttons" type="hidden" name="action" value="dosave" />
          <input class="buttons" type="submit" name="do" value=" Сохранить " /></td>
      </tr>
      
    </table>
    </form>
    HTML;
    echo"Подвал";
    ?>

    qbasic, 19 Марта 2011

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

    +170

    1. 1
    2. 2
    3. 3
    4. 4
    void Draw_Pixel_Memset(UINT color,    //color = _RGB32BIT(a,r,g,b) ((b) + ((g) << 8) + ((r) << 16) + ((a) << 24))
                          UINT *buffer){ //buffer =  (UINT*) ddsd.lpSurface
      memset(buffer, color,8); 
    }

    Рисование пикселя с помощью meset()

    Подскажите, пожалуйста, почему при использование этой функции в 32 битном режиме точка получается какового то серого цвета.
    С другой стороны если использовать 8 битный режим то пиксель будет нужного цвета.

    Источник: http://www.gamedev.ru/code/forum/?id=145274

    TarasB, 19 Марта 2011

    Комментарии (18)
  3. JavaScript / Говнокод #6026

    +162

    1. 1
    2. 2
    return vars[v] = ($.inArray(v, wndConfig["out_zero"]) !== -1)
      ? (tmp == 0 ? 0 : tmp) : tmp;

    Из серии "в пятницу вечером". Ладно хоть сейчас перечитал этот кусок и увидел.

    telnet, 19 Марта 2011

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

    +126

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    format MS COFF
    
    public fuckHighLevel as '_fuckHighLevel@4'
    
    fuckHighLevel:
            pop ebx
    
                pop eax
                add eax, 1
    
            jmp ebx

    Вызываем ассемблерную процедуру из Си.
    Вместо retn используем безусловыный переход на адрес возврата.
    Но работает же!

    danilissimus, 19 Марта 2011

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

    +120

    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
    if (clr1 != Color.Black && clr2 != Color.Black)
                {
                    int R1 = clr1.R > clr2.R ? clr1.R - 1 : clr1.R + 1;
                    int R2 = clr1.R < clr2.R ? clr1.R - 1 : clr1.R + 1;
                    int G1 = clr1.G > clr2.G ? clr1.G - 1 : clr1.G + 1;
                    int G2 = clr1.G < clr2.G ? clr1.G - 1 : clr1.G + 1;
                    int B1 = clr1.B > clr2.B ? clr1.B - 1 : clr1.B + 1;
                    int B2 = clr1.B < clr2.B ? clr1.B - 1 : clr1.B + 1;
                    if (R1 > 255) R1 = 255; if (R1 < 0) R1 = 0;
                    if (R2 > 255) R2 = 255; if (R2 < 0) R2 = 0;
                    if (G1 > 255) G1 = 255; if (G1 < 0) G1 = 0;
                    if (G2 > 255) G2 = 255; if (G2 < 0) G2 = 0;
                    if (B1 > 255) B1 = 255; if (B1 < 0) B1 = 0;
                    if (B2 > 255) B2 = 255; if (B2 < 0) B2 = 0;
    
                    outp.b = Color.FromArgb(R1, G1, B1); outp.a = Color.FromArgb(R2, G2, B2);
                }

    Нашёл у себя такого красавца годичной давности - суровое "плавное" целочисленное интерполирование двух цветов для Compact Framework.

    RaZeR, 19 Марта 2011

    Комментарии (1)
  6. Pascal / Говнокод #6023

    +99

    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
    var
      i,c,b,f:integer;
      str:string;
    procedure TForm1.codir;
    begin
    b:=1;
    f:=1;
    c:=length(edit1.Text);
    str:=edit1.Text;
    repeat
    i:=ord(str[f]);
    case i of
    0:inc(i);
    1:inc(i);
    2:inc(i);
    3:inc(i);
    4:inc(i);
    5:inc(i);
    6:inc(i);
    7:inc(i);
    8:inc(i);
    9:i:=0;
    end;
    
    Delete(str, b, 1);
    Insert(inttostr(i),str,b);
    inc(b);
    inc(f);
    until b=c;
    edit2.Text:=str;
    end;

    bugmenot, 19 Марта 2011

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

    +168

    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
    #include <iostream>
    using namespace std;
    void main()
    {
        char U='#';
    int K;
        _asm
        {
            mov eax, 0
            mov al, U
            mov K,eax
        }
        cout<<K<<endl;
    }

    "Получение десятичного представления числа". C wasm.ru

    rat4, 18 Марта 2011

    Комментарии (14)
  8. C++ / Говнокод #6021

    +167

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    PopupWindow* GameLocations::getCurrentPopup()
    {
    	if(m_curPopup != nullptr && m_curPopup->needsClose())
    	{
    		m_curPopup->onClose();
    		m_curPopup = nullptr;
    		m_walker->BeginWalk(m_graph->getClosestNode(m_currentLocationId));
    	}
    	return m_curPopup;
    }

    Kirinyale, 18 Марта 2011

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

    +114

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if (defaultOrderType == OrderType.NoCharge || defaultOrderType == OrderType.Claims)
    {
        noChargeItemEntry.Style.Add(HtmlTextWriterStyle.Display, "block");
        itemEntryPanel.Style.Add(HtmlTextWriterStyle.Display, "none");
        items.Style.Add(HtmlTextWriterStyle.Display, "none");
    }
    else
    {
        noChargeItemEntry.Style.Add(HtmlTextWriterStyle.Display, "none");
        itemEntryPanel.Style.Add(HtmlTextWriterStyle.Display, "block");
        items.Style.Add(HtmlTextWriterStyle.Display, "block");
    }

    abatishchev, 18 Марта 2011

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

    +116

    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
    // Method that returns anonymous type as object
    object ReturnAnonymous() {
      return new { City="Prague", Name="Tomas" };
    }
    
    void Main() {
      // Get instance of anonymous type with 'City' and 'Name' properties
      object o = ReturnAnonymous();
    
      // This call to 'Cast' method converts first parameter (object) to the
      // same type as the type of second parameter - which is in this case 
      // anonymous type with 'City' and 'Name' properties
      var typed = Cast(o, new { City="", Name="" });
      Console.WriteLine("{0}, {1}", typed.City, typed.Name)
    }
    
    // Cast method - thanks to type inference when calling methods it 
    // is possible to cast object to type without knowing the type name
    T Cast<T>(object obj, T type) {
      return (T)obj;
    }

    via http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/c1c179bb-ea88-4633-970a-947f0dd1e71f/

    Jopa123, 18 Марта 2011

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