1. PHP / Говнокод #18432

    +142

    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
    function array_to_file($array_name, $array, $filename = 0, $file = 0)
    {
    	$level = 1;
    	if($file == 0) {
    		$level = 0;
    		$file = fopen($filename, "w");
    		if(!$file) {
    			return false;
    		}
    		fwrite($file, "<" . "?\n\$".$array_name." = ");
        }
    
        $cnt = count($array);
        $i = 0;
        fwrite($file, "\narray(\n");
        foreach($array as $key => $value)
        {
    		if($i++ != 0) {
    			fwrite($file, ",\n");
    		}
    		if(is_array($array[$key])) {
    			fwrite($file, "\"".$key."\" => ");
    			array_to_file($array_name, $array[$key], 0, $file);
    		} else  {
    			$value = addcslashes($value, "\""."\\\\");
    			fwrite($file, str_repeat(" ", ($level + 1) * 2) . "\"".$key."\" => \"".$value."\"");
    		}
        }
        fwrite($file, ")");
    
        if($level == 0) {
    		fwrite($file, ";\n?".">");
    		fclose($file);
    		return true;
        }
    }

    alex322, 02 Июля 2015

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

    −105

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    Функция КонтрИскл8(код)
        
        КонтрИскл8=Справочники.Контрагенты.НайтиПоКоду(Код).Ссылка.ДополнительныеРеквизиты.Найти(ПланыВидовХарактеристик.ДополнительныеРеквизитыИСведения.НайтиПоНаименованию("Код_").Ссылка).Значение;
        Искл8=КонтрИскл8;
        Возврат Искл8; 
        
    КонецФункции

    Укоадено с mista.ru. Не мог не поделиться. Когда впервые увидел, мой взгляд был примерно таким - 0_0

    portwein, 02 Июля 2015

    Комментарии (0)
  3. SQL / Говнокод #18430

    −160

    1. 1
    n IN (6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25)

    условие n >= 6 выполнено

    lisiy50, 02 Июля 2015

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

    +142

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    /* Background gallery by http://manos.malihu.gr */
    //config
    //set default images view mode
    //$defaultViewMode="full"; //full, normal, original
    $defaultViewMode="original"; //full, normal, original
    $tsMargin=0; //first and last thumbnail margin (for better cursor interaction) 
    $scrollEasing=999888; //scroll easing amount	 (0 for no easing) 
    $scrollEasingType="easeOutCirc"; //scroll easing type 
    $thumbnailsContainerOpacity=0.9; //thumbnails area default opacity
    $thumbnailsContainerMouseOutOpacity=0; //thumbnails area opacity on mouse out
    $thumbnailsOpacity=1; //thumbnails default opacity
    $nextPrevBtnsInitState="show"; //next/previous image buttons initial state ("hide" or "show")
    $keyboardNavigation="on"; //enable/disable keyboard navigation ("on" or "off")
    
    //cache vars
    $thumbnails_wrapper=$("#thumbnails_wrapper");
    $outer_container=$("#outer_container");
    $thumbScroller=$(".thumbScroller");
    $thumbScroller_container=$(".thumbScroller .container");
    $thumbScroller_content=$(".thumbScroller .content");
    $thumbScroller_thumb=$(".thumbScroller .thumb");
    $preloader=$("#preloader");
    $toolbar=$("#toolbar");
    $toolbar_a=$("#toolbar a");
    $bgimg=$("#bgimg");
    $img_title=$("#img_title");
    $nextImageBtn=$(".nextImageBtn");
    $prevImageBtn=$(".prevImageBtn");
    
    $bg=$("#bg");
    
    $(window).load(function() {
    	$toolbar.data("imageViewMode",$defaultViewMode); //default view mode
    	if($defaultViewMode=="full"){
    		$toolbar_a.html("<img src='images/toolbar_n_icon.png' width='50' height='50'  />").attr("onClick", "ImageViewMode('normal');return false").attr("title", "Restore");
    	} else {
    		$toolbar_a.html("<img src='images/toolbar_fs_icon.png' width='50' height='50'  />").attr("onClick", "ImageViewMode('full');return false").attr("title", "Maximize");
    	}
    	/* var winWidth=$(window).width();
    	var winHeight=$(window).height();
    	$("#bg").attr("min-height",winHeight+"px"); */
    	ShowHideNextPrev($nextPrevBtnsInitState);
    	//thumbnail scroller
    	$thumbScroller_container.css("marginLeft",$tsMargin+"px"); //add margin
    	sliderLeft=$thumbScroller_container.position().left;
    	sliderLeft=0;
    	sliderWidth=$outer_container.width();
    	$thumbScroller.css("width",sliderWidth);
    	var totalContent=0;
    	fadeSpeed=200;
    	
    	var $the_outer_container=document.getElementById("outer_container");
    	var $placement=findPos($the_outer_container);
    	
    	$thumbScroller_content.each(function () {
    		var $this=$(this);
    		totalContent+=$this.innerWidth();
    		$thumbScroller_container.css("width",totalContent);
    		$this.children().children().children(".thumb").fadeTo(fadeSpeed, $thumbnailsOpacity);
    	});
    
    	$thumbScroller.mousemove(function(e){
    		if($thumbScroller_container.width()>sliderWidth){
    	  		var mouseCoords=(e.pageX - $placement[1]);
    	  		var mousePercentX=mouseCoords/sliderWidth;
    	  		var destX=-((((totalContent+($tsMargin*2))-(sliderWidth))-sliderWidth)*(mousePercentX));
    	  		var thePosA=mouseCoords-destX;
    	  		var thePosB=destX-mouseCoords;
    	  		if(mouseCoords>destX){
    		  		$thumbScroller_container.stop().animate({left: -thePosA}, $scrollEasing,$scrollEasingType); //with easing
    	  		} else if(mouseCoords<destX){
    		  		$thumbScroller_container.stop().animate({left: thePosB}, $scrollEasing,$scrollEasingType); //with easing
    	  		} else {
    				$thumbScroller_container.stop();  
    	  		}
    		}
    	});
    
    	$thumbnails_wrapper.fadeTo(fadeSpeed, $thumbnailsContainerOpacity);
    	/* $thumbnails_wrapper.hover(
    		function(){ //mouse over
    			var $this=$(this);
    			$this.stop().fadeTo("slow", 1);
    		},
    		function(){ //mouse out
    			var $this=$(this);
    			$this.stop().fadeTo("slow", $thumbnailsContainerMouseOutOpacity);
    		}
    	); */
    
    	$thumbScroller_thumb.hover(
    		function(){ //mouse over
    			var $this=$(this);
    			$this.stop().fadeTo(fadeSpeed, 1);
    		},
    		function(){ //mouse out
    			var $this=$(this);
    			$this.stop().fadeTo(fadeSpeed, $thumbnailsOpacity);
    		}
    	);

    carousel

    vityapro, 02 Июля 2015

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

    +142

    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
    private int[] ListToArray(List<int> list)
    {
    	try
    	{
    		int[] res = new int[list.Count];
    		
    		for (int i = 0; i < list.Count; i++)
    		{
    			res[i] = list[i];
    		}
    		
    		return res;
    	}
    	catch (Exception) { return new int[0]; }
    }

    А ещё он заполняет List<> в цикле for

    rumpowered, 01 Июля 2015

    Комментарии (4)
  6. Куча / Говнокод #18427

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    foo() ->
        Du =  os:cmd("du -b "++?PM_LOGS_PATH),
        [DiscSize|_] = string:tokens(Du, "\t"),
        case list_to_integer(DiscSize) > 10000000000 of
          ...

    Вся мощь эрланга. В строке может быть не только число? Let it crash!

    lesmugfrog, 01 Июля 2015

    Комментарии (0)
  7. SQL / Говнокод #18426

    −84

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    BEGIN
    select count(*) INTO var FROM table_name;
    EXCEPTION WHEN OTHERS THEN 
    var:=0;
    END;

    Если что-то пойдет не так...
    P.S.: count() всегда возвращает какое-либо значение. Ошибке не откуда взяться.

    mishok, 01 Июля 2015

    Комментарии (9)
  8. SQL / Говнокод #18425

    −176

    1. 1
    and (ss_1<>'SS0001' or ss_1<>'SS0002' or ss_1<>'SS0010')

    Сегодня на продакшене было обнаружено гениальное выражение в одном из запросов.

    mishok, 01 Июля 2015

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

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    public int MapToLowerPageBoundary(int rowIndex)
    {
           return (rowIndex / RowsPerPage) * RowsPerPage;
    }

    Нашел этот метод в проекте... Интересно о чем думал автор...

    alex493049469, 01 Июля 2015

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

    +142

    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
    <?php
    
    $self=$_SERVER['PHP_SELF'];
    
    if (isset($_GET['page'])) { $page=$_GET['page'];} else {$page=1;}
    
    $pages=25;
    $page_offset=5;
    $unique_links=9;
    
    if ($page != 1) { // Don't show back link if current page is first page.
    $back_page = $page-1;
    echo("<a href=\"$self?page=$back_page\">prev</a>    \n");}
    
    for ($i=1; $i <= $pages; $i++)  {
    
    if ($i == $page) {
     echo("<b>$i</b>\n");// If current page don't give link, just text.
     }  else {
    
    if (($i>$page-$page_offset) && ($i<$page+$page_offset)  && ($page>$page_offset)) {	
    echo("<a href=\"$self?page=$i\">$i</a> \n");
    } 
    elseif (($i<=$unique_links) && ($page<=$page_offset)) {
    	echo("<a href=\"$self?page=$i\">$i</a> \n");
    }
    elseif (($i>$pages-$unique_links) && ($page>$pages-$page_offset)) {
    echo("<a href=\"$self?page=$i\">$i</a> \n");	
    }
    
    }
    
    }
    
    if (!($page >= $pages) && $pages != 1) { // If last page don't give next link.
    $next_page = $page + 1;
    echo("<a href=\"$self?page=$next_page\">next</a>");}
    
    
    ?>

    Адовый аромат (хоть и рабочий), понимаю, но помогите упростить, пожалуйста. Условия внутри цикла скорее всего избыточны.
    Вкратце: "плавающий" пагинатор, 9 уникальных ссылок.

    nurfed362, 30 Июня 2015

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