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

    +170

    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
    if($pnumber < $max)
              {
                if ($number > 5) $start="<a class='guest' href=goods.php?page=".$page."&n=1 title=Первая страница>1</a>&nbsp;";
                if ($number < $pages-4) $last="&nbsp;<a class='guest' href=goods.php?page=".$page."&n=".$pages." title=Последняя страница>".$pages."</a>";
                if ($number > 4) $pointleft="... ";
                if ($number <= $pages-4) $pointright=" ...";
                if ($number != 1) $prevpage="<a class='guest' href=goods.php?page=".$page."&n=".($number-1)." title=Назад>&lt;&lt;</a>&nbsp;&nbsp;";
                if ($number != $pages) $nextpage="&nbsp;&nbsp;<a class='guest' href=goods.php?page=".$page."&n=".($number+1)." title=Вперед>&gt;&gt;</a>";
                if ($number-3 > 0) $page3left="<a class='guest' href=goods.php?page=".$page."&n=".($number-3)." title=Страница&nbsp;".($number-3).">".($number-3)."</a> | ";
                if ($number-2 > 0) $page2left="<a class='guest' href=goods.php?page=".$page."&n=".($number-2)." title=Страница&nbsp;".($number-2).">".($number-2)."</a> | ";
                if ($number-1 > 0) $page1left="<a class='guest' href=goods.php?page=".$page."&n=".($number-1)." title=Страница&nbsp;".($number-1).">".($number-1)."</a> | ";
                if ($number+1 <= $pages) $page1right=" | <a class='guest' href=goods.php?page=".$page."&n=".($number+1)." title=Страница&nbsp;".($number+1).">".($number+1)."</a>";
                if ($number+2 <= $pages) $page2right=" | <a class='guest' href=goods.php?page=".$page."&n=".($number+2)." title=Страница&nbsp;".($number+2).">".($number+2)."</a>";
                if ($number+3 <= $pages) $page3right=" | <a class='guest' href=goods.php?page=".$page."&n=".($number+3)." title=Страница&nbsp;".($number+3).">".($number+3)."</a>";
                echo "<tr><td colspan='2'><p style='text-align:center;'><font class='guest'>".$prevpage.$start.$pointleft.$page3left.$page2left.$page1left.$number."/".$pages.$page1right.$page2right.$page3right.$pointright.$last.$nextpage."</font></p></td></tr>";
              }

    Пейджинг страниц

    RReverser, 19 Декабря 2010

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

    +169

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    list($msec,$sec)=explode(chr(32),microtime());
    $HeadTime=$sec+$msec;
    // основной код скрипта
    list($msec,$sec)=explode(chr(32),microtime());
    echo "<b><center>Страница сгенерирована за: ".round(($sec+$msec)-$HeadTime,4)." секунд</center></b>";

    Такой оригинальный способ определения времени выполнения скрипта...

    DropWorld, 19 Декабря 2010

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

    +16

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    div.field.field-type-filefield.field-field-videofile,
    div.field.field-type-filefield.field-field-videoftp,
    .content .field-field-videofile div.field-items, 
    .content .field-field-videoftp div.field-items,
    .content .field-field-videofile div.field-item, 
    .content .field-field-videoftp div.field-item{clear:both;overflow:hidden;display:block;}
    .field-field-videofile div.field-label-inline-first, 
    .field-field-videofile div.field-label-inline,
    .field-field-videoftp div.field-label-inline-first,
    .field-field-videoftp div.field-label-inline{clear:both;overflow:hidden;display:block;visibility:visible;}

    Вот такой вот css родил. кстате где CSS разметко здеся?

    brainstorm, 19 Декабря 2010

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

    +170

    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
    try {
        @$ids = array_map(function($p)
       {
         static $index = 0;
         $index++; 
         if (is_numeric($p) && intval($p) == $p) 
           return intval($p); 
         else 
            throw new Exception("The element #{$index} is crap");
       }, 
       explode(',', $_COOKIE['integers']));
      }
       catch (Exception $e) {
        exit ("Uh oh! {$e->getMessage()}");
    }

    Это мы так парсим intы в куках

    eyeland, 19 Декабря 2010

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

    +169

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $stringPath = dirname(__FILE__);
    
    if (strstr($stringPath,":")) $stringExplode = "\\";
      else $stringExplode = "/";
           
    $paths = explode($stringExplode,$stringPath);

    Источник: http://www.php.net/manual/en/function.require.php#70463
    Автору срочно найти в том-же мануале: DIRECTORY_SEPARATOR

    XPSystemServices, 19 Декабря 2010

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

    +173

    1. 1
    if(!file_exists(getenv('SCRIPT_FILENAME'))) die('File not found)';

    Нет, ну а вдруг?!

    Flazher, 19 Декабря 2010

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

    +165

    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
    for ($i = $bstart; $i < $bend; $i++) 
    {
    	// ГЛАВНАЯ BASE НЕТУ
    	
    	if (empty($_REQUEST['base']) && $i == 1) 
    	{
    		$pagin .= '<strong><font color=#980101>' . $i . '</font></strong>&nbsp;&nbsp;';
    	}
    	if (empty($_REQUEST['base']) && $i != 1) 
    	{	
    		$b_start = (ARTICLE_VIEW * $i) - ARTICLE_VIEW;
    		$query_news = $sn . record_lanuage($page) . $ot . $b_start . ", " . ARTICLE_VIEW;
    		$res = mysql_query($query_news) or die(error($query_news));		
    		
    		if ($db->nr($res))
    		{
    			$pagin .= '<a href="http://' . $config['server_name'] . '/article.php?page=' . $_REQUEST['page'] . '&base=' . $i . $base_mmt . '">' . $i . '</a>&nbsp;&nbsp;';
    		}
    		else
    		{
    			$pagin .= '<font>' . $i . '</font>&nbsp;&nbsp;';
    		}
    		if ($i == $bend - 1 && $db->nr($res) != 0)
    		{
    			$pagin .= '<a href="http://' . $config['server_name'] . '/article.php?page=' . $_REQUEST['page'] . '&base=' . ($i + 1) . $base_mmt . '">&gt;</a>';
    		}
    	}
    	
    	// ГЛАВНАЯ BASE ЕСТЬ
    	
    	if (!empty($_REQUEST['base']) && $i < $_REQUEST['base']) 
    	{	
    		$pagin .= '<a href="http://' . $config['server_name'] . '/article.php?page=' . $_REQUEST['page'] . '&base=' . $i . $base_mmt . '">' . $i . '</a>&nbsp;&nbsp;';
    	}
    	if (!empty($_REQUEST['base']) && $i >= $_REQUEST['base']) 
    	{			
    		$b_start = (ARTICLE_VIEW * $i) - ARTICLE_VIEW;
    		$query_news = $sn . $q . $ot . $b_start . ", " . ARTICLE_VIEW;
    		
    		$res = mysql_query($query_news) or trigger_error($sql);
    		
    		if ($_REQUEST['base'] == $i) 
    		{
    			$pagin .= '<strong><font color=#980101>' . $i . '</font></strong>&nbsp;&nbsp;';
    		}
    		if ($_REQUEST['base'] < $i) 
    		{
    			if ($db->nr($res) != 0) 
    			{
    				$pagin .= '<a href="http://' . $config['server_name'] . '/article.php?page=' . $_REQUEST['page'] . '&base=' . $i . $base_mmt . '">' . $i . '</a>&nbsp;&nbsp;';
    			}
    			else
    			{
    				$pagin .= '<font>' . $i . '</font>&nbsp;&nbsp;';
    			}
    		}
    		if ($db->nr($res) != 0 && substr($i, strlen($i) - 1) == 0)
    		{
    			$pagin .= '<a href="http://' . $config['server_name'] . '/article.php?page=' . $_REQUEST['page'] . '&base=' . ($i + 1) . $base_mmt . '">&gt;</a>';
    		}
    	}
    }

    пагинация длиной в 130 строк и даже не функция, выложил только основную EPIC часть, которая существовала в отдельном файле!

    Genka, 19 Декабря 2010

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

    +81

    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
    public static void createShotAndSend() {
            Toolkit tool = Toolkit.getDefaultToolkit();
            Dimension screen = tool.getScreenSize();
    
            int w = screen.width;
            int h = screen.height;
            
            int x = MouseInfo.getPointerInfo().getLocation().x-W/2;
            int y = MouseInfo.getPointerInfo().getLocation().y-H/2;
    
    
            if(x == ox && y == oy) {
                return;
            }
    
            ox = x;
            oy = y;
    
            int sx = Math.min(Math.max(x, 0), w-W);
            int sy = Math.min(Math.max(y, 0), h-H);
    
            BufferedImage capture;
            try {
                capture = (new Robot()).createScreenCapture(new Rectangle(sx, sy, W, H));
            } catch (AWTException ex) {
                System.err.println("Failed screen capturing!");
                return;
            }
    
            ByteArrayOutputStream data = new ByteArrayOutputStream();
            try {
                ImageIO.write(capture, "JPG", data);
            } catch (IOException ex) {
                System.err.println("Failed writing capture!");
                return;
            }
    
            byte[] toSend = data.toByteArray();
            int l = data.size();
            byte[] size = itob(l);
    
            //pool - Client[]
            for(int i = 0; i < pool.length; i++) {
                if(pool[i] == null) continue;
                if(!pool[i].isActive()) continue;
    
                pool[i].send(size, 0, 4);
                pool[i].send(toSend, 0, l);
            }
        }

    делаем скриншот. квадратом в 100 пикселей (курсор в центре).

    danilissimus, 19 Декабря 2010

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

    +165

    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
    function passgen( $length )
    {
        if( $_SERVER['REQUEST_METHOD'] == 'POST' )
        {
            $length = (int) $length;   
            $pass = "";
            for( $i = 0; $i < $length; $i ++ ) {
                if( isset( $_POST['uc'] ) ) {
                    $j = mt_rand( 1, 10 );
                        if( $j % 3 )
                            $pass .= chr( mt_rand( 97, 122 ) ) ;
                        else
                            $pass .= chr( mt_rand( 65, 90 ) ) ;
                } else 
                    $pass .= chr( mt_rand( 97, 122 ) ) ;    
            }   
            return $pass;
        }
    }

    Ice, 19 Декабря 2010

    Комментарии (57)
  10. Python / Говнокод #4976

    −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
    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
    import sys
    from ru.hastel.gameserver.model.quest import State
    from ru.hastel.gameserver.model.quest import QuestState
    from ru.hastel.gameserver.model.quest.jython import QuestJython as JQuest
    
    qn = "2008_christmas"
    
    class Quest (JQuest) :
    
     def __init__(self,id,name,descr): JQuest.__init__(self,id,name,descr)
    
     def onEvent (self,event,st) :
        htmltext = event
    
        if event == "1":
            if st.getQuestItemsCount(5556) >= 4 and st.getQuestItemsCount(5557) >= 4 and st.getQuestItemsCount(5558) >= 10 and st.getQuestItemsCount(5559) >= 1:
                st.takeItems(5556,4)
                st.takeItems(5557,4)
                st.takeItems(5558,10)
                st.takeItems(5559,1)
                st.giveItems(5560,1)
                htmltext = "<html><body>Merry Christmas.</body></html>"
            else:
                 htmltext = "31863-2.htm"
        elif event == "2":
            if st.getQuestItemsCount(5560) >= 10 :
                st.takeItems(5560,10)
                st.giveItems(5561,1)
                htmltext = "<html><body>Merry Christmas.</body></html>"
            else:
                 htmltext = "31863-3.htm"
        if htmltext != event:
          st.setState(COMPLETED)
          st.exitQuest(1)
    
        return htmltext
    
    
     def onTalk (self,npc,player):
        st = player.getQuestState(qn)
        if not st : return 
        npcId = npc.getNpcId()
        if npcId == 31863 :
           htmltext = "31863-1.htm"
           st.setState(STARTED)
        return htmltext
    
    
    
    QUEST       = Quest(2008,qn,"custom")
    CREATED     = State('Start', QUEST)
    STARTED     = State('Started', QUEST)
    COMPLETED   = State('Completed', QUEST)
    
    QUEST.setInitialState(CREATED)
    
    QUEST.addStartNpc(31863)
    QUEST.addTalkId(31863)

    Вот простенький эвент на Питоне , как улучшить подскажите

    Akira, 19 Декабря 2010

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