1. C# / Говнокод #16924

    +132

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    SqlConnection cmdConnection = GetSKDConnection();
    cmdConnection.Open();
    SqlCommand resetCardCmd = new SqlCommand("UPDATE hPerson SET CurrentCardNr=NULL WHERE PersonalNr='" + pass.Number.TrimStart('0'), cmdConnection);
    resetCardCmd.CommandText = "DELETE FROM bCardData WHERE CardFK=" + (from pf in pass.PassFieldList where pf.FieldTypeName == "radio" select pf).Single().Card.CardNumber;
    resetCardCmd.ExecuteNonQuery();

    Мне кажется, или что то важное точно не произойдет?

    SantePaulinum, 24 Октября 2014

    Комментарии (0)
  2. bash / Говнокод #16923

    −117

    1. 1
    SET_CCC="CCC= ${CCC}"

    Где-то в макросах для autotools.

    bormand, 24 Октября 2014

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

    −93

    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
    # Source: python3.4/distutils/dir_util.py
    
    
    # cache for by mkpath() -- in addition to cheapening redundant calls,
    # eliminates redundant "creating /foo/bar/baz" messages in dry-run mode
    _path_created = {}
    
    # I don't use os.makedirs because a) it's new to Python 1.5.2, and
    # b) it blows up if the directory already exists (I want to silently
    # succeed in that case).
    def mkpath(name, mode=0777, verbose=1, dry_run=0):
        """Create a directory and any missing ancestor directories.
    
        If the directory already exists (or if 'name' is the empty string, which
        means the current directory, which of course exists), then do nothing.
        Raise DistutilsFileError if unable to create some directory along the way
        (eg. some sub-path exists, but is a file rather than a directory).
        If 'verbose' is true, print a one-line summary of each mkdir to stdout.
        Return the list of directories actually created.
        """
    
        global _path_created
    
        # Detect a common bug -- name is None
        if not isinstance(name, basestring):
            raise DistutilsInternalError, \
                  "mkpath: 'name' must be a string (got %r)" % (name,)
    
        # XXX what's the better way to handle verbosity? print as we create
        # each directory in the path (the current behaviour), or only announce
        # the creation of the whole path? (quite easy to do the latter since
        # we're not using a recursive algorithm)
    
        name = os.path.normpath(name)
        created_dirs = [] 
        if os.path.isdir(name) or name == '':
            return created_dirs
        if _path_created.get(os.path.abspath(name)):
            return created_dirs
        ...

    Мало того, что метод жив на основании того, что os.makedirs был добавлен только в Python 1.5.2 (мама родная, 2.7 скоро закопаем, а говно всё тянется), так его ещё и умудрились наиндусить на 60 строк кода, да ещё и ХХХ секцию аккуратно положили. Ладно, чего это я придираюсь... Ах да, оно кеширует уже созданные директории, так что если создать папку и удалить её, второй раз её уже никак не создашь...

    frol, 23 Октября 2014

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

    +134

    1. 1
    2. 2
    3. 3
    4. 4
    //#if UNITY_IPHONE && !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9)
    if (Selection.activeGameObject != null)
    control = (IControl)Selection.activeGameObject.GetComponent("IControl");
    //#endif

    принял код от юнити юниора

    sladkijBubaleh, 23 Октября 2014

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

    +153

    1. 1
    document.body.innerHTML = document.body.innerHTML.replace(/guest/g, '');<

    DesmondHume, 23 Октября 2014

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

    +135

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    bool result = false;
    if (xmlString != null)
    {
       result = reportService.SaveQ360Report(questionnaireId, xmlString, publishReport);
       UpdateCurrentReportModel(questionnaireId, reportService);
    }
    // string errorMessage;
    if (result == false)
       result = true; //because model is not changed
    return Json(new { Success = result, ErrorMessage = DisplayLabels.InvalidModelError });

    sharpman, 23 Октября 2014

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

    +53

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    /* set _god=true temporarily, safely */
    class GodScope {
        bool _prev;
    public:
        GodScope();
        ~GodScope();
    };

    mongo/db/client.h
    Почувствуй простор божий

    roman-kashitsyn, 23 Октября 2014

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

    +121

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (Ints.contains(new int[] { 4, 5 }, statusCode / 100)) {
    	// error response
    } else {
    	// success response
    }

    Насколько я знаю, Apache HTTP Client не содержит "официального" метода для определения категории кода состояния. Приходится так.

    someone, 23 Октября 2014

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

    +156

    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
    if (varform)
        {
            switch (response.variants.length % 10)
            {
                case 1:
                    varform=1;
                    break;
                case 2:
                case 3:
                case 4:
                    varform=2;
                    break;
                case 0:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                    varform=3;
                    break;
            }
        }
        if (response.variants.length>=11 && response.variants.length<=14)
            varform=3;
        switch (varform)
        {
            case 0:
               caption.innerHTML="<b>Адрес распознан удачно</b>";
               break;
            case 1:
               caption.innerHTML="<b>Плохой адрес. Найден " + response.variants.length.toString()+" вариант</b>";
               break;
            case 2:
               caption.innerHTML="<b>Плохой адрес. Найдено " + response.variants.length.toString()+" варианта</b>";
               break;
            case 3:
               caption.innerHTML="<b>Плохой адрес. Найдено " + response.variants.length.toString()+" вариантов</b>";
               break;
        }

    Постыдство с сайта http://strela-ru.ucoz.ru/pa_query.html

    grobotron, 23 Октября 2014

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

    +117

    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
    @Override
    public void afterPersistenceInit() {
    	val conn = emProvider.get().unwrap(Connection.class);
    
    	try {
    		log.info("Transaction isolation level: {}", getLevelString(conn.getTransactionIsolation()));
    	} catch (final SQLException e) {
    		log.error("Error getting transaction isolation level", e);
    	}
    }
    
    private String getLevelString(final int isolationLevel) {
    	// Poor man's enums. Use reflection to find a constant with the given value
    	try {
    		for (val maybeLevelConstant: Connection.class.getDeclaredFields()) {
    			if (maybeLevelConstant.getType() == int.class && maybeLevelConstant.getName().startsWith("TRANSACTION_")
    					&& maybeLevelConstant.getInt(null) == isolationLevel) {
    				return maybeLevelConstant.getName();
    			}
    		}
    	} catch (final IllegalArgumentException | IllegalAccessException e) {
    		return "UNKNOWN";
    	}
    	
    	return "UNKNOWN";
    }

    Ищем рефлексией константу с нужным значением. И всё для того, чтобы напечатать её в логе. Вот что крест животворящий отсутствие энумов в legacy API делает.

    someone, 23 Октября 2014

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