1. Лучший говнокод

    В номинации:
    За время:
  2. ActionScript / Говнокод #6080

    −89

    1. 1
    2. 2
    3. 3
    4. 4
    if(b==0){B[b].addChild(ch1)}
    if(b==1){B[b].addChild(ch2)}
    if(b==2){B[b].addChild(ch3)}
    if(b==3){B[b].addChild(ch4)}

    Ну вот так все просто... дело было в три часа утра

    -M-, 24 Марта 2011

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    function plural_filter($param) {
      if(strstr($param, 'Hotels'))
        return str_replace('Hotels', 'Hotel', $param);
      else if(strstr($param, 'Restaurants'))
        return str_replace('Restaurants', 'Restaurant', $param);
      else
        return $param;
    }

    no comments xD

    realsugar, 22 Марта 2011

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

    +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
    <?php
    // Calculate the age from a given birth date
    // Example: GetAge("1986-06-18");
    function GetAge($Birthdate)
    {
            // Explode the date into meaningful variables
            list($BirthYear,$BirthMonth,$BirthDay) = explode("-", $Birthdate);
            // Find the differences
            $YearDiff = date("Y") - $BirthYear;
            $MonthDiff = date("m") - $BirthMonth;
            $DayDiff = date("d") - $BirthDay;
            // If the birthday has not occured this year
            if ($DayDiff < 0 || $MonthDiff < 0)
              $YearDiff--;
            return $YearDiff;
    }
    ?>

    добыто в интернете.
    Опять пхп и опять даты. Похоже, это вечное...

    Lure Of Chaos, 20 Марта 2011

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

    −101

    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
    вопрос:
    есть массив $friends[id1] и friends2[id2] можно ли их объединить?
    
    ответ:
    $friends[id1] .= $friends2[id2];//(точка перед равно)
    
    Помогло?
    
    если ключи есть совпадающие
    foreach($friends2[id2] as $key=>$item)
    {
        $friends[id1][$key.'_2']=$item;
    }
    
    
    ну или с проверкой
    foreach($friends2[id2] as $key=>$item)
    {
        if(isset($friends[id1][$key]))// проверка на существование ключа
        {
            $friends[id1][$key.'_2']=$item;
        }
        else
        {
            $friends[id1][$key]=$item;
        }
    }
    
    
    можно усложнить
    foreach($friends2[id2] as $key=>$item)
    {
        if(isset($friends[id1][$key]) && $friends[id1][$key]!==$item)// проверка на существование ключа и совпадение с существующим значением ключа первого массива
        {
                $friends[id1][$key.'_2']=$item;
        }
        else
        {
            $friends[id1][$key]=$item;
        }
    }
    вот

    мой говнокод))

    Snickers, 20 Марта 2011

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

    +159

    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
    <?php
    /* Подключаемые файлы */
    require_once('data/config.test.php');
     
    /**
    * Сохранение настроек модуля
    */
    if ($action == "dosave") {
        $find[]     = "'\r'";
        $replace[]  = "";
        $find[]     = "'\n'";
        $replace[]  = "";
     
    if ($member_db[1] != 1) {
        msg ("error", $lang['opt_denied'], $lang['opt_denied']);
    }
    $handler = @fopen('data/config.test.php', "wb");
    fwrite ($handler, "<?php \n\n//Test configurations
                             \n\n\$config_test = array(
                             \n\n'version' => \"v.1.0\",\n\n");
     
    foreach ($save_con as $name => $value) {    
        $value = trim(stripslashes ($value));
        $value = htmlspecialchars  ($value, ENT_QUOTES);
        $value = preg_replace($find, $replace, $value);
        fwrite($handler, "'{$name}' => \"{$value}\",\n\n");
    }
        
    fwrite($handler, ");\n\n?>");
    fclose($handler);
     
    msg ("info", "Строка изменена",
         "{$lang['opt_sysok_1']}<br /><br />
          <a href=\"{$PHP_SELF}?mod=test_adm\">{$lang['db_prev']}</a>");
    }
    echo"Шапка";
    echo<<<HTML
    <form action="" method="POST">
    <table width="100%">
      <tr>
        <td class="option" style="padding:4px;">
          <b> Текст выводимой строки: </b><br />
          <span class="small"> например: Hello world </span>
        <td align="middle" width="400">
          <input class="edit" style="text-align:center" size="40" value="{$config_test['text']}" name="save_con[text]"></td>
      </tr>
      
      <tr>
        <td class="option" style="padding:4px;">
           <b> Комментарий к тексту: </b><br />
           <span class="small"> например: Это ваш первый пример модуля с админпанелью </span>
        <td align="middle" width="400">
           <input class="edit" style="text-align:center" size="40" value="{$config_test['detail']}" name="save_con[detail]"></td>
      </tr>
    
      <tr>
        <td class="option" style="padding-bottom:10px; padding-top:10px; padding-left:10px;" colspan="2">
          <input class="buttons" type="hidden" name="action" value="dosave" />
          <input class="buttons" type="submit" name="do" value=" Сохранить " /></td>
      </tr>
      
    </table>
    </form>
    HTML;
    echo"Подвал";
    ?>

    qbasic, 19 Марта 2011

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

    +162

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    /**
    	 * Test to see if the cache storage is available.
    	 *
    	 * @static
    	 * @access public
    	 * @return boolean  True on success, false otherwise.
    	 */
    	function test()
    	{
    		return true;
    	}

    Описание метода в коментах.
    Joomfish

    tranquillity, 16 Марта 2011

    Комментарии (4)
  8. C# / Говнокод #6002

    +114

    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
    [Serializable()]
    	public class Vendor
    	{
    		#region Constructors
    
    		public Vendor(long vendorID)
    		{
    			LoadData(vendorID);
    		}
    
    		internal Vendor(Vendor argVendor)
    		{
    			if (argVendor != null)
    			{
    				this.ID = argVendor.ID;
    				this.VendorName = argVendor.VendorName;
    				this.Account = argVendor.VendorAccount;
    				this.EIN = argVendor.VendorEIN;
    				this.Address = argVendor.VendorAddress;
    				this.City = argVendor.VendorCity;
    				this.State = argVendor.VendorState;
    				this.PostalCode = argVendor.VendorZip;
    				this.Phone = argVendor.VendorPhone;
    				this.ContactName = argVendor.VendorContact;
    				this.VendorCode = argVendor.VendorCode;
    				this.Country = argVendor.VendorCountry;
    				this.FaxNumber = argVendor.VendorFax;
    				this.Email = argVendor.Email;
    			}
    		}
    		#endregion
    
    		public void LoadData(long vendorID)
    		{
    			POMRepositoryDataClassesDataContext db = new POMRepositoryDataClassesDataContext();
    			var ven = (from v in db.Vendors
    					   where v.ID == vendorID
    					   select v).SingleOrDefault();
    			if (ven != null)
    			{
                    populateMe(ven);
    			}
    		}
            public void LoadDataByVendorCode(string argVendorCode)
            {
                POMRepositoryDataClassesDataContext db = new POMRepositoryDataClassesDataContext();
                var ven = (from v in db.Vendors
                           where v.VendorCode == argVendorCode
                           select v).Take(1).SingleOrDefault();
                if (ven != null)
                {
                    populateMe(ven);
                }
            }
            private void populateMe(Vendor ven)
            {
                this.ID = ven.ID;
                this.VendorName = ven.VendorName;
                this.Account = ven.VendorAccount;
                this.EIN = ven.VendorEIN;
                this.Address = ven.VendorAddress;
                this.City = ven.VendorCity;
                this.State = ven.VendorState;
                this.PostalCode = ven.VendorZip;
                this.Phone = ven.VendorPhone;
                this.ContactName = ven.VendorContact;
                this.VendorCode = ven.VendorCode;
                this.Country = ven.VendorCountry;
    	    this.FaxNumber = ven.VendorFax;
    	    this.Email = ven.Email;
            }
    }

    No comments!!!

    Arterius, 16 Марта 2011

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

    +161

    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
    elseif(isset($_GET['del']))
    {
        foreach($_POST as $id=>$a)
        {
            mysql_query("DELETE FROM `{$prefixbd}$table` WHERE `id`='".intval($id)."'")or die(mysql_error());
            @chmod(ret_img($file_path.$id),0777);
            @unlink(ret_img($file_path.$id));
            @chmod(ret_img($file_path.$id.'_big'),0777);
            @unlink(ret_img($file_path.$id.'_big'));
            $sql=mysql_query("SELECT FROM `{$prefixbd}{$table}_img` WHERE `prod`='".intval($id)."'")or die(mysql_error());
            while($data=mysql_fetch_assoc($sql)){
                @chmod(ret_img($file_path.$id.'_'.$data['id'].'_add'),0777);
                @unlink(ret_img($file_path.$id.'_'.$data['id'].'_add'));
                @chmod(ret_img($file_path.$id.'_big_'.$data['id'].'_add'),0777);
                @unlink(ret_img($file_path.$id.'_big_'.$data['id'].'_add'));
                mysql_query("DELETE FROM `{$prefixbd}{$table}_img` WHERE `id`='".$data['id']."'");
            }
        }

    Обратите внимание как удаляет файлы)) исходник из некого chrono CMS

    dobs2005, 16 Марта 2011

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

    +163

    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
    <?php
    set_time_limit(0);
    $d    = 0;
    $t    = 0;
    $link = mysql_connect('localhost', 'root', '123456'); // or die(mysql_error());
    //mysql_query('SET NAMES `cp1251`') or die(mysql_error());
    $dbr = mysql_query('SHOW DATABASES') or die(mysql_error());
    while ($dbd = mysql_fetch_assoc($dbr)) {
        if ($dbd['Database'] != 'information_schema') {
            mysql_select_db($dbd['Database'], $link); // or die(mysql_error());
            $tr  = mysql_query('SHOW  TABLES'); // or die(mysql_error());
            $sql = '';
            while ($td = mysql_fetch_assoc($tr)) {
                $sql .= '`' . $td['Tables_in_' . $dbd['Database']] . '`, ';
                ++$t;
            }
            $sql = substr($sql, 0, -2);
            mysql_query('REPAIR TABLE  ' . $sql . ''); // or die(mysql_error());
            ++$d;
        }
    }
    echo 'Востановил: ' . $d . ' баз(ы) данных, общие кол-во таблиц: ' . $t;
    mysql_close($link);

    Делает "REPAIR" всех баз данных.

    Unknown, 14 Марта 2011

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

    −94

    1. 1
    2. 2
    mCharInfoContent.x += ( hexTile.x + hexTile.parent.x + hexTile.parent.parent.x + hexTile.parent.parent.parent.x );
    mCharInfoContent.y += ( hexTile.y + hexTile.parent.y + hexTile.parent.parent.y + hexTile.parent.parent.parent.y );

    Красота неописуемая, метод научного тыка в действии

    Werdn, 11 Марта 2011

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