1. Perl / Говнокод #5763

    −123

    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
    sub initialize  # Действия выполняемые непосредственно перед стартом цикла если мы ведём базу, что бы подгрузится из неё!!!!!
    {
    	my $bc = shift; 
    
    	if ( $bc->{const}{jnl} eq "1" )
    	{
    		$bc->{variable}{ip_addr} = run_shell_script("ip a", 'l');
    
    		open JNL, '<', $bc->{const}{base_jnl};
    		undef $\;
    		my @jnl_strings = <JNL>;
    		close JNL;
    
    		my $ip_regext = qr/(?:[0-9]\.|[0-9]{2}\.|[0-2][0-9]{2}\.){3}(?:[0-9]|[0-9]{2}|[0-2][0-9]{2})/;
    
    		map
    		{
    			chomp;
    
    			if (/^($ip_regext);(.*);($ip_regext);(.*);opt\[ip_v_2:(.*),(.*);int_2:(.*),(.*),(.*)\]$/)
    			{
    				my ( $s1, $s2, $s3, $s4, $s5, $s6, $s7, $s8, $s9 ) = ( "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9" );
    
    				if ( dynamic_comparison_ip($bc, $s1, $s3, $s5, $s8) == '1' )
    				{
    					cut_jnl($bc, $s1, '');
    				}
    				else
    				{
    					$bc->{variable}{base_virtual_ip}{$s1} = $s3;
    					$bc->{variable}{base_mask_v_ip}{$s1} = $s2;
    					$bc->{variable}{base_id}{$s1} = $s4;
    					$bc->{variable}{base_addit_v_ip}{$s1} = $s5;
    					$bc->{variable}{base_mask_v_ip_addit}{$s1} = $s6;
    					$bc->{variable}{base_addit_dev}{$s1} = $s7;
    					$bc->{variable}{base_addit_ip}{$s1} = $s8;
    					$bc->{variable}{base_mask_ip_addit}{$s1} = $s9;
    					$bc->{variable}{base_info_T}{$s1} = $bc->{variable}{no_info_T_max};
    					$bc->{variable}{base_delay}{$s1} = 0;
    					$bc->{const}{info}->debug("String $_ has been added in dynamic base");
    
    					push @{$bc->{variable}{base_load_conf}}, $s1; # Формируем базу загруженных из файла
    
    					$bc->{variable}{intrf_eth0} = Modules_SR::Ifconfig_all->new(
    						"$bc->{config_params}{HOST}", 
    						"$bc->{variable}{base_mask_v_ip}{$s1}");
    
    					if ($bc->{variable}{base_addit_v_ip}{$s1})
    					{
    						$bc->{variable}{intrf_eth00} = Modules_SR::Ifconfig_all->new("
    							$bc->{config_params}{HOST}", 
    							"$bc->{variable}{base_mask_v_ip_addit}{$s1}"); 
    					}
    					
    					if ($bc->{variable}{base_addit_dev}{$s1})
    					{
    						$bc->{variable}{intrf_eth1} = Modules_SR::Ifconfig_all->new(
    							"$bc->{variable}{base_addit_dev}{$s1}", 
    							"$bc->{variable}{base_mask_ip_addit}{$s1}");  
    					}
    
    					check_stop_status($bc, "$s1");
    				}
    			}
    			else
    			{
    				$bc->{const}{info}->debug("String $_ hasn't been added in dynamic base");
    				$bc->{const}{warning}->debug("String $_  has incorrect format!!!");
    			}
    		} @jnl_strings;
    	}
    } # end Действия выполняемые непосредственно перед стартом цикла

    Всё оттуда же. Инициализация объекта. Теперь делать через map {} стало, по-видимому, модно. Куча непонятно зачем нужных переменных и полей... FACEPALM...

    SadKo, 22 Февраля 2011

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

    −124

    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
    if ($bc->{variable}{status} eq "1" && $bc->{variable}{wait} eq "mmua" &&    # Действия при получении подтверждения старта
    			$bc->{const}{data} =~ /^MMUA\(mkd;$bc->{config_params}{VIRTUAL_IP};.*;$bc->{config_params}{HOST};$bc->{config_params}{TCM_ID};.*;.*\)$/)
    	{
    #		$bc->{const}{info}->debug("START ACCEPT");
    		
    		$bc->{const}{console_out} = "1.Answer SR-Slave: ok\n";
    		
    		my $res = check_virtual_ip($bc, "0", "0", "1", "$bc->{config_params}{VIRTUAL_IP}");
    		$bc->{const}{info}->debug("check_virtual_ip = $res");
    
    		unless ($res =~ /.*exist already and not local.*/)
    		{
    			EXECUTE_START($bc);
    			$bc->{const}{info}->debug("Start permit");
    		}
    		else
    		{
    			$bc->{const}{info}->debug("Start not recommend");
    		}
    
    		$bc->{const}{console_out} .= "2.Answer check_virtual_ip: " . $res;
    		open (RESPONSE, ">$bc->{const}{res_start}");
    		print RESPONSE $bc->{const}{console_out};
    		close RESPONSE;
    	}
    	elsif ($bc->{variable}{status} eq "1" && $bc->{variable}{wait} eq "mmua") # Действия при ожидании подтверждения от Сервера старта
    	{
    #		$bc->{const}{info}->debug("START ACCEPT WAIT");
    		
    		if ( $bc->{variable}{var_T1} >=  $bc->{variable}{T1} )
    		{
    			$bc->{const}{console_out} = "1.Answer SR-Slave: slave doesn't answer\n";
    			
    			my $res = check_virtual_ip($bc, "0", "0", "1", "$bc->{config_params}{VIRTUAL_IP}");
    			$bc->{const}{info}->debug("check_virtual_ip = $res");
    
    			unless( $res =~ /.*exist already and not local.*/ )
    			{
    				EXECUTE_START($bc);
    				$bc->{const}{info}->debug("Start permit");
    			}
    			else
    			{
    				$bc->{const}{info}->debug("Start not recommend");
    			}
    
    			$bc->{const}{console_out} .= "2.Answer check_virtual_ip: " . $res;
    
    			open (RESPONSE, ">$bc->{const}{res_start}");
    			print RESPONSE $bc->{const}{console_out};
    			close RESPONSE;
    		}
    		else
    		{
    			++$bc->{variable}{var_T1};
    		}
    ### Возможно жопа здесь !!!!!
    	}
    	elsif (-e $bc->{const}{req_restart} or $bc->{variable}{before_start} eq '1') # Действия при обноружении рестарта ручного или при первом запуске
    	{
    #		$bc->{const}{info}->debug("FIRST START / RESTART");
    		
    		unlink $bc->{const}{req_restart};
    		unlink $bc->{const}{req_restart_program};
    		unless($bc->{variable}{before_start})
    		{
    			$bc->{const}{info}->debug("Found restart.req");
    		}
    		else
    		{
    			$bc->{const}{info}->debug("Starting MASTER -> send MMU...");	      
    		}	      
    
    		send_mmu ($bc, "1", "mmua-for-restart");
    		$bc->{variable}{delay} = $bc->{variable}{delay_max};
    		$bc->{variable}{before_start} = 2 if ($bc->{variable}{before_start} eq '1');   # Не будем отправлять INFO, пока не прийдёт подтверждение MMUA
    	}

    Ещё несколько перлов из утилиты. Так записываем конечный автомат по функционированию протокола. Привёл только маленький кусочек из цепочки IF'ов.

    SadKo, 22 Февраля 2011

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

    +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
    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
    <html>
    <head>
    <title>Красивое облао тегов</title> 
    <script type="text/javascript" src="swfobject.js"></script>
    </head>
    <body>
    
    <div id="tags">
    
    <?php
    $tags = '<tags>
    <a href="http://Wincert.ru" style="font-size: 15pt">Wincert</a>
    <a href="http://W-blog.ru" style="font-size: 15pt">Мой блог</a>
    <a href="http://cssor.ru" style="font-size: 15pt">Крутой сайт о CSS</a>
    <a href="http://Wincert.ru" style="font-size: 15pt">Веб разработчик</a>
    <a href="http:// W-blog.ru" style="font-size: 15pt">Интересное</a>
    </tags>';
    ?>
    Для корректного отображения этого элемента вам необходимо установить FlashPlayer и включить в браузере Java Script.
    <script type="text/javascript">
    var rnumber = Math.floor(Math.random()*9999999);
    var widget_so = new SWFObject("tagcloud.swf?r="+rnumber, "tagcloudflash", "230", "140", "9", "#ffffff");
    widget_so.addParam("allowScriptAccess", "always");widget_so.addVariable("tcolor", "0x333333");
    widget_so.addVariable("tspeed", "115");
    widget_so.addVariable("distr", "true");
    widget_so.addVariable("mode", "tags");
    widget_so.addVariable("tagcloud", "<?php echo urlencode($tags); ?>");
    widget_so.write("tags");</script> 
    
    </div>
    
    </body>
    </html>

    qbasic, 22 Февраля 2011

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

    +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
    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
    <script type="text/javascript" src="swfobject.js"></script>
    <script type="text/javascript">
    	function  myTags(mytags){
    		mytags=mytags.replace(/<A/g, '<a')
    			.replace(/\/A>/g, "/a>")
    			.replace(/(\starget=_)(\w*)/g, ' target="_$2"')
    			.replace(/(\sclass=)(?!")(\w*)/g, ' class="$2"')
    			.replace(/(\sname=)(?!")(\w*)/g, ' name="$2"')
    			.replace(/(\sid=)(?!")(\w*)/g, ' id="$2"')
    			.replace(/(\srel=)(?!")(\w*)/g, ' rel="$2"');
    		mytags=encodeURIComponent(mytags).replace(/!/g, '%21')
    			.replace(/'/g, '%27').replace(/\(/g, '%28')
    			.replace(/\)/g, '%29').replace(/\*/g, '%2A');
    		var rnumber = Math.floor(Math.random()*9999999);
    		var flashvars = {
    			tcolor:"0x2A62C8",
    			tcolor2:"0x000000",
    			hicolor:"0xB12AC8",
    			tspeed:"110",
    			distr:"true",
    			mode:"tags",
    			tagcloud:mytags
    		};
    		var params = {
    			allowScriptAccess:"always",
    			bgcolor:'#ffffff'
    		};
    		var attributes = {
    			id:"flash_cloud"
    		};
    		swfobject.embedSWF("tagcloud.swf?r="+rnumber,
    						   "tags", "600", "420", "9.0.0",
    						   "expressInstall.swf", flashvars,
    						   params, attributes);
    	}
    	window.onload=function(){
    		var mytags="<tags>"
    		+document.getElementById('tags').innerHTML
    		+"</tags>";
    		myTags(mytags);
    	};
    </script>

    qbasic, 22 Февраля 2011

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

    +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
    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
    <?
    //include('../root/start.php');
    include('start.php');
    
    
    
    
    $hotels_menu_id = GetSettingsParam('hotels_menu_id');
    
    if ($image_id = $_GET['image_id']) {
        $row = mysql_fetch_assoc(mysql_query(
                        'select co.id co_id, co.title co_title, ' .
                        'ci.id ci_id, ci.title ci_title, ' .
                        'h.id h_id, h.title h_title ' .
                        'from ' . _mysql_tbl_prefix . 'countries co ' .
                        'left join ' . _mysql_tbl_prefix . 'cities ci on co.id = ci.country_id ' .
                        'left join ' . _mysql_tbl_prefix . 'hotels h on ci.id = h.city_id ' .
                        'left join ' . _mysql_tbl_prefix . 'hotel_images hi on hi.hotel_id = h.id ' .
                        'where hi.image_id = ' . $image_id));
        echo mysql_error();
    # $src = '../../hotel_images/'.(int)($image_id/2000).'/'.$image_id.'.jpg';
        $src = './hotel_images/' . (int) ($image_id / 2000) . '/' . $image_id . '.jpg';
    }
    ?>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
            <title>Фото отеля "<?= $row['h_title'] ?>" (<?= $row['ci_title'] . ', ' . $row['co_title'] ?>) - Туроператор</title>
        </head>
        <link rel="stylesheet" href="../hotel_image.css">
        <body>
            <table height="100%" width="100%">
                <tr>
                    <td valign="middle" align="center">
                        <h1 class="hotel-image-title"><?=
    'Фото отеля "<a href="../index.php?menu_id=' . $hotels_menu_id . '&hotel_id=' . $row['h_id'] . '">' . $row['h_title'] . '</a>" ' .
            '(<a href="../index.php?menu_id=' . $hotels_menu_id . '&city_id=' . $row['ci_id'] . '">' . $row['ci_title'] . '</a>, ' .
            '<a href="../index.php?menu_id=' . $hotels_menu_id . '&country_id=' . $row['co_id'] . '">' . $row['co_title'] . '</a>)'
    ?></h1>
                        <a href="#" onClick="window.close()"><img src="<?= $src ?>" class="hotel-image" alt="Фото отеля "<?= $row['h_title'] ?>" (<?= $row['ci_title'] . ', ' . $row['co_title'] ?>)"></a>
                    </td>
                </tr>
            </table>
        </body>
    </html>

    Попросили так сазать исправить))
    я был ошеломлен "магическим числом" 2000

    rainerg, 22 Февраля 2011

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

    +146

    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
    package gargoyle.xenox.game;
    
    import gargoyle.util.log.Log;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.Serializable;
    
    @SuppressWarnings("rawtypes")
    public abstract class Persistent<T extends Persistent> implements Serializable {
      private static final long serialVersionUID = 1L;
    
      private File file(final Class<? extends Persistent> clazz) {
        return new File(System.getProperty("user.home"), clazz.getName() + ".dat");
      }
    
      @SuppressWarnings("unchecked")
      final protected T load(final Class<T> clazz) {
        ObjectInputStream in;
        try {
          in = new ObjectInputStream(new FileInputStream(this.file(clazz)));
          return (T) in.readObject();
        } catch (final IOException e) {
          Log.error(e);
        } catch (final ClassNotFoundException e) {
          Log.error(e);
        }
        return null;
      }
    
      final protected void save(final T o) {
        ObjectOutputStream os = null;
        try {
          os = new ObjectOutputStream(new FileOutputStream(this.file(o.getClass())));
          os.writeObject(this);
          os.flush();
        } catch (final IOException e) {
          Log.error(e);
        } finally {
          try {
            if (os != null) {
              os.close();
            }
          } catch (final IOException e) {
            Log.error(e);
          }
        }
      }
    }

    такой вот забавный сериализатор получился
    причина - запутался в генериках

    Lure Of Chaos, 21 Февраля 2011

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

    +165

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    template<typename Class>
    void Raise(int Code)
    {
      throw Class(Code);
    };

    Продолжение эпоса из уже всем знакомого проекта, доставшегося по наследству, в котором активно используются исключния.

    Говногость, 21 Февраля 2011

    Комментарии (44)
  8. ActionScript / Говнокод #5756

    −102

    1. 1
    import com.adobe.protocols.dict.events.ErrorEvent;

    Ну хоть бы циферку добавили...

    wvxvw, 21 Февраля 2011

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

    +84

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    transDate = ( ExtBaApiStaging.class.equals( extExcep.getClass() ) )?((ExtBaApiStaging)extExcep).getBeginDate():
    		( ExtRsApiCancel.class.equals( extExcep.getClass() ) )?((ExtRsApiCancel)extExcep).getTransDate():
    		( ExtRsApiWriteCustContact.class.equals( extExcep.getClass() ) )?((ExtRsApiWriteCustContact)extExcep).getTransDate():
    		( ExtRsApiPayAdjust.class.equals( extExcep.getClass() ) )?((ExtRsApiPayAdjust)extExcep).getTransDate():
    		( ExtRsApiChgCustomer.class.equals( extExcep.getClass() ) )?((ExtRsApiChgCustomer)extExcep).getTransDate():
    		( ExtRsApiChgService.class.equals( extExcep.getClass() ) )?((ExtRsApiChgService)extExcep).getTransDate():
    		( ExtRsApiChgBoxData.class.equals( extExcep.getClass() ) )?((ExtRsApiChgBoxData)extExcep).getTransDate():
    		( ExtCLApiIsfMnp.class.equals( extExcep.getClass() ) )?((ExtCLApiIsfMnp)extExcep).getLoadDate():
    		( ExtCLApiNoTruckSro.class.equals( extExcep.getClass() ) )?((ExtCLApiNoTruckSro)extExcep).getLoadDate():
    		( ExtCLApiNsfHoldEcOsa.class.equals( extExcep.getClass() ) )?((ExtCLApiNsfHoldEcOsa)extExcep).getLoadDate():
    		( ExtRsApiSendAHit.class.equals( extExcep.getClass() ) )?((ExtRsApiSendAHit)extExcep).getTransDate() : null;

    Это писала одна тимлид

    tr00_gr1m_doomster, 21 Февраля 2011

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

    −123

    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
    sub check_interface
    {
    	my $int_input = shift;
    	my $all_intr_local = [];
    	$_ = qx[ip a];
    	s[\d{1,}:[ ]{1,}([^ ]{1,}):.*]<unshift(@$all_intr_local, $1)>ge;
    	if ( ! grep( { /^$config_params{$int_input}$/ } @$all_intr_local ))
    	{
    		$warning->debug("Error: interface $int_input can't found local!!!");
    		exit 1;         
    	}
    	else
    	{
    		$info->debug("Load param $int_input = $config_params{$int_input}.");   
    	}
    }

    А вот так мы сканируем сетевые интерфейсы...

    SadKo, 21 Февраля 2011

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