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

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

    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
    class Animal {
        move(distanceInMeters = 0) {
            print(`Animal moved ${distanceInMeters}m.`);
        }
    }
    
    function main() {
        const dog = new Animal();
        dog.move(10);
    
        const dog2 = Animal();
        dog2.move(11);
    }

    Загадка дня... кто знает что первый вызов конструктора отличается от второго?

    ASD_77, 07 Июля 2021

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

    +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
    template<typename F, typename... CurryArgs>
    struct curry {
        F func;
        std::tuple<CurryArgs...> tup{};
    
        curry(F f) : func(std::move(f)) {}
    
        template<typename... CtorArgs>
        curry(F f, CtorArgs &&... args) : func(std::move(f)), tup(std::forward<CtorArgs>(args)...) {}
    
        template<typename Tup1, typename Tup2>
        curry(F f, Tup1 && tup1, Tup2 && tup2) : func(std::move(f)), tup(std::tuple_cat(tup1, tup2)) {}
    
        template<typename... Args>
        auto operator()(Args &&... args)
        {
            constexpr size_t have_args = sizeof...(Args) + sizeof...(CurryArgs);
            constexpr size_t need_args = detail::functor_traits<F>::args_count;
            if constexpr (have_args > need_args) {
                static_assert(!sizeof(std::tuple_element_t<0, std::tuple<Args...>>*),
                              "Too many arguments.");
            } else if constexpr (have_args == need_args) {
                return std::apply(func, std::tuple_cat(tup, std::tuple(std::forward<Args>(args)...)));
            } else {
                return curry<decltype(func), CurryArgs..., Args...>(func, tup, std::tuple(std::forward<Args>(args)...));
            }
        }
    };
    
    int main()
    {
        auto f = [](int a, float b, const std::string & c) -> int {
            std::cout << "Functor! a = " << a << ", b = " << b << ", c = " << c << std::endl;
            return a + static_cast<int>(b);
        };
    
        std::cout << f(16, 42.1f, "Hello") << std::endl;
    
        auto c0 = curry(f);
        auto c1 = c0(16);
        auto c2 = c1(42.1f);
    
        c0(16)(42.1f)("Hello");
        c1(42.1f)("Hello");
        c2("Hello");
    
        c0(16, 42.1f)("Hello");
        c0(16, 42.1f, "Hello");
    
        c1(42.1f, "Hello");
    }

    Каррировали-каррировали, да выкаррировали.
    https://wandbox.org/permlink/LPXFUNpWOREcB3wH

    PolinaAksenova, 10 Мая 2021

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

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    std::cout << "Creating ptr1!" << std::endl;
    auto ptr1 = make_nft<Cow>();
    std::cout << "ptr1(" << &ptr1 << "): " << ptr1.get() << std::endl;
    ptr1->MakeSound();
    
    std::cout << "Creating ptr2!" << std::endl;
    nft_ptr<Animal> ptr2;
    std::cout << "ptr2(" << &ptr2 << "): " << ptr2.get() << std::endl;
    std::cout << "Moving: ptr2 = std::move(ptr1)" << std::endl;
    ptr2 = std::move(ptr1);
    std::cout << "Moved: ptr1 = " << ptr1.get() << " ptr2 = " << ptr2.get()
              << std::endl;

    https://github.com/zhuowei/nft_ptr

    "C++ std::unique_ptr that represents each object as an NFT on the Ethereum blockchain."

    PolinaAksenova, 13 Апреля 2021

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

    +1

    1. 1
    Class HasThisTypePatternTriedToSneakInSomeGenericOrParameterizedTypePatternMatchingStuffAnywhereVisitor

    https://javadoc.io/doc/org.aspectj/aspectjweaver/1.8.10/org/aspectj/weaver/patterns/HasThisTypePatternTriedToSneakInSomeGene ricOrParameterizedTypePatternMatchingStu ffAnywhereVisitor.html

    6oHo6o, 21 Марта 2021

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    /**
         * Change the zoom level to the specified value. Specify 0.0 to reset the
         * zoom level.
         *
         * @param zoomLevel The zoom level to be set.
         */
        public void setZoomLevel(double zoomLevel);

    Когда-то я думал, что zoom 100% это 1.0. И что на zoom нужно умножать. Но оказалось, что я анскильный.

    DypHuu_niBEHb, 24 Сентября 2020

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

    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
    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
    <?php
    
    function get_post_id($comment_list_id) {
        $rawdata = file_get_contents("https://govnokod.ru/comments/$comment_list_id/post");
        $rawdata='<?xml encoding="UTF-8">'.$rawdata;
    
        $old_libxml_error = libxml_use_internal_errors(true);
        $dom = new DOMDocument;
        $dom->loadHTML($rawdata);
        libxml_use_internal_errors($old_libxml_error);
    
        $xpath = new DOMXPath($dom);
        $entries = $xpath->query('//*[@id="content"]/ol[@class="posts hatom"]/li[@class="hentry"]/h2/a');
    
        foreach($entries as $entry) {
            $href = $entry->getAttribute('href');
            if(preg_match('#https://govnokod.ru/(\d+)#', $href, $matches)) {
                $post_id = $matches[1];
                break;
            }
        }
        return $post_id;
    }
    
    $outf = fopen('postids.csv', 'w');
    fputcsv($outf, array('post_id','comment_list_id'));
    for($i = 1; $i <= 26663; $i++) {
        fputcsv($outf, array(get_post_id($i), $i));
    }
    fclose($outf);

    Получение списка всех говнокодов, комментарии к которым можно восстановить.

    ropuJIJIa, 19 Мая 2020

    Комментарии (23)
  8. PHP / Говнокод #26514

    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
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    <div class="choose_payment">
                    	<div class="title"><span>2</span>Выберите способы оплаты (все без комиссии)</div>
                        <!-- all terminals -->
                        <div class="all_terminals">
                              <!-- fike: конечно же тут были все терминалы, а вы как думали? -->
                        </div>        
    					<!-- payments. no commisson -->
                       <div class="no_commission"><label>
                        	<div class="title_no_commission"><i>Подсказка:</i></div>
                            
                            <div class="we_recommend_2">
                            	<div class="title_we_recommend_2">
    					Оплачиваете первый раз?<br>
    					наши специалисты ответят на все вопросы <br>
    					<!--?phpphp echo preg_replace("/([0-9]{1})([0-9]{3})([0-9]{3})([0-9]{2})([0-9]{2})/", "+$1 ($2) $3-$4-$5", SUPPORT_PHONE); ?--> ежедневно с 10:00 до 19:00
    				</div>
                            </div>
    						</label>
                        </div>
                    </div>

    А впрочем нет, не ответят

    Fike, 20 Марта 2020

    Комментарии (23)
  9. Go / Говнокод #26349

    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
    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
    // GostServer is the type that contains all of the relevant information to set
    // up the GOST HTTP Server
    type GostServer struct {
    	host       string      // Hostname for example "localhost" or "192.168.1.14"
    	port       int         // Port number where you want to run your http server on
    	api        *models.API // SensorThings api to interact with from the HttpServer
    	https      bool
    	httpsCert  string
    	httpsKey   string
    	httpServer *http.Server
    }
    
    // CreateServer initialises a new GOST HTTPServer based on the given parameters
    func CreateServer(host string, port int, api *models.API, https bool, httpsCert, httpsKey string) Server {
    	setupLogger()
    	a := *api
    	router := CreateRouter(api)
    	return &GostServer{
    		host:      host,
    		port:      port,
    		api:       api,
    		https:     https,
    		httpsCert: httpsCert,
    		httpsKey:  httpsKey,
    		httpServer: &http.Server{
    			Addr:         fmt.Sprintf("%s:%s", host, strconv.Itoa(port)),
    			Handler:      PostProcessHandler(RequestErrorHandler(LowerCaseURI(router)), a.GetConfig().Server.ExternalURI),
    			ReadTimeout:  30 * time.Second,
    			WriteTimeout: 30 * time.Second,
    		},
    	}
    }
    
    // Start command to start the GOST HTTPServer
    func (s *GostServer) Start() {
    	t := "HTTP"
    	if s.https {
    		t = "HTTPS"
    	}
    
    	logger.Infof("Started GOST %v Server on %v:%v", t, s.host, s.port)
    
    	var err error
    	if s.https {
    		err = s.httpServer.ListenAndServeTLS(s.httpsCert, s.httpsKey)
    	} else {
    		err = s.httpServer.ListenAndServe()
    	}
    
    	if err != nil {
    		logger.Panicf("GOST server not properly stopped: %v", err)
    	}
    }
    
    // Stop command to stop the GOST HTTP server
    func (s *GostServer) Stop() {
    	if s.httpServer != nil {
    		logger.Info("Stopping HTTP(S) Server")
    		s.httpServer.Shutdown(context.Background())
    	}
    }

    Нашёл ГостСервер го

    https://github.com/gost/server/blob/master/http/gostserver.go

    gostinho, 13 Января 2020

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

    +3

    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
    /**
         * Four state boolean.
         */
        enum Bool {
            /** */
            FALSE,
    
            /** */
            TRUE,
    
            /** */
            READY,
    
            /** */
            DONE
        }

    MAKAKA, 27 Ноября 2019

    Комментарии (23)
  11. bash / Говнокод #25985

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    set -e
    
    myfunc() {
      echo "START"
      v=$(asdasdsd 1 2 3)
      echo "FINISH"
    }
    
    myfunc && echo "OK"

    Выводит:

    START
    ./b.sh: line 5: asdasdsd: command not found
    FINISH
    OK

    asdasdsd - несуществующая команда, вызывающая падение скрипта

    Помогите сделать так, чтобы ошибку можно было поймать, и чтобы до echo "FINISH" не доходило.
    Уже всё перепробовал. Нерабочие вореанты просьба не предлагать.



    Вот так работает правильно
    set -e

    myfunc() {
    echo "START"
    v=$(asdasdsd 1 2 3)
    echo "FINISH"
    }

    myfunc


    Выводит:
    START
    ./a.sh: line 5: asdasdsd: command not found

    Но мне нужно ошибку перехватить.

    guestinxo, 22 Октября 2019

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