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

    +96

    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
    // expressions to parse
    		$input_pars = array(
    			's:2'=>'(sort(\d+)/?)?', 				//1-2
    			'id:2'=>'((\d+)/?)?',  			 		//3-4
    			'utkonos_id-shop_id:2-2'=>'(u(\d+)(s(\d+))?/)?', 	//5-6 7-8
    			'iid:1'=>'([0-9a-zA-Z_]+)/?', 				//9
    			'page:2'=>'(pg(\d+)/)?', 				//10-11
    			'chpsize:2'=>'(chp(\d+)/)?', 				//12-13
    			'chlist:2'=>'(chlist_(grid|list)/)?', 				//14-15
    			'p_other:1'=>'(.*)',					//16
    		);
    		if(!$class)unset($input_pars['iid:1']);
    		$m = array();
    		$i=0;
    
    		if(isset($_REQUEST['p_'])&&preg_match('[^'.implode('',$input_pars).'$]',$_REQUEST['p_'],$m)) {
    			//vd($m);
    			foreach($input_pars as $key=>$line) {
    				list($par_name,$num) = explode(':', $key);
    				$par_name_arr = explode('-',$par_name);
    				$num_arr = explode('-',$num);
    				if(count($par_name_arr)>1) {
    					foreach($par_name_arr as $kluch => $par_name) {
    						$i += $num_arr[$kluch];
    						$_REQUEST[$par_name] = $m[$i];
    					}
    				}else{
    					$i += $num;
    					$_REQUEST[$par_name] = $m[$i];
    				}
    			}
    			$_REQUEST['id'] += 0;
    			if ($_REQUEST['s'] === '0') {
    				$_REQUEST['s'] = 0;
    			}
    			if ($_REQUEST['chpsize'] === '0') {
    				$_REQUEST['chpsize'] = 0;
    			}
    			vd($_REQUEST);
    		}else{
    			$_REQUEST['s'] = grv('s',-1);						/// Сортировка
    			$_REQUEST['id'] = grv('id',0);
    			$_REQUEST['shop_id'] = grv('shop_id',0);
    			$_REQUEST['page'] = grv('page',0);
    			$_REQUEST['chpsize'] = (int)grv('chpsize',-1);
    		}

    ggg, 23 Апреля 2012

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

    +103

    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
    digits n  = reverse $ map (`mod` 10) (takeWhile (/= 0) (iterate (`div` 10) n))
    
    fromDigits l = sum $ zipWith (*) (reverse l) (map (10^) [0..])
    
    isPalindromic x = digits x == (reverse $ digits x)
    
    
    f :: Integer -> [[Integer]] -> [Integer] -> Int -> [[Integer]]
    f x founded lookedup niter 
                      | niter > 50 = [notlychers, [x] ++ lychers ++ lookedup, zs]
                      | nextX `elem` notlychers = [[x] ++ notlychers ++ lookedup, lychers, zs]
                      | nextX `elem` lychers = [notlychers, [x] ++ lychers ++ lookedup, zs]
                      | isPalindromic nextX = [[x] ++ notlychers ++ lookedup, lychers, zs]
                      | otherwise = f nextX founded (x : lookedup) (niter+1)
       where nextX = x + fromDigits (reverse $ digits x)
             notlychers = founded !! 0
             lychers = founded !! 1
             zs = founded !! 2
    
    g :: [[Integer]] -> [[Integer]]
    g founded = f (x-1) [xs, ys, [x-1]] [] 0
     where x  = zs !! 0
           xs = founded !! 0
           ys = founded !! 1
           zs = founded !! 2
    
    gg n = g [[],[],[n+1]]
    
    isLycher n = null $ (gg n) !! 0

    http://projecteuler.net/problem=55
    http://projecteuler.net/thread=55


    >i even haven't understood why it works :(

    TheHamstertamer, 23 Апреля 2012

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

    +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
    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
    <table style="width: 100%">
    				<tr>
    					<td rowspan="2" style="width: 39px">&nbsp;</td>
    					<td height="22px" width="306px" background="/templates/images/all_for_your.jpg" style="background-repeat: no-repeat;"></td>
    					<td>&nbsp;</td>
    				</tr>
    				<tr>
    					<td width="306px">
    						<table  class="style2" style="height: 147px;" >
    <tr>
    					<!--<td height="22px" width="306px" background="/templates/images/all_for_your.jpg">
    				</td>-->
    				</tr>
    				<tr>
    					<td class="style14" style="height: 21px;"><a href="page13.html" <?php if ($_GET['id'] == 13) echo "style=\"color: red;\""; ?>> ччччч</td>
    				</tr>
    								<tr>
    					<td class="style14" style="height: 21px;"><a href="page12.html" <?php if ($_GET['id'] == 12) echo "style=\"color: red;\""; ?>> фвургия</td>
    				</tr>
    								<tr> 
    					<td class="style14" style="height: 21px; ">
    					<a href="page8.html" <?php if ($_GET['id'] == 8) echo "style=\"color: red;\""; ?>> ывфыв</a> </td>
    			    </tr>
    				<tr>
    					<td class="style14" style="height: 21px; ;"><a href="page9.html" <?php if ($_GET['id'] == 9) echo "style=\"color: red;\""; ?>> ыывсия</td>
    				</tr>
    				<tr>
    					<td class="style14" style="height: 21px; "><a href="page43.html" <?php if ($_GET['id'] == 43) echo "style=\"color: red;\""; ?>> Вмиика</td>
    				</tr>				
    				<tr>
    					<td class="style14" style="height: 21px; "><a href="page10.html" <?php if ($_GET['id'] == 10) echo "style=\"color: red;\""; ?>>ние</td>
    				</tr>
    					<tr>
    					<td class="style14" style="height: 21px; "><a href="page14.html" <?php if ($_GET['id'] == 14) echo "style=\"color: red;\""; ?>>Одыа 
    					</td>
    				</tr>
    					<tr>
    					<td class="style14" style="height: 21px; "><a href="page22.html" <?php if ($_GET['id'] == 22) echo "style=\"color: red;\""; ?>> Оысия</td>
    				</tr>
    			</table>

    Один из старых сайтов нашел:)

    EGR, 23 Апреля 2012

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

    +112

    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
    <?php
    @session_start();
    include("с.php");
    if(isset($_POST['postid'])){
    	if($_POST['PoM']=="plus"){
    		if(isset($_SESSION['userid']) && mysql_num_rows(mysql_query("SELECT * FROM `bans` WHERE `userid`='".@$_SESSION['userid']."';"))==0){
    		$query89=mysql_query("SELECT `from` FROM `blogs` WHERE `bid`='".$_POST['postid']."' LIMIT 1;");
    		if($_SESSION['userid']==mysql_result($query89, 0, 0)){ } else {
    		$get_rating=mysql_query("SELECT `rating` FROM `blogs` WHERE `bid`='".$_POST['postid']."';");
    		$check_vote_plus=mysql_query("SELECT `voteid` FROM `blogvotes` WHERE `bid`='".$_POST['postid']."' and `userid`='".$_SESSION['userid']."' and `PoM`='plus';");
    		$check_vote_minus=mysql_query("SELECT `voteid` FROM `blogvotes` WHERE `bid`='".$_POST['postid']."' and `userid`='".$_SESSION['userid']."' and `PoM`='minus';");
    		if(mysql_num_rows(@$check_vote_minus)){
    		mysql_query("DELETE FROM `blogvotes` WHERE `bid`='".$_POST['postid']."' and `userid`='".$_SESSION['userid']."';");
    		mysql_query("UPDATE `blogs` SET `rating`=".mysql_result($get_rating, 0, 0)."+1 WHERE `bid`='".$_POST['postid']."';");
    		}
    		$get_rating2=mysql_query("SELECT `rating` FROM `blogs` WHERE `bid`='".$_POST['postid']."';");
    		$check_vote_plus3=mysql_query("SELECT `voteid` FROM `blogvotes` WHERE `bid`='".$_POST['postid']."' and `userid`='".$_SESSION['userid']."' and `PoM`='plus';");
    		if(!mysql_num_rows(@$check_vote_plus3)){
    		mysql_query("UPDATE `blogs` SET `rating`=".mysql_result($get_rating2, 0, 0)."+1 WHERE `bid`='".$_POST['postid']."';");
    		mysql_query("INSERT INTO blogvotes(`bid`, `userid`, `PoM`) VALUES('".$_POST['postid']."', '".$_SESSION['userid']."', '".$_POST['PoM']."');");
    		$query6=mysql_query("SELECT `userid`, `username`, `email`, `points`, `reputation` FROM `users` WHERE `userid`='".$_SESSION['userid']."' LIMIT 1");
    		$current_user=mysql_fetch_row($query6);
    		}
    		}
    		}
    		$get_r_rating=mysql_query("SELECT `rating` FROM `blogs` WHERE `bid`='".$_POST['postid']."';");
    		$ratingValue=mysql_result($get_r_rating, 0, 0);
    	}
    }
    ?>

    Очередной код, используемый в моём самописном движке для оценки постов. Разобраться во всём этом удаётся только благодаря тому, что я писал его недавно и помню построение кода.

    BiggestFox, 23 Апреля 2012

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

    +70

    1. 1
    if (sAttrName.equalsIgnoreCase("10")) {

    someone, 23 Апреля 2012

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

    +110

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    int[] k = new int[docArr.Length];
    int index = 0;
    
    foreach (var item in docArr)
    {
          k[index] = (int)item;
          index++;
    }
    
    var l = k.ToArray().OrderByDescending(i => i);

    True сортировка массива.

    partizan, 23 Апреля 2012

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

    −15

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function _taxonomy_image_exists($tid) {
      if (db_fetch_object(db_query('SELECT path FROM {term_image} WHERE tid=%d', $tid))) {
        return TRUE;
      }
      return FALSE;
    }

    brainstorm, 22 Апреля 2012

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

    +130

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    for(int j =0;j<d[i]/2;++j){
        char e[2] = {0,'\0'};
        const char* g = &e[0];
        e[0] = dict[i];
        s0.append(g);           
    }

    Нужен был const char*

    Abbath, 22 Апреля 2012

    Комментарии (4)
  9. Python / Говнокод #10015

    −98

    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
    # TODO: fix this hell
    def pretty_print(w, p):
        w = truncate(w)
        p = truncate(p)
        my_matrix = zip(p, w)
        print  "\n".join(["\t\t".join(["\t".join(map(str, r)) for r in t]) for t in my_matrix])        
    
    # TODO: and this
    def truncate(m):
        for i in range(len(m)):
            for j in range(len(m[0])):
                if(len(str(m[i][j])) > 5):
                    m[i][j] = "%.3f" % m[i][j]
        return m

    catcall, 22 Апреля 2012

    Комментарии (3)
  10. Java / Говнокод #10014

    +92

    1. 1
    "".equalsIgnoreCase(propertiesFile) != true

    индусское достояние

    Desperate, 22 Апреля 2012

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