1. Python / Говнокод #11284

    −93

    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
    # -*- coding: utf-8 -*-
    from django.db import models
    
    # Create your models here.
    
    class SheduleItem(models.Model):
      WIKDI = (
        ('monday', 'Понедельник'),
        ('tuesday', 'Вторник'),
        ('wednesday', 'Среда'),
        ('thursday', 'Четверг'),
        ('friday', 'Пятница'),
        ('saturday', 'Суббота'),
        ('sunday', 'Воскресенье'),
      )
      TAIM = (
        ('08:00', '08:00'),
        ('09:00', '09:00'),
        ('10:00', '10:00'),
        ('11:00', '11:00'),
        ('12:00', '12:00'),
        ('13:00', '13:00'),
        ('14:00', '14:00'),
        ('15:00', '15:00'),
        ('16:00', '16:00'),
        ('17:00', '17:00'),
        ('18:00', '18:00'),
        ('19:00', '19:00'),
        ('20:00', '20:00'),
        ('21:00', '21:00'),
      )
      weekday = models.CharField(max_length=20, choices=WIKDI)
      time = models.CharField(max_length=6, choices=TAIM)
      action = models.CharField(max_length=30)
      trainer = models.ForeignKey('trainers.StrongTrainer')
    
      def __unicode__(self):
        return self.action

    Django-модель для таблицы расписания занятий. Выдавлено в 2 часа ночи под Сержа Танкяна.

    fat0troll, 24 Июня 2012

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

    +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
    function group_sorting_ABC(array, mode)
    {
        var arr = [],
            resArray = [],
            add;
        for (var i = 0; i < array.length; i++)
        {
            var key;
            if (array[i].index && mode == 'index')
            {
                switch (array[i].index.toString().length)
                {
                case 1:
                    add = '00';
                    break;
                case 2:
                    add = '0';
                    break;
                case 3:
                    add = '';
                    break;
                }
                key = add + array[i].index;
            }
            else
            {
                key = array[i].name;
            }
            arr.push(key + '@' + i);
        }
        arr = arr.sort();
        for (var i = 0; i < arr.length; i++)
        {
            var a = arr[i].split('@');
            var item = array[a[1]];
            resArray.push(item);
        }
        return resArray;
    }

    Наковырял в middleware set top box-а MAG-250.

    vovams, 23 Июня 2012

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

    −45

    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
    #include <iostream>
    #include <conio.h>
     
    using namespace std;
     
    void iswap(int &n1, int &n2)
    {
        int temp = n1;
        n1 = n2;
        n2 = temp;
    }
     
    int main()
    {
        int const n = 100;
        int a[n];
        for ( int i = 0; i < n; ++i ) { a[i] = n - i; cout << a[i] << " "; }
            //заполняем массив для наглядности.
            //-----------сортировка------------// 
            //сортирует по-возрастанию. чтобы настроить по-убыванию, 
            //поменяйте знаки сравнения в строчках, помеченных /*(знак)*/
        int sh = 0; //смещение
        bool b = false;
        for(;;)
        {
            b = false;
            for ( int i = 0; i < n; i++ )
            {
                if( i * 2 + 2 + sh < n )
                {
                    if( ( a[i + sh] > /*<*/ a[i * 2 + 1 + sh] ) || ( a[i + sh] > /*<*/ a[i * 2 + 2 + sh] ) )
                    {
                        if ( a[i * 2 + 1 + sh] < /*>*/ a[i * 2 + 2 + sh] ) 
                        {
                            iswap( a[i + sh], a[i * 2 + 1 + sh] );
                            b = true;
                        }
                        else if ( a[i * 2 + 2 + sh] < /*>*/ a[ i * 2 + 1 + sh]) 
                             {
                                 iswap( a[ i + sh], a[i * 2 + 2 + sh]);
                                 b = true;
                             }
                    }
                }
                else if( i * 2 + 1 + sh < n )
                     {
                         if( a[i + sh] > /*<*/ a[ i * 2 + 1 + sh] )
                         {
                             iswap( a[i + sh], a[i * 2 + 1 + sh] );
                             b = true;
                         }
                     }
            }
            if (!b) sh++; //смещение увеличивается, когда на текущем этапе 
                          //сортировать больше нечего
            if ( sh + 2 == n ) break; 
        }  //конец сортировки
     
     
        cout << endl << endl;
        for ( int i = 0; i < n; ++i ) cout << a[i] << " "; 
     
     
        _getch();
        return 0;
    }

    Запостил как-то на вики как более короткая реализация с++, более понятная и главное - рабочая. Не признали. Сам смотрю - не понимаю че там написано )))

    idec, 23 Июня 2012

    Комментарии (58)
  4. PHP / Говнокод #11281

    +50

    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
    <?php
    		
    		$confs = array();
    		
    		$q = new WP_Query(array('post_type' => 'conference',
    					'posts_per_page' => -1,
    					'meta_key' => 'cd-conference-date-start',
    					'orderby' => 'meta_value_num',
    					'order' => 'DESC'
    					));
    		while($q->have_posts()): $q->the_post();
    		$confs[date("Y", get_post_meta($post->ID, 'cd-conference-date-start', true))][] = array('conf_title' => get_the_title(),
    												      'conf_date_start' => get_post_meta($post->ID, 'cd-conference-date-start', true),
    												      'conf_date_end' => get_post_meta($post->ID, 'cd-conference-date-end', true),
    												      'conf_link' => get_permalink(),
    												      'conf_city' => '', /* Город */
    												      'conf_icon' => '' /* Иконка */
    												      );
    		endwhile;
    
    		wp_reset_postdata();
    		
    		foreach($confs as $key => $value)
    		{
    		?>
                    <h1 class="year"><?=$key;?></h1>
    		<?php
    		//print_r($value);
    		?>
                    <div class="conferences">
    		  <?php foreach($value as $val)
    		  {
    		  //print_r($val);
    		  ?>
                      <div class="conf">
                        <div class="leftcol">
                          <a href="<?=$val["conf_link"];?>"><img src="<?=$val["conf_icon"];?>"></a>
                        </div>
                        <div class="rightcol">
                          <a href="<?=$val["conf_link"];?>"><h2><?=$val["conf_title"];?></h2></a>
                          <span class="date-place">
    			<?php
    			//setlocale(LC_TIME, "ru_RU");
    			if(date("m", $val["conf_date_start"]) == date("m", $val["conf_date_end"])) $confdays = date("j", $val["conf_date_start"])."-".date("j", $val["conf_date_end"])." ".mb_strtolower(strftime("%B", $val["conf_date_start"]));
    			else
    			{
    				$confdays = date("j", $val["conf_date_start"])." ".mb_strtolower(strftime("%B", $val["conf_date_start"]))." - ".date("j", $val["conf_date_end"])." ".mb_strtolower(strftime("%B", $val["conf_date_end"]));
    			}
    			?>
    			<?=$confdays;?>, <?=$val["conf_city"];?>
    		      </span>
                        </div>
                      </div>
    		  <?php
    		  }
    		  ?>
                    </div>
    		
    		<?php } ?>

    varg242, 23 Июня 2012

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

    +130

    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
    int print_entry(const char* name, const char* dir,const struct stat* st)
    {
      if(!S_ISDIR(st->st_mode)){
          if(S_ISREG(st->st_mode)){
            printf("<file type=\"regular file\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          };
          if(S_ISCHR(st->st_mode)){
            printf("<file type=\"charcter device\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          }
          if(S_ISBLK(st->st_mode)){
            printf("<file type=\"block device\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          }
          if(S_ISFIFO(st->st_mode)){
            printf("<file type=\"FIFO(named pipe)\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          }
          if(S_ISLNK(st->st_mode)){
             char *linkname;
             ssize_t r;
             char *lname=strcat(dir,"");
             linkname =  new char[st->st_size + 1];
             if (linkname == NULL) {
                fprintf(stderr, "insufficient memory\n");
                exit(EXIT_FAILURE);
             }
            r=readlink(lname, linkname, st->st_size + 1);
            if (r < 0) {
              return 0;
            }
               if (r > st->st_size) {
            fprintf(stderr, "symlink increased in size "
                            "between lstat() and readlink()\n");
            exit(EXIT_FAILURE);
        }
    
            linkname[st->st_size] = '\0';
            printf("<file type=\"symbolic link\" owner=\"%d\" group=\"%d\" linkname=\"%s\">%s/%s</file>\n",st->st_uid,st->st_gid,linkname,dir,name);
          }
          if(S_ISSOCK(st->st_mode)){
            printf("<file type=\"socket\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          }
        }
        return 0;
    }
     
    int main(int argc, char* argv[])
    {
    if(argc != 2)
        {
        fprintf(stderr, "Usage: %s DIR\n", argv[0]);
        exit(1);
        }
        printf("<dir name=\"%s\">\n",argv[1]);
        walk(argv[1], print_entry, 1,0);
        printf("</dir>",argv[1]);
    }

    Создание xml файла всех директорий, поддиректорий и их файлов

    AliceGoth, 22 Июня 2012

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

    +45

    1. 1
    $ApsolutePath = $_SERVER['DOCUMENT_ROOT']; # Абсолютный путь до сайта (автоматическое определение корневой директории)

    $ApsolutePath - Ну как? КАК?

    domaster, 22 Июня 2012

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

    +66

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // Масив с выбором
    if ($type=="textAr") {
    	foreach ($stext as $key=>$row) {
    		if ($key==$data) {
    			return $row;
    			break;
    		}
    	}
    }

    Кто-то тролит хостинг...
    Заменено на if ('textAr'==$type && isset($stext[$data]) ) return $stext[$data];

    domaster, 22 Июня 2012

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

    +66

    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
    // text
    if ($type=="text") {
    	[skip]
    }
    
    // order
    if ($type=="order") {
    	[skip]
    }
    
    // select
    if ($type=="select") {
    	[skip]
    }
    
    // chekbox
    if ($type=="chekbox") {
    	[skip]
    }

    Таких проверок штук 20. Коментарии на всех соответствующие.

    domaster, 22 Июня 2012

    Комментарии (23)
  9. Куча / Говнокод #11276

    +142

    1. 1
    <a href="tariff.php">Расчет тарифа</a>

    dos_, 21 Июня 2012

    Комментарии (9)
  10. Perl / Говнокод #11275

    −124

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    > cat 1.pl
    $owner = "Jack";
    print "This is $owner\n";
    print "This is $owner's house\n";
    >  perl 1.pl
    This is Jack
    This is  house

    The old package delimiter was a single quote, but double colon is now the preferred delimiter, in part because it's more readable to humans, and in part because it's more readable to emacs macros. It also makes C++ programmers feel like they know what's going on--as opposed to using the single quote as separator, which was there to make Ada programmers feel like they knew what was going on. Because the old-fashioned syntax is still supported for backwards compatibility, if you try to use a string like "This is $owner's house" , you'll be accessing $owner::s ; that is, the $s variable in package owner , which is probably not what you meant. Use braces to disambiguate, as in "This is ${owner}'s house" .

    bormand, 21 Июня 2012

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