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

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

    +4

    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
    public class tcMoveDirection
    		{
    			public enum tcDirection { R, L, N };
    			static public tcDirection fromstring(string expression)
    			{
    				switch (expression)
    				{
    					case "R":
    						return tcDirection.R;
    
    					case "L":
    						return tcDirection.L;
    
    					case "N":
    						return tcDirection.N;
    
    					default: throw new InvalidCastException();
    				}
    
    			}
    
    		}

    dm_fomenok, 23 Мая 2016

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

    +6

    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
    #include <iostream>
        using namespace std;
         
        struct One
        {
          bool operator==(const One &) { cout << "hello from One!" << endl; return true; }
          bool operator==(unsigned int) { cout << "hello from One!" << endl;  return true; }
        };
        One operator "" x( unsigned long long int ) { return One{}; }
        One operator "" xMAGICK( unsigned long long int ) { return One{}; }
         
        int main()
        {
          cout << (0xMAGICK == 0x);
         
          return 0;
        }

    http://ideone.com/gGYFce
    Расширяем множество шестнадцатеричных цифр при помощи UDL
    В C++17 осталось разрешить перегрузку операторов встроенных типов - вот тогда можно будет оторваться по-полной!

    gost, 05 Мая 2016

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

    +2

    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
    $vv = $_GET['new'];
    $v1 = $_GET['1'];
    $v2 = $_GET['2'];
    $v3 = $_GET['3'];
    $v4 = $_GET['4'];
    $v5 = $_GET['5'];
    $v6 = $_GET['6'];
    $v7 = $_GET['7'];
    $v8 = $_GET['8'];
    $v9 = $_GET['9'];
    $v10 = $_GET['10'];
    $v11 = $_GET['11'];
    $v12 = $_GET['12'];
    if (mb_strlen($vv) >= 1) {
    	mysql_query ("INSERT INTO vote (title, votes) VALUES ('$vv', '0')");
    	header('Location: /index.php');
    	exit;
    }
    if (mb_strlen($v1) >= 1 or mb_strlen($v2) >= 1 or mb_strlen($v3) >= 1 or mb_strlen($v4) >= 1 or mb_strlen($v5) >= 1 or mb_strlen($v6) >= 1 or mb_strlen($v7) >= 1 or mb_strlen($v8) >= 1 or mb_strlen($v9) >= 1 or mb_strlen($v10) >= 1 or mb_strlen($v11) >= 1 or mb_strlen($v12) >= 1) {
    	mysql_query ("UPDATE vote SET title='$v1' WHERE id='1'");
    	mysql_query ("UPDATE vote SET title='$v2' WHERE id='2'");
    	mysql_query ("UPDATE vote SET title='$v3' WHERE id='3'");
    	mysql_query ("UPDATE vote SET title='$v4' WHERE id='4'");
    	mysql_query ("UPDATE vote SET title='$v5' WHERE id='5'");
    	mysql_query ("UPDATE vote SET title='$v6' WHERE id='6'");
    	mysql_query ("UPDATE vote SET title='$v7' WHERE id='7'");
    	mysql_query ("UPDATE vote SET title='$v8' WHERE id='8'");
    	mysql_query ("UPDATE vote SET title='$v9' WHERE id='9'");
    	mysql_query ("UPDATE vote SET title='$v10' WHERE id='10'");
    	mysql_query ("UPDATE vote SET title='$v11' WHERE id='11'");
    	mysql_query ("UPDATE vote SET title='$v12' WHERE id='12'");
    	header('Location: /');
    	exit;
    }

    Сохранение вопросов в опроснике.

    slowpoke59rus, 27 Апреля 2016

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

    +6

    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
    public static List<string[]> split(string s)
        {
            bool ins = false;
            int no = 3;
            var L = new List<string>();
            var Res = new List<string[]>();
            var B = new StringBuilder();
            foreach (var c in s)
            {
                switch (c)
                {
                    case '§':
                        if (ins)
                        {
                            ins = false;
                            L.Add(B.ToString());
                            if (no == 0)
                            {
                                Res.Add(L.ToArray<string>());
                                L.Clear();
                                no = 3;
                            }
                        }
                        else
                        {
                            ins = true;
                            B.Clear();
                        }
                        break;
                    case '|':
                        if (!ins) { no--; }
                        else B.Append(c);
                        break;
                    default:
                        if (ins) B.Append(c);
                        break;
                }
            }
            return Res;
        }

    Судя по наименованиям - типичная лаба школьника.
    Однако, автор - Сошников - евангелист мелкософта. Тот самый, который F# пропагандирует (катается с одной и той же лекцией уже несколько лет по разным конференциям; и, кстати, принимают его всегда восторженно).
    Пруф: http://stackoverflow.com/a/36888673/5045688

    koodeer, 27 Апреля 2016

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

    +4

    1. 1
    A notice tag marks out-of-service equipment, such as a fire hydrant. Included is a guide member that has one or more guide channels and which is inserted into a connector body. The CNT array is patterned by using a patterned metallic seed layer on the substrate to form the CNT array by chemical vapor deposition. The pivot arm has a biasing mechanism with a force that results in less impact force between the pivot arm roller and drive roller when the trailing edge of each mail piece passes through the take-away nip, resulting in less vibration of the weighing platform as mail pieces exit the weighing platform. The process gas is exhausted from the chamber.

    Автоматическая генерация изобретений для общественного достояния
    https://geektimes.ru/post/274156/

    Вореции на страже от патентных троллей?

    kerman, 12 Апреля 2016

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

    +12

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    //Если кто-то пытается изменить стандартный отчет и не является Кириллом
    if (in_array($reportId, Default_Model_DbTable_SupplierReport::getInstance()->getStandardIds()) == true
    	&& $this->me->id != Default_Model_User::getKirill()->id
    ) {
    	return false;
    }

    jbot, 12 Апреля 2016

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

    +1

    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
    public class FileStorage {
            public FileStorage() {
                try {
                    if (String.IsNullOrEmpty(Common.GlobalVariables.FileStorage)) {
                        throw new Exception(Common.GuiHelper.ShowErrorMessage("FileStorage", String.Empty));
                    }
    
                    if (!Directory.Exists(Common.GlobalVariables.FileStorage)) {
                        DirectoryInfo di = Directory.CreateDirectory(Common.GlobalVariables.FileStorage);
                        if (!di.Exists) {
                            throw new Exception(Common.GuiHelper.ShowErrorMessage("FileStorageDir", String.Empty));
                        }
                    }
                } catch (Exception er) {
                    throw new Exception(er.Message);
                }
            }
    
            public String CreateFileDirectory() {
                try {
                    int iIdx = 0;
                    Boolean bIsCreated = false;
                    while (!bIsCreated && iIdx < 10) {
                        String sDir = Guid.NewGuid().ToString("N").ToLower();
                        sDir = sDir.Substring(0, 2);
                        if (!Directory.Exists(Common.GlobalVariables.FileStorage + sDir + @"\")) {
                            DirectoryInfo di = Directory.CreateDirectory(Common.GlobalVariables.FileStorage + sDir + @"\");
                            if (di.Exists) {
                                return Common.GlobalVariables.FileStorage + sDir + @"\";
                            }
                        }
    
                        iIdx++;
                    }
    
                    return null;
                } catch (Exception er) {
                    throw new Exception(er.Message);
                }
            }
        }

    может я чего не понимаю, но зачем?

    Lokich, 08 Апреля 2016

    Комментарии (5)
  9. JavaScript / Говнокод #19739

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if(this.options.raining){
          this.dropletsCounter+=this.options.dropletsRate*timeScale*this.areaMultiplier;
          times(this.dropletsCounter,(i)=>{
            this.dropletsCounter--; // зачем это тут?
            this.drawDroplet(
              random(this.width/this.scale),
              random(this.height/this.scale),
              random(...this.options.dropletsSize,(n)=>{
                return n*n;
              })
            )
    });

    завис на этой строке... https://github.com/codrops/RainEffect/blob/master/src/raindrops.js

    makc3d, 01 Апреля 2016

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

    +2

    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
    78. 78
    79. 79
    80. 80
    public interface ICachedObject<TCachedValue>
        {
            TCachedValue Value { get; set; } 
        } 
    
    public interface ICacheProvider<TCachedObject, TCachedValue>
            where TCachedObject : ICachedObject<TCachedValue>
        {
            TCachedObject Get(string key);
    
            void Set(string key, TCachedObject value);
    
            void Remove(string key);
    
            IEnumerable<TCachedObject> GetAll();
        }
    
    public class CachedEntityObject : ICachedObject<IEntity>
        {
            public EntityState State { get; set; }
    
            public IEntity Value { get; set; }
        }
    
        public abstract class CacheProvider<TCache, TCachedObject, TCachedValue> :
            ICacheProvider<TCachedObject, TCachedValue> 
            where TCache : IDictionary<string, TCachedObject>
            where TCachedObject : ICachedObject<TCachedValue>
        {
            protected TCache Cache;
    
            protected abstract void InitializationCache();
    
            public abstract TCachedObject Get(string key);
    
            public abstract void Set(string key, TCachedObject value);
    
            public abstract void Remove(string key);
    
            public abstract IEnumerable<TCachedObject> GetAll();
        }
    
     public class CacheEntity : CacheProvider<Dictionary<string, CachedEntityObject>, CachedEntityObject, IEntity>
        {
            public CacheEntity()
            {
                InitCache();
            }
    
            protected sealed override void InitCache()
            {
                Cache = new Dictionary<string, CachedEntityObject>();
            }
    
            public override CachedEntityObject Get(string key)
            {
                if (Cache[key] == null)
                    throw new NullReferenceException($"{nameof(key)} not found from cache list");
    
                return Cache[key];
            }
    
            public override void Set(string key, CachedEntityObject value)
            {
                Remove(key);
    
                Cache[key] = value;
            }
    
            public override void Remove(string key)
            {
                if (Cache.ContainsKey(key))
                    Cache.Remove(key);
            }
    
            public override IEnumerable<CachedEntityObject> GetAll()
            {
                return Cache.Values;
            }
        }

    Кэш сущностей

    Serega9I, 31 Марта 2016

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

    0

    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
    $f = fopen("./.htaccess", "r");
    			while (!feof($f)) {
    			    $tmp = fgets($f);
    			    $tmp = str_replace(REDIRECT_USER."/", $_POST["redir_user"]."/", $tmp);
    			    $tmp = str_replace(REDIRECT_SHOP."/", $_POST["redir_shop"]."/", $tmp);
    			    $tmp = str_replace(REDIRECT_ADMIN."/", $_POST["redir_admin"]."/", $tmp);
    			    $tmp = str_replace(REDIRECT_NEWS."/", $_POST["redir_news"]."/", $tmp);
    			    $tmp = str_replace(REDIRECT_CART."/", $_POST["redir_cart"]."/", $tmp);
    			    $tmp = str_replace(REDIRECT_PAYMENT."/", $_POST["redir_payment"]."/", $tmp);
    			    $tmp = str_replace(REDIRECT_INFO."/", $_POST["redir_info"]."/", $tmp);
    			    $line[] = $tmp;
    			}
    			fclose($f);

    Настройка редиректов из админки

    drop_database, 29 Марта 2016

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