1. Куча / Говнокод #17514

    +130

    1. 1
    2. 2
    Я не жду чтобы меня плюсовали, но давайте сделаем небольшую игру, ломающую стереотипы?
    Например рогалик в небольшое кол-во строк. В качестве главного героя можно взять крутого парня ломающего черепа.

    LispGovno, 25 Января 2015

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

    +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
    19. 19
    20. 20
    21. 21
    <?php
    /**
     * Округляет число до заданного количества знаков после запятой.
     * @param float $v	- округляемое число.
     * @param int $prec - количество знаков после запятой (по-умолчанию: 0).
     * @param str $mode - режим округления: ceil | floor | round (по-умолчанию: round).
     * @return float округлённое число.
     */
    function round2($v, $prec = 0, $mode = "round") {
    	for ($k = 1, $i = 0; $i < $prec; $i++, $k *= 10)
    		;
    	switch ($mode) {
    		case "ceil" : $v = ceil($k * $v) / $k;
    			break;
    		case "floor" : $v = floor($k * $v) / $k;
    			break;
    		default : $v = round($k * $v) / $k;
    	}
    
    	return $v;
    }

    kissarat, 24 Января 2015

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

    +141

    1. 1
    strcat(strcpy(malloc(strlen(argv[0]) + sizeof(".track")), argv[0]), ".track")

    LispGovno, 24 Января 2015

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

    +72

    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
    public class Командир {
        private String имя;
        private ПоходНаГерманию поход;
    
        public Командир(String имя) {
            this.имя = имя;
            поход = new ПоходНаГерманию();
         }
    
        public Богатство пойтиВпоход()
                             throws НеПолучилосьException {
            return поход.сходить();
        }
    }

    больше русской жабы тут http://www.spring-source.ru/docs_simple.php?type=manual&theme=docs_s imple&docs_simple=chap01_p03

    argamidon, 24 Января 2015

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

    +95

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    static void Main(string[] args)
            {
                Func<int, int> m = delegate(int a)
                {
                    Func<int, int> c = x => x / 2;
                    return a * c(a);
                };
                Console.WriteLine(m(10));
                Console.ReadKey();
            }

    Нестандартный подход

    SharK1870, 24 Января 2015

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

    +94

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    combinations.AddRange(combinations4);
                combinations.AddRange(from combination5 in combinations5
                                      where
                                          (from combination4 in combinations4
                                           where
                                               (from c4class in combination4.Classes
                                                where !combination5.Classes.Contains(c4class)
                                                select c4class).Count() == 0
                                           select combination4).Count() == 0
                                      select combination5);

    Теперь у меня есть ачивка "сделать через LINQ не смотря ни на что".
    Тому, кто поймёт, что же здесь происходит - достанется воображаемый пряник.

    krypt, 24 Января 2015

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function(dateToAdjust) {
        dateToAdjust = new Date(dateToAdjust);
        var offsetMs = dateToAdjust.getTimezoneOffset() * 60000;
        return new Date(dateToAdjust.getTime() - offsetMs);
    }

    даты в js, люблю их даже больше чем в php

    movaxbx, 24 Января 2015

    Комментарии (0)
  8. Си / Говнокод #17507

    +137

    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
    // For a portable version of timegm(), set the TZ environment variable  to
    // UTC, call mktime(3) and restore the value of TZ.  Something like
    
    #include <time.h>
    #include <stdlib.h>
    
    time_t
    my_timegm(struct tm *tm)
    {
        time_t ret;
        char *tz;
    
        tz = getenv("TZ");
        if (tz)
            tz = strdup(tz);
        setenv("TZ", "", 1);
        tzset();
        ret = mktime(tm);
        if (tz) {
            setenv("TZ", tz, 1);
            free(tz);
        } else
            unsetenv("TZ");
        tzset();
        return ret;
    }

    Цитата из man timegm. Сборка unix timestamp из компонент (год, месяц и т.п.).

    Удобно, наглядно, потокобезопасно.

    bormand, 23 Января 2015

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

    +50

    1. 1
    2. 2
    3. 3
    if ( !log.append(log_line) )
    
    log.append("Can't append to log");

    laMer007, 23 Января 2015

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

    +54

    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
    // We now have a locale string, but the global locale can be changed by
    // another thread. If we allow this thread's locale to be updated before we're done
    // with this string, it might be freed from under us.
    // Call versions of the wide-to-MB-char conversions that do not update the current thread's
    // locale.
    
    //...
    
    /*
                 * Note that we are using a risky trick here.  We are adding this
                 * locale to an existing threadlocinfo struct, and thus starting
                 * the locale's refcount with the same value as the whole struct.
                 * That means all code which modifies both threadlocinfo::refcount
                 * and threadlocinfo::lc_category[]::refcount in structs that are
                 * potentially shared across threads must make those modifications
                 * under _SETLOCALE_LOCK.  Otherwise, there's a race condition
                 * for some other thread modifying threadlocinfo::refcount after
                 * we load it but before we store it to refcount.
                 */

    MS VS 2013 CRT

    LispGovno, 23 Января 2015

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