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

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    FileInfo[] fi = new DirectoryInfo(di.FullName).GetFiles();
    
    var creationList = from file in fi
                                 where file.CreationTime.CompareTo(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)) < 0 //This instance is earlier than value. 
                                 group file.CreationTime by DateTime.Parse(file.CreationTime.ToString("yyyy-MM-dd")) into ct
                                 select ct.Key;

    что делает этот код?

    taburetka, 24 Января 2014

    Комментарии (13)
  2. Java / Говнокод #14410

    +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
    13. 13
    final class HackFormFlowPanel extends FormPanel {
    	...
    	
    	@Override
    	public void reset() {
    		GWT.log("Upload form reset suppressed");
    		// Overridden to do nothing.
    	}
    	
    	public void reallyReset() {
    		super.reset();
    	}
    }

    После успешного аплоада файла gwtupload говорит reset форме с элементом выбора файла. И никак не отключается. А нужно, чтобы файл оставался выбранным.

    Пришлось нагородить вот такой костыль.

    someone, 24 Января 2014

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    var summa = 0;
    for (i = 0; i < data.length; i++) {
        var j = 0;
        for (var key in data[i]) {
            j++;
            if (j == 3) summa += parseFloat(data[i][key]);
        }
    }

    вытаскиваем сумму из массива вида: [{MODEL:"ID-2112",COUNT:"1",PRICE:"14070"}, {...}]
    не! ну трети же, чо..

    belukov, 24 Января 2014

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

    +121

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    //if they're locked out or banned die
    if ( ( $bwpsoptions['id_enabled'] == 1 ||$bwpsoptions['ll_enabled'] == 1 ) && $this->checklock( $current_user->user_login ) ) {
    
    	wp_clear_auth_cookie();
        @header( 'HTTP/1.0 418 I\'m a teapot' );
        @header( 'Cache-Control: no-cache, must-revalidate' ); 
        @header( 'Expires: Thu, 22 Jun 1978 00:28:00 GMT' );
        die( __( 'error', $this->hook ) );
    
    }

    https://plugins.trac.wordpress.org/browser/better-wp-security/trunk/inc/secure.php#L925

    someone, 24 Января 2014

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    $result_max = mysql_query("SELECT MAX(id)+1 as max FROM cms_competition;");
    $row_max = mysql_fetch_object($result_max);
    if(!$row_max->max)
          $row_max->max = 1;

    Так ведь проще

    kindofbear, 24 Января 2014

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

    +153

    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
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    $db = new DB_Sql();
            $db->connect();
    		$sql = "SELECT  distinct(absnum) FROM articles";
    		$db->query($sql);
        		while ($db->next_record()){
                    $is_img_sql[] = $db->f('absnum');
                }
    		
            $Open = opendir($_SERVER['DOCUMENT_ROOT'].'/img/forall/a/');
                while(false !== ($gdir = readdir($Open))){
                    if($gdir != "." && $gdir != ".."){
                        $dir[] = $gdir;
                    }
                }
            closedir($Open);
    		
            foreach ($dir as $fdir){
                if(is_dir($_SERVER['DOCUMENT_ROOT'].'/img/forall/a/'.$fdir.'/')){
                $Open2 = opendir($_SERVER['DOCUMENT_ROOT'].'/img/forall/a/'.$fdir.'/');
                    while(false !== ($gdir2 = readdir($Open2))){
                        if($gdir2 != "." && $gdir2 != ".."){
                            $tmp = intval($fdir.ereg_replace("\..*","",$gdir2));
                            if(!in_array($tmp,$is_img_sql)){
                                $delfile = $_SERVER['DOCUMENT_ROOT'].'/img/forall/a/'.$fdir.'/'.$gdir2;
                                    if (is_file($delfile)){
                                        if (unlink($delfile)){
                                            echo "Файл <b>".$delfile."</b> удален<br>";
                                        }
                                    }
                            }
                        }
                    }
                closedir($Open2);
                }
            }
    		
            $Open = opendir($_SERVER['DOCUMENT_ROOT'].'/img/g/');
                while(false !== ($gdirg = readdir($Open))){
                    if($gdirg != "." && $gdirg != ".."){
                        $dirg[] = $gdirg;
                    }
                }
    		
            closedir($Open);
            foreach ($dirg as $fdir){
                $Open2 = opendir($_SERVER['DOCUMENT_ROOT'].'/img/g/'.$fdir.'/');
                    while(false !== ($gdir2 = readdir($Open2))){
                        if($gdir2 != "." && $gdir2 != ".."){
                            $tmp = intval($fdir.$gdir2.ereg_replace("\..*","",$gdir3));
                            if(!in_array($tmp,$is_img_sql)){
                                $delfile = $_SERVER['DOCUMENT_ROOT'].'/img/g/'.$fdir.'/'.$gdir2;
                                    if (is_dir($delfile)){
                                        $Opendel = opendir($delfile);
                                            while(false !== ($gdirdel = readdir($Opendel))){
                                                if($gdirdel != "." && $gdirdel != ".."){
                                                    $tpmdel = $delfile."/".$gdirdel;
                                                        if (is_file($tpmdel)){
                                                            unlink($tpmdel);
                                                        }
                                                }
                                            }
                                            if (rmdir($delfile)){
                                               echo "Директория <b>".$delfile."</b> удалена<br>";
                                            }
                                     }
                            }
                        }
                    }
                closedir($Open2);
            }
    		
    		$sql = "SELECT  distinct(absnum) FROM price";
    		$db->query($sql);
        		while ($db->next_record()){
                    $is_img_price[] = $db->f('absnum');
                }
            $Open = opendir($_SERVER['DOCUMENT_ROOT'].'/img/forall/p/');
                while(false !== ($gdirp = readdir($Open))){
                    if($gdirp != "." && $gdirp != ".."){
                        $dirp[] = $gdirp;
                    }
                }
            closedir($Open);
    		
            foreach ($dirp as $fdir){
                $Open2 = opendir($_SERVER['DOCUMENT_ROOT'].'/img/forall/p/'.$fdir.'/');
                    while(false !== ($gdir2 = readdir($Open2))){
                        if($gdir2 != "." && $gdir2 != ".."){
                            $tmp = intval($fdir.ereg_replace("\..*","",$gdir2));
                            if(!in_array($tmp,$is_img_price)){
                                $delfile = $_SERVER['DOCUMENT_ROOT'].'/img/forall/p/'.$fdir.'/'.$gdir2;
                                        if (is_file($delfile)){
                                            if (unlink($delfile)){
                                               echo "Файл <b>".$delfile."</b> удален<br>";
                                            }
                                        }
                            }
                        }
                    }

    shmaltorhbooks, 24 Января 2014

    Комментарии (2)
  7. Java / Говнокод #14405

    +74

    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
    if (myTransactions
            .get(i)
            .getTransactionType()
            .name()
            .compareToIgnoreCase(
                    com.mycompany.myproject.common.TransactionType.ENTER
                            .name()) == 0
            || myTransactions
                    .get(i)
                    .getTransactionType()
                    .name()
                    .compareToIgnoreCase(
                                com.mycompany.myproject.common.TransactionType.ENTER_AGAIN
                                        .name()) == 0) {
    
        BigDecimal fee = myTransactions.get(i).
                .getAmount().subtract(
                        myTransactions.get(i)
                                .getContribution());
    // ...
    }
    
    // Notes by Wissenstein
    //
    // package com.mycompany.myproject.common;
    // public enum TransactionType {
    //     ENTER, ENTER_AGAIN, GET, GIVE
    // }
    // ...
    // public class Transaction {
    // ...
    //     public TransactionType getTransactionType() {
    // ...
    //     }
    // }
    // ...
    // List<Transaction> myTransactions;
    // ...
    // P.S. Идентификаторы изменены.

    К тому, что myTransactions.get(i) повторяется, я уже привык и рефакторю это одним махом.
    Однако использованный здесь метод сравнения значений типа enum меня озадачил…

    wissenstein, 23 Января 2014

    Комментарии (0)
  8. Java / Говнокод #14404

    +174

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    static String asHex(int i){
    		return
    			Joiner.on( " " ).join(
    				Splitter.fixedLength( 4 ).split(
    					String.format("%s8", Integer.toHexString(i))
    						.replace(' ', '0')
    				)
    			);
    }

    LINQ-мышление в жабе.

    3.14159265, 23 Января 2014

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

    −131

    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
    [self
            performSelectorOnMainThread: @selector(_blockCaller:)
            withObject: ^{
                [self _reportAchievement:achievement listener:listener];
            }
            waitUntilDone: YES
        ];
    
    <...>
    
    - (void) _blockCaller:(void(^)())blockHandler {
        blockHandler();
    }

    GCD не в моде.

    krypt, 23 Января 2014

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

    +156

    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
    function search(url,param)
                    {
                            $("#rightContent").hide()
                            setBlock("Загрузка")
                            loadLeftMenu()
                            $("#content").load("/search", function(response, status, xhr){
                                $("#Subscription").show()
                                    queryStr=param.split("&")
    
                                    if (queryStr.length==2){
                                            str=(queryStr[0]).replace("querystr=","")
                                            $("#querystr").val(decodeURI(str.replace(/\+/g," ")))
                                            region=((queryStr[1]).replace("region=","")).split(",")
                                            replaceItemInArray(region,"59","59,81")
                                            removeFromArray(region,'81')
                                            replaceItemInArray(region,"75","75,80")
                                            removeFromArray(region,'80')
                                            updateMultiselect("#region", region, "region")
                                    }
                                    if (queryStr.length==3){
                                            str=(queryStr[1]).replace("querystr=","")
                                            $("#querystr").val(decodeURI(str.replace(/\+/g," ")))
                                            region=((queryStr[2]).replace("region=","")).split(",")
                                            replaceItemInArray(region,"59","59,81")
                                            removeFromArray(region,'81')
                                            replaceItemInArray(region,"75","75,80")
                                            removeFromArray(region,'80')
                                            updateMultiselect("#region", region, "region")
                                    }
                                    if (queryStr.length==4){
                        str=(queryStr[0]).replace("querystr=","")
                        $("#querystr").val(decodeURI(str.replace(/\+/g," ")))
    
                        region=((queryStr[1]).replace("region=","")).split(",")
    
                        if (queryStr[2]=='fz94=true'){
                          $('#fz94').attr('checked','checked')
                        }else{
                          $('#fz94').removeAttr('checked')
                        }
    
                        if (queryStr[3]=='fz223=true'){
                          $('#fz223').attr('checked','checked')
                        }else{
                          $('#fz223').removeAttr('checked')
                        }
                                            
                                            replaceItemInArray(region,"59","59,81")
                                            removeFromArray(region,'81')
                                            replaceItemInArray(region,"75","75,80")
                                            removeFromArray(region,'80')
                                            
                                            updateMultiselect("#region", region, "region")
                                    }
                    if (queryStr.length==5){
                        str=(queryStr[1]).replace("querystr=","")
                        $("#querystr").val(decodeURI(str.replace(/\+/g," ")))
    
                        region=((queryStr[2]).replace("region=","")).split(",")
    
                        if (queryStr[3]=='fz94=true'){
                            $('#fz94').attr('checked','checked')
                        }else{
                            $('#fz94').removeAttr('checked')
                        }
    
                        if (queryStr[4]=='fz223=true'){
                            $('#fz223').attr('checked','checked')
                        }else{
                            $('#fz223').removeAttr('checked')
                        }
    
                        replaceItemInArray(region,"59","59,81")
                        removeFromArray(region,'81')
                        replaceItemInArray(region,"75","75,80")
                        removeFromArray(region,'80')
    
                        updateMultiselect("#region", region, "region")
                    }
    
    // Ну и так далее

    Разбор строки запроса

    hdkeeper, 23 Января 2014

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