1. C++ / Говнокод #9956

    +155

    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
    int main() {
        
        float a = 3.14;
        
        asm volatile (
                        "decl   %%esp"                      "\n\t"
                        "movb   $0, (%%esp)"                "\n\t"
                        "decl   %%esp"                      "\n\t"
                        "movb   $'\n', (%%esp)"             "\n\t"
                        "movl   $32, %%eax"                 "\n"
            "label0:"                                       "\n\t"
                        "shrl   %[A]"                       "\n\t"
                        "decl   %%esp"                      "\n\t"
                        "jc     label1"                     "\n\t"
                        "movb   $'0', (%%esp)"              "\n\t"
                        "jmp    label2"                     "\n"
            "label1:"                                       "\n\t"
                        "movb   $'1', (%%esp)"              "\n\t"
            "label2:"                                       "\n\t"
                        "decl   %%eax"                      "\n\t"
                        "cmpl   $0, %%eax"                  "\n\t"
                        "ja     label0"                     "\n\t"
                                                            "\n\t"
                        "pushl  %%esp"                      "\n\t"
                        "call   printf"                     "\n\t"
                                                            "\n\t"
                        "addl   $38, %%esp"                 "\n"
            
            : /* no output registers */
            : [A] "r" (a)
            : "%esp", "%eax"
        );
        
        return 0;
    }

    float > bin

    igoreknog, 16 Апреля 2012

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

    +1002

    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
    void TExternalIOBuffer::swap(TExternalIOBuffer& Buffer)
    {
    	ASSERT(typeid(Buffer)==typeid(TExternalIOBuffer));
    	const TExternalIOBuffer CurrentBuffer=*this;
    	const TExternalIOBuffer OtherBuffer=Buffer;
    	Buffer.~TExternalIOBuffer();
    	::new((void*)&Buffer) TExternalIOBuffer(CurrentBuffer);
    	this->~TExternalIOBuffer();
    	::new((void*)this) TExternalIOBuffer(OtherBuffer);
    };
    
    const TExternalIOBuffer& TExternalIOBuffer::operator=(const TAbstractIOBuffer& Buffer)
    {
    	this->~TExternalIOBuffer();
    	::new((void*)this)TExternalIOBuffer(Buffer);
    	return *this;
    };

    Большой проект, попало в релиз.

    Говногость, 16 Апреля 2012

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

    +117

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    static double E( double epsilon )
    {
    	int n = 1, nf = 1;
    	double e = 0;
    	while (Math.Abs(e - Math.E) > epsilon)
    	{
    		e += 1.0 / nf;
    		nf *= n;
    		n++;
    	}
    	return e;
    }

    Вычисление числа e как суммы обратных факториалов. По мотивам реальных событий.

    Steve_Brown, 16 Апреля 2012

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

    +128

    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
    #ifndef __KERNEL__
    /* Multicast groups - backwards compatiblility for userspace */
    #define SELNL_GRP_NONE		0x00000000
    #define SELNL_GRP_AVC		0x00000001	/* AVC notifications */
    #define SELNL_GRP_ALL		0xffffffff
    #endif
    
    enum selinux_nlgroups {
    	SELNLGRP_NONE,
    #define SELNLGRP_NONE	SELNLGRP_NONE
    	SELNLGRP_AVC,
    #define SELNLGRP_AVC	SELNLGRP_AVC
    	__SELNLGRP_MAX
    };
    #define SELNLGRP_MAX	(__SELNLGRP_MAX - 1)

    Linux 3.3.0
    include/linux/selinux_netlink.h

    myaut, 15 Апреля 2012

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    foreach ($items as $item_id)
    {
        if ((int)$item_id<=0)
            die();
        // ...
        if (!$redis->sIsMember("views_today_stats_sadd:{$views_stats_namespace}",$key))
            $redis->sAdd("views_today_stats_sadd:{$views_stats_namespace}",$key);
        // ...
    }

    Пехепешник второго уровня: циклы уже осилил, а вот с множествами пока не разобрался.

    roman-kashitsyn, 14 Апреля 2012

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

    +154

    1. 1
    2. 2
    3. 3
    escape = function(string) {
        return (''+string).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/\//g,'&#x2F;');
      };

    Ваше мнение?

    __proto__, 14 Апреля 2012

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

    +1004

    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
    long base64::rlong (char * source)
    {
        long res = 0;
        for (int i = 0; i < 4; i++) ((char *) &res)[3 - i] = source[i];
        return res;
    }
    
    void base64::encode (char * source, char * dest)
    {
        char base[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
        int n = 0;
        for (int nd = 0; nd < ceil(4*((double)strlen(source))/3); nd++)
            dest[n++] = base[rlong(&source[((nd >> 2) << 2)*3 >> 2]) >> (26 - 6*(nd - ((nd >> 2) << 2))) & 0x3F]; 
        for (int i = 0; i < ((int) ceil(((double)n)/4) << 2) - n; i++) dest[n++] = '=';
        dest[n] = 0;
    }

    Ответ преподу по c++. Переводстроки в base64.

    antonymus, 14 Апреля 2012

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

    +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
    #include <stdio.h>
    
    float abs(float a) { return a > 0 ? a : -a; }
    
    int main() {
        float x, e, step = 1, summ = step;
        int i = 0;
        
        scanf("%f, %f", (printf("x, e: "), &x), &e);
        
        do summ += (abs(step *= x / ++i) > e) ? step : 0; while (abs(step) > e);
        
        printf("summ = %f\n", summ);
        
        return 0;
    }

    вычисление суммы ряда (1 + x/1! + x^2/2! + ... + x^n/n!), с заданной точностью

    igoreknog, 14 Апреля 2012

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

    +149

    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
    $USER_ID = $_GET['user_id']; 
          $API_METHOD = $_GET['method']; 
          
          $Errors = array('Error#001' => 'Undefined data in request!');
          
          switch($API_METHOD)
          {
            case 'get_user_name_by_id':
              echo EncodeJSON(UserAPI::GetUserNameByID($USER_ID));
              break;  
              
            case 'get_user_status_by_id':
              echo EncodeJSON(UserAPI::GetUserStatusByID($USER_ID));
              break;
                
            default:
              echo $Errors['Error#001'];
              break; 
          }
            class UserAPI //test
            {
               function GetUserNameByID($ID)
               {
                  $SqlQuery = mysql_query("SELECT displayname FROM engine4_users WHERE user_id='$ID'");
                  $Response = mysql_fetch_array($SqlQuery);
                  $Result = array('UserName'=>$Response['displayname']);
                  return $Result;
               }
               
               function GetUserStatusByID($ID)
               {
                  $SqlQuery = mysql_query("SELECT status FROM engine4_users WHERE user_id='$ID'");
                  $Response = mysql_fetch_array($SqlQuery);
                  $Result = array('UserStatus'=>$Response['status']);
                  return $Result; 
               }
            }
            
            function EncodeJSON($arr) {
            $parts = array();
            $is_list = false;
            
            if (!is_array($arr)) return;
            if (count($arr)<1) return '{}';
            $keys = array_keys($arr);
            $max_length = count($arr); 
                    
            if(($keys[0] == 0) and ($keys[$max_length] == $max_length)) {
                $is_list = true;
                for($i=0; $i<count($keys); $i++) { 
                    if($i != $keys[$i]) { 
                        $is_list = false; 
                        break;
                    }
                }
            }
            foreach($arr as $key=>$value) {
                if(is_array($value)) { 
                    if($is_list) $parts[] = array2json($value);
                    else $parts[] = '"' . $key . '":' . array2json($value);
                } else {
                    $str = '';
                    if(!$is_list) $str = '"' . $key . '":';
                    if(is_numeric($value)) $str .= $value; 
                    elseif($value === false) $str .= 'false'; 
                    elseif($value === true) $str .= 'true';
                    else $str .= '"' . addslashes($value) . '"';
                    $parts[] = $str;
                }
            }
            $json = implode(',',$parts);
            if($is_list) return '[' . $json . ']';
            return '{' . $json . '}';
        }

    Удивительное рядом.

    Govnisti_Diavol, 14 Апреля 2012

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (!$_GET['nocache']) {
      $use_caching=0; // use cache?
     } else {
      $use_caching=0;
     }

    ReckO, 14 Апреля 2012

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