1. Лучший говнокод

    В номинации:
    За время:
  2. Куча / Говнокод #9545

    +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
    (require 'clsql)
    
    (clsql:file-enable-sql-reader-syntax)
    
    (clsql:connect
     '("localhost" "database" "user" "password")
     :database-type :mysql)
    
    (defun how-many-goods-do-you-have (year month)
      (declare
       (type (integer 2000 2011) year)
       (type (integer 1 12) month))
      (clsql:select [item_id] [sale_date]
    		:from "table"
    		:where [or
    		[is [null [sale_date]]]
    		[< [sale_date]
    		(clsql:sql 'str_to_date\(
    			   (format
    			    nil
    			    "~a-~2,'0d-00"
    			    year month)
    			   '|, '%Y-%m-%d')|
    			   )]]))

    Эксперименты :)

    wvxvw, 26 Февраля 2012

    Комментарии (14)
  3. Куча / Говнокод #9077

    +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
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    (define rsagen
      (lambda ()
         (for-each (lambda (rsa counter)
                     (cond
                      ((> (random) 0.5)
                       (fprintf out-quest "%N=~s, d=~s\n\\item Задача. Криптосистема RSA. Дано: $p=~s,\\ q=~s,\\ e=~s$. Вычислить $N, d$.\n"
                                (third rsa)
                                (fifth rsa)
                                (first rsa)
                               (second rsa)
                               (fourth rsa)
                               
                               ))
                      (else
                       ((lambda (randM) 
                          (fprintf out-quest "%p=~s,q=~s,e=~s,M=~s\n\\item Задача. Криптосистема RSA. Дано: $d=~s,\\ N=~s,\\ C=~s$. Вычислить $M$.\n"
                                   (first rsa)
                                   (second rsa)
                                   (fourth rsa)
                                (rsacrypt randM (fourth rsa) (third rsa))
                                (fifth rsa)
                               (third rsa)
                               randM
                               ))
    
                        ((Y
                          (lambda (checkrand)
                            (lambda (randf)
                              ((lambda (rand)
                                 (cond
                                  ((not (eq? (rsacrypt rand (fourth rsa) (third rsa)) rand))
                                   rand)
                                  (else
                                   (checkrand randf))))
                               (randf)))))
                         (lambda () (- (third rsa) (+ (random (quotient (third rsa) 2)) 1))))
                         
                        )
                        )
                       )
                     )
                   (take (shuffle (getalllistallmany_e (next-primes 7 50) (next-primes 5 10))) 14)
                   (build-list 14 (lambda (x) (+ x 1))))
         ))

    Генерирование заданий по криптосистеме RSA. Обратите внимание на Y комбинатор.

    shem, 11 Января 2012

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

    +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
    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
    #include<conio.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    void main() {
    clrscr();
    int i,j,k=0,n=6,l;
    float x[6],y[6],s[11],t[6],ur[6][7],s1;
    
    x[0]=0.1;   y[0]=0.25;
    x[1]=0.3;   y[1]=0.5;
    x[2]=0.4;   y[2]=0.65;
    x[3]=0.6;   y[3]=0.55;
    x[4]=0.7;   y[4]=0.42;
    x[5]=0.8;   y[5]=0.3;
    
    
    for(i=0;i<6;i++) {
    s[i]=0;
    for(j=0;j<6;j++)
    s[i]+=exp(i*log(x[j]));
    printf("%.2f\n",s[i]);
    
    }
    
    for(i=0;i<6;i++){
    t[i]=0;
    for(j=0;j<6;j++)
    t[i]+=pow(x[j],i)*y[j];}
    
    //----------------------------Gaus-----------------
    for(i=0;i<6;i++)
    for(j=0;j<7;j++)
    ur[i][j]=0;
    
    l=3;
    for(i=0;i<6;i++) {
    k=0;
    for(j=i;j<l;j++){
    
    
    ur[i][k]=s[j];
    k++;}
    
    ur[i][k]=t[i];
    l++;
    }
    n=3;
    ur[0][0]=s[0]; ur[0][1]=s[1]; ur[0][2]=s[2]; ur[0][3]=s[3]; ur[0][4]=s[4]; ur[0][5]=s[5]; ur[0][6]=t[0];
    ur[1][0]=s[1]; ur[1][1]=s[2]; ur[1][2]=s[3]; ur[1][3]=s[4]; ur[1][4]=s[5]; ur[1][5]=s[6]; ur[1][6]=t[1];
    ur[2][0]=s[2]; ur[2][1]=s[3]; ur[2][2]=s[4]; ur[2][3]=s[5]; ur[2][4]=s[6]; ur[2][5]=s[7]; ur[2][6]=t[2];
    ur[3][0]=s[3]; ur[3][1]=s[4]; ur[3][2]=s[5]; ur[3][3]=s[6]; ur[3][4]=s[7]; ur[3][5]=s[8]; ur[3][6]=t[3];
    ur[4][0]=s[4]; ur[4][1]=s[5]; ur[4][2]=s[6]; ur[4][3]=s[7]; ur[4][4]=s[8]; ur[4][5]=s[9]; ur[4][6]=t[4];
    ur[5][0]=s[5]; ur[5][1]=s[6]; ur[5][2]=s[7]; ur[5][3]=s[8]; ur[5][4]=s[9]; ur[5][5]=s[10]; ur[5][6]=t[5];
      
    ur[0][0]=6.0; ur[0][1]=2.90; ur[0][2]=1.75; ur[0][3]=1.16; ur[0][4]=0.81; ur[0][5]=0.59; ur[0][6]=2.67;
    ur[1][0]=2.90; ur[1][1]=1.75; ur[1][2]=1.16; ur[1][3]=0.81; ur[1][4]=0.59; ur[1][5]=0.43; ur[1][6]=1.30;
    ur[2][0]=1.75; ur[2][1]=1.16; ur[2][2]=0.81; ur[2][3]=0.59; ur[2][4]=0.43; ur[2][5]=0.32; ur[2][6]=0.75;
    ur[3][0]=1.16; ur[3][1]=0.81; ur[3][2]=0.59; ur[3][3]=0.43; ur[3][4]=0.32; ur[3][5]=0.24; ur[3][6]=0.47;
    ur[4][0]=0.81; ur[4][1]=0.59; ur[4][2]=0.43; ur[4][3]=0.32; ur[4][4]=0.24; ur[4][5]=0.18; ur[4][6]=0.32;
    ur[5][0]=0.59; ur[5][1]=0.43; ur[5][2]=0.32; ur[5][3]=0.24; ur[5][4]=0.18; ur[5][5]=0.14; ur[5][6]=0.22;
    ...

    Убило реализация степени ввиде exp, и мега инициализация)

    Bogdand, 19 Декабря 2011

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

    +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
    37. 37
    38. 38
    39. 39
    /// <summary>
            /// Abs function
            /// </summary>
            private static object Abs(List<Expression> p)
            {
                return Math.Abs(p[0]);
            }
    
            /// <summary>
            /// Acos function
            /// </summary>
            private static object Acos(List<Expression> p)
            {
                return Math.Acos(p[0]);
            }
    
            /// <summary>
            /// Asin function
            /// </summary>
            private static object Asin(List<Expression> p)
            {
                return Math.Asin(p[0]);
            }
    
            /// <summary>
            /// Atan function
            /// </summary>
            private static object Atan(List<Expression> p)
            {
                return Math.Atan(p[0]);
            }
    
            /// <summary>
            /// Atan2 function
            /// </summary>
            private static object Atan2(List<Expression> p)
            {
                return Math.Atan2(p[0], p[1]);
            }

    Кусок кода от "Капитана Очевидность"

    govnokoder_, 15 Декабря 2011

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

    +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
    public static string FristChar(this string input)
        {
            if (!string.IsNullOrEmpty(input))
            {
                if (input.Length >= 1)
                {
                    return input.Substring(0, 1);
                }
                else
                {
                    return input;
                }
            }
            else
            {
                return null;
            }
        }

    http://www.extensionmethod.net/Details.aspx?ID=170

    Author: Mehrdad Ghasemi

    Killster, 13 Ноября 2011

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

    +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
    static string ContentTypeDecode(string contentTypeName)
            {
                if (contentTypeName.Equals("Поручение")) return "Задание";
                if (contentTypeName.Equals("Поручение с результатом типа текст")) return "Задание с результатом типа текст";
                if (contentTypeName.Contains("Поручение с результатом типа выбор")) return "Задание с результатом типа выбор";
                if (contentTypeName.Equals("Поручение с результатом типа документ")) return "Задание с результатом типа документ";
                if (contentTypeName.Equals("Поручение с результатом типа форма")) return  "Задание с результатом типа форма";
                if (contentTypeName.Equals("Поручение с результатом типа флаг")) return "Задание с результатом типа флаг";
                if (contentTypeName.Equals("Поручение с результатом типа число")) return "Задание с результатом типа число";
                if (contentTypeName.Equals("Поручение с результатом типа дата")) return "Задание с результатом типа дата";
                if (contentTypeName.Equals("Поручение с результатом типа пользователь")) return "Задание с результатом типа пользователь";
                if (contentTypeName.Equals("Поручение с результатом типа список пользователей")) return "Задание с результатом типа список пользователей";
                if (contentTypeName.Equals("Поручение на сканирование")) return "Задание на сканирование";
                if (contentTypeName.Equals("Задача на контроль поручения")) return "Задание на контроль";
                if (contentTypeName.StartsWith("Утверждение документа v3")) return "Утверждение документа";
                if (contentTypeName.StartsWith("Согласование документа v3")) return "Согласование документа";
                if (contentTypeName.StartsWith("Утверждение документа v4")) return "Утверждение документа";
                if (contentTypeName.StartsWith("Согласование документа v4")) return "Согласование документа";
                return null;
            }///string ContentTypeDecode(string ContentTypeName)

    Из реального комерческого проекта

    VasyaPupkin, 02 Ноября 2011

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

    +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
    #include <stdio.h>
    #include <stdlib.h>
    
    #define $ /* */
    
    #define ARGV argv
    
    #define if($x) int main(int argc, char *argv[])
    
    #define $start 1  
    
    #if PERL
     sub atoi { $_[0] }
     $ argc=@ARGV;
     $ start=0;
     $ x=1;
    #endif
    
    if($x)
    {
     int $ sum;
     int $ i;
     
     $ sum=0;
    
     for ( $ i = $start; $ i < $ argc ; $ i++) {
       $ sum += atoi ($ ARGV [$ i]);}
    
     printf("%d\n", $ sum);
    
    exit(0);
    }

    Пришла в голову вот такая вот идея, уже пишу серьезный проект, а вам даю на оценку вот такой вот код.
    Думаю вообще связать это все дело еще и с PHP, вот таким вот образом:
    <?php system('./home/Cuberpunk/private/iGuruCodder/SeriousProject/main 15 12 15'); ?>
    Хотел запостить на Хабр, но нету там аккаунта, поэтому пишу сюда ;)
    Оценивайте, комментируйте. Сейчас работаю над крупным проектом на эту тему, ждите.
    Если кому интересно, то вот моя темка на форуме, где все более подробно описано:
    http://forum.antichat.ru/threadedpost2883414.html

    Cyber-punk, 01 Ноября 2011

    Комментарии (28)
  9. Си / Говнокод #8371

    +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
    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
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    /* ... */
    /**************************************************************************************
      cpu_information () parse /proc/cpuinfo to get information about CPU 
     **************************************************************************************/
    int cpu_information (data* user_data, int pos)
    {
      FILE *cpufp/* /proc/cpuinfo */ /*, *sysfs_max_cpu_freq_fp  /sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq */;
       
      char* ch = (char*)malloc (MAXLEN);
      char* line = (char*)malloc (MAXLEN);
      char* buf = (char*)malloc (MAXLEN);
      
      GtkTreeIter iter[2];
      // int y = 0;
      if ((cpufp = fopen(CPU_INFORMATION_FILE, "r")) == NULL)
        printf ("%s\n", "Error opening /proc/cpuinfo");
    
      while (fgets (ch, MAXLEN, cpufp) != NULL) 
      {
        if (!strncmp (ch, "processor", 9)) 
        {
          sscanf (ch, "%*s %*s %s", line);
          strcpy (buf, "CPU");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[0],NULL, pos, 0, buf, 1, line, -1);
        } else if (!strncmp(ch, "vendor_id", 9))
        {
          sscanf(ch,"%*s %*s %s", line);
          strcpy (buf, "Processor type:");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1); 
        } else if (!strncmp(ch, "model name", 10))
        {
          strcpy(buf, "Model name");
          ch[strlen(ch)-1] = '\0'; //delete '\n' symbol from the end of string
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, &ch[13], -1);
        } else if (!strncmp(ch, "cpu MHz", 7))
        {
          int curr_cpu_freq;
          sscanf(ch, "%*s %*s %*s %d\n", &curr_cpu_freq);
          sprintf(line, "%d", curr_cpu_freq);
          strcpy (buf, "Current Processor Speed in MHz");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line,-1);
          /*
    	 Begin parsing /sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq 
    	 
          sprintf (sysfs_max_cpu_freq_path, SYSFS_CPU_MAX_FREQ_FORMAT_STRING, y);
          if ((sysfs_max_cpu_freq_fp = fopen (sysfs_max_cpu_freq_path, "r")) == NULL) {
        	  printf("%s %s\n", "Error opening",  sysfs_max_cpu_freq_path);
          }
          while (fgets (line, MAXLEN, sysfs_max_cpu_freq_fp) != NULL)
          {
    	sscanf (line, "%d", &max_cpu_freq);
    	sprintf (line, "%d", max_cpu_freq/1000);
    	strcpy (buf, "Max Processor Speed in MHz");
    	gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[2],&iter[1], pos, 0, buf, 1, line,-1);
          }
          y++;
          
    	 End parsing 
           
          fclose (sysfs_max_cpu_freq_fp);*/
        }  else if (!strncmp(ch, "cache size", 10))
        {
          sscanf(ch, "%*s %*s %*s %s", line);
          strcpy (buf, "Processor cache size");
          strcat (line, " KB");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1);
    
        } else if (!strncmp(ch, "bogomips", 8)) 
        {
          sscanf(ch, "%*s %*s %s", line);
          strcpy (buf, "Processor speed in Bogomips");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1);
          cpu_temperature (user_data,&iter[0], pos); //get CPU temperature.
        }
        pos++;
      }
    
      free (buf);
      free (line);
      free (ch);
      //free (sysfs_max_cpu_freq_path);
      fclose (cpufp);
      return 0;
    }
    /* ... */

    По просьбам трудящихся http://govnokod.ru/7979#comment116436

    По коду:
    1) хорошо бы проверять, что попытался выделить;
    2) ошибка произошла успешно — начинаем парсить...;
    3) для решения таких задач стоит обратить своё внимание на, например, PyGTK.

    P.S. Если уж совсем не в мочь и к строкам так тянет,
    то допилите под себя LiteC, у Г.Шилдта есть что подсмотреть.

    sayidandrtfm, 31 Октября 2011

    Комментарии (20)
  10. Куча / Говнокод #7972

    +133

    1. 1
    string file_label = file.local_basename.replace ("_", "__"); // Cute emoticons!

    http://bazaar.launchpad.net/~sikon/steadyflow/trunk/view/head:/Steadyflow/IndicatorController.vala

    lucidfox, 25 Сентября 2011

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    if (ID_Pers == (decimal)r["Код_ФизЛица"])
        query = new SqlCommand("UPDATE СписокФизическихЛиц SET ДатаРождения=CONVERT(DateTime,'" + Date + "',104) where  ID='" + r["Код_ФизЛица"].ToString() + "'", conn);
    else
        query = new SqlCommand("UPDATE СписокФизическихЛиц SET ДатаРождения=CONVERT(DateTime,'" + Date + "',104) where  ID='" + ID_Pers.ToString() + "'", conn);

    Классический говнокод.

    exile, 23 Августа 2011

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