1. C# / Говнокод #17489

    +95

    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
    double[,] ThreadMatrixMult(int size, double[,] m1, double[,] m2)
            {
                double[,] result = new double[size, size];
                var threads = new List<Thread>(size);
                for (int i = 0; i < size; i++)
                {
                    var t = new Thread( ti =>
                    {
                        int ii = (int)ti;
                        for (int j = 0; j < size; j++)
                        {
                            result[ii, j] = 0;
                            for (int k = 0; k < size; k++)
                            {
                                result[ii, j] += m1[ii, k] * m2[k, j];
                            }
                        }
                    });
                    threads.Add(t);
                    t.Start(i);
                }
                
                foreach (Thread thread in threads)
                    thread.Join();
    
                return result;
            }

    LispGovno, 21 Января 2015

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

    +59

    1. 1
    2. 2
    3. 3
    if ( number % 10 == 0 ) {
        number %= 10;
    }

    мне кажется, или...

    artembegood, 21 Января 2015

    Комментарии (6)
  3. Python / Говнокод #17487

    −109

    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
    class QuerysetResponse(object):
        """
            вариант респонса для фильтрации гридов или диктселекфилдов
            используя механизм инструкций
        """
        def __init__(self, queryset, application, root=None):
    
            self.root = root or "data"
    
        def __new__(cls, *args, **kwargs):
            return super(cls, cls).__new__(cls)(*args, **kwargs)
    
        def __call__(self, queryset, application):
            dict_list = []
            pack = get_pack_instance(application)
            for item in pack.list_columns:
                if isinstance(item, (list, tuple)):
                    dict_list.append(item[0])
                elif isinstance(item, dict) and item.get('data_index'):
                    dict_list.append(item['data_index'])
            self.dict_ = dict_list
            if not queryset:
                queryset = []
    
            return PreJsonResult(dict(rows=list(queryset),
                total=len(queryset)), dict_list=self.dict_).get_http_response()

    self.root не используется, ну, это видно. QuerysetResponse "инстанцируется" во всем проекте один раз.
    Мне бы такое даже в голову не пришло.

    pycz, 21 Января 2015

    Комментарии (26)
  4. JavaScript / Говнокод #17486

    +157

    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
    if ( diffYear < 5 ) {
            document.getElementById('yearsText').innerHTML = "года |";
        } else if ( diffYear > 1 ){
            document.getElementById('yearsText').innerHTML = "лет |";
        } else {
            document.getElementById('yearsText').innerHTML = "год |";
        }
        
        if ( diffMonth > 4 ) {
            document.getElementById('monthText').innerHTML = "месяцев |";
        } else if ( diffMonth > 1 ){
            document.getElementById('monthText').innerHTML = "месяца |";
        } else {
            document.getElementById('monthText').innerHTML = "месяц |";
        }
        
        if ( diffDay > 5 ) {
            document.getElementById('monthText').innerHTML = "дней |";
        } else if ( diffDay > 1 ){
            document.getElementById('monthText').innerHTML = "дня |";
        } else {
            document.getElementById('monthText').innerHTML = "день |";
        }
    }

    очередная кака с датой

    artembegood, 21 Января 2015

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

    −161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    my @arr = (1,2,3,4);
    foreach (@arr) 
    {
       threads->new(\&doSomething, $_)->join;
    }

    Цикл на 4...? Запуск потоков.

    BoBikeR, 20 Января 2015

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

    +91

    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
    <? die;
    
    if($_GET['tn'])
    {
    	if(($i = $conf['settings'][$s = "{$arg['modpath']}=>img"]) && ($img = explode(",", $i))){ $tn = array_combine($img, $img); }else{
    		$tn = array($_GET['tn']=>preg_replace('/[^0-9a-z_]/', '', $_GET['tn']));
    	} $sql = "SELECT `". mpquot($_GET['fn'] ? $_GET['fn'] : "img"). "` FROM {$conf['db']['prefix']}{$arg['modpath']}_{$tn[$_GET['tn']]} WHERE id=".(int)$_GET['id'];
    	$file_name = mpopendir("include")."/".($fn = mpql(mpqw($sql), 0, ($_GET['fn'] ? $_GET['fn'] : "img")));
    	if(!array_search(array_pop(explode('.', $file_name)), array(1=>"jpg", "jpeg", "png", "gif"))){
    		$file_name = mpopendir("img/ext/". array_pop(explode('.', $file_name)). ".png");
    	}
    }else{
    	$file_name = mpopendir("modules/{$arg['modpath']}/img/". basename($_GET['']));
    } header ("Content-type: image/". array_pop(explode('.', $file_name)));
    echo mprs($file_name, $_GET['w'], $_GET['h'], $_GET['c']);
    
    ?>

    это не шуууутки мы встретились в маршруууутке

    deconf, 20 Января 2015

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

    +76

    1. 1
    2. 2
    if ( !log.append(log_line) )
    	log.append("Can't append to log");

    Безумие, оно рядом.

    Anus, 20 Января 2015

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

    +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
    $i = 0;
            for ($k = 0; $k<=5; $k++){
                if ($i==5)
                    break;
                foreach (getContent($id) as $content_row) {
                    $i++;
                    $htmlshowcase = $content_row->getShowcase(1, $k);
                    if ($htmlshowcase == '')
                        $i--;
                    else
                        $html .= $htmlshowcase;
                    if ($i==5)
                        break;
                }
            }

    Лучший способ прохода по циклу.

    arkham_vm, 20 Января 2015

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

    +129

    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
    import std.uuid;
    import std.file;
    import std.path;
    import std.string;
    ubyte[] sdlBytes = cast(ubyte[]) import("SDL2.dll");   // SDL2.dll contents
    void main(string[] args)
    {
        auto uuid = randomUUID();
        string uuid = randomUUID().toString();
        string filename = format("SDL2-%s.dll", uuid);     // Making an unique file name.
        string depacked = buildPath(tempDir(), filename);
        std.file.write(depacked, sdlBytes);                // Writing the dynlib to a temporary file.
        DerelictSDL2.load(depacked);                       // Use the depacked dynlib and load its symbols.
    }

    лол, надо поюзать.

    DlangGovno, 19 Января 2015

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

    +152

    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
    <?
    require_once('ittable.class.php');
    
    class ITForm extends ITTable
    {
    public function __construct($tbl)
    {
    parent::__construct($tbl);
    
    //путь с скрипту который удаляет файлы по tblname record_id filename
    $this->path2deletephp='/itcms4/ckeditor/delete.php';
    }
    
    
    public function printForm($i, $action, $head, $submitvalue='', $captcha=0)
    {
    $form = $this->generateFormData($i, $action, $head, $submitvalue, $captcha);
    
    print "<h1>$form->head</h1>
    $form->begin
    $form->inputhidden
    
    <table>";
    
    foreach($form->inputs as $k=>$v)
     print "<tr id='itforms_$k'" . ($this->columns[$k]->blockclass?' class="' . $this->columns[$k]->blockclass . '"':'') ."><td>$v->name</td><td>$v->input</td></tr>\n";
     
    print "</table>
    
    $form->files
    
    
    <hr><input type='submit' value='$form->submitvalue'></form>
    
    <script type='text/javascript'>
    var itform;
    $(document).ready(function()
      {
       itform = new ITForm($('#$this->tbl$i->id'));
       $form->js
       });
    </script>
    ";
    }
    
    public function insertForm($head, $submitvalue='', $i=0)
    {
     if(!$i)
      $i = new stdClass();
      
     $copy_id = intval($_GET['copy_id']);
     if($copy_id)
     {
      $r=exec_mysql_query("SELECT * FROM $this->tbl WHERE id='$copy_id'");
      $row=mysql_fetch_array($r);
      foreach($row as $k=>$v)
       if(!isset($i->$k))
        $i->$k = $v;
     }
     //чтобы можно было загрузить файлы делаем временный id в диапазоне от 10^7 до 2*10^9
     $i->id = 'r' . rand(10000000, 2000000000);
     $this->printForm($i, 'insert.php', $head, $submitvalue);
    } 
    
    public function updateForm($id, $head, $submitvalue='')
    {
     $this->printForm($this->getObject($id), 'update.php',  $head, $submitvalue);
    
    if(mysql_numrows(exec_mysql_query("SELECT id FROM it_updatelog WHERE tbl='$this->tbl' AND record_id='$id'")))
     print "<a href=/crm2/log/?w_tbl_2=$this->tbl&w_record_id_1=$id>История изменений</a><br>"; 
    }
    
    public function deleteForm($id, $head, $submitvalue='')
    {
     $this->printForm($this->getObject($id), 'delete.php',  $head, $submitvalue);
    }
    
    public function updateForm4Object($o, $head, $submitvalue='')
    {
     $this->printForm($o, 'update.php',  $head, $submitvalue);
    
    if(mysql_numrows(exec_mysql_query("SELECT id FROM it_updatelog WHERE tbl='$this->tbl' AND record_id='$o->id'")))
     print "<a href=/crm2/log/?w_tbl_2=$this->tbl&w_record_id_1=$o->id>История изменений</a><br>"; 
    }

    Продолжение: http://govnokod.ru/17479

    itgovnokod, 19 Января 2015

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