1. C++ / Говнокод #23181

    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
    #include <type_traits>
    
    struct TPred1 {};
    struct TPred2 {};
    template<typename P1, typename P2> struct TAnd1: P1, P2 {TAnd1(P1, P2) {}};
    template<typename P1, typename P2> struct TAnd2: P1, P2 {TAnd2(P1, P2) {}};
    
    template<typename T, T v> struct my_integral_constant {enum {value=v};};
    template<class T, class From> struct my_is_base_of:
      my_integral_constant<bool, __is_base_of(T, From)> {};
    
    template<typename P1, typename P2> std::enable_if_t<
      my_is_base_of<TPred1, P1>::value &&
      my_is_base_of<TPred1, P2>::value,
    TAnd1<P1, P2>> operator&&(P1 p1, P2 p2)
    {return {p1, p2};}
    
    template<typename P1, typename P2> std::enable_if_t<
      my_is_base_of<TPred2, P1>::value &&
      my_is_base_of<TPred2, P2>::value,
    TAnd2<P1, P2>> operator&&(P1 p1, P2 p2)
    {return {(p1, p2};}
    
    
    template<typename T> struct is_callable
    {
      template<typename T1> struct dummy;
      template<typename CheckType> static short check(dummy<decltype(
        std::declval<std::remove_reference_t<CheckType>>()())>*);
      template<typename CheckType> static char check(...);
      enum: bool {value = sizeof(check<T>(nullptr)) == sizeof(short)};
    };
    
    struct IntellisenseKiller
    {
      template<typename T, typename = std::enable_if_t<
        std::is_function<T>::value &&
        is_callable<T>::value
      >> IntellisenseKiller(const T&) {}
      IntellisenseKiller(bool) {}
    };
    IntellisenseKiller eat4GbRam = true;

    Обнаружился ещё один способ превратить Visual Studio 2017 в тормозной, пожирающий 4 ГБ оперативы, блокнот с подсветкой синтаксиса.
    Это минимальный пример, который я выделил из своей библиотеки и порезал всё, что не вызывает баг. Вроде бы не связанные между собой куски кода, но глюки студии вызывают только вместе. Целый день потратил на поиск причины глюка.
    Случайно обнаружил, что длина получившегося фрагмента кода 42 строки. Я не подгонял, честно. Так что можно сказать, что ошибка в 42 строке. Без этой строки Intellisense заработает.

    gammaker, 12 Июля 2017

    Комментарии (45)
  2. Си / Говнокод #23180

    +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
    #include <stdint.h>
    #include <stdio.h>
    
    char a[] = {35,105,110,99,108,117,100,101,32,60,115,116,100,105,110,116,46,104,62,10,35,105,110,99,108,117,100,101,32,60,115,116,100,105,111,46,104,62,10,10,99,104,97,114,32,97,91,93,32,61,32,123,0,125,59,10,10,105,110,116,32,109,97,105,110,40,118,111,105,100,41,10,123,10,32,32,105,110,116,32,98,59,10,32,32,98,32,61,32,112,114,105,110,116,102,40,34,37,115,34,44,32,97,41,59,10,32,32,102,111,114,32,40,99,104,97,114,32,42,105,32,61,32,97,59,32,105,32,60,32,97,32,43,32,115,105,122,101,111,102,40,97,41,59,32,105,43,43,41,10,32,32,123,10,32,32,32,32,112,114,105,110,116,102,40,34,37,105,44,34,44,32,42,105,41,59,10,32,32,125,10,32,32,112,114,105,110,116,102,40,34,37,115,34,44,32,97,43,98,43,49,41,59,10,32,32,114,101,116,117,114,110,32,48,59,10,125,10,};
    
    int main(void)
    {
      int b;
      b = printf("%s", a);
      for (char *i = a; i < a + sizeof(a); i++)
      {
        printf("%i,", *i);
      }
      printf("%s", a+b+1);
      return 0;
    }

    куайн на сишечке

    j123123, 12 Июля 2017

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

    −3

    1. 1
    2. 2
    Камерунские нигеры ебут админа этого сайта в четыре ствола; но, что любопытно, нельзя сказать, чтобы это ему как-то прямо уж так-таки и не нравилось.
    Извиваться-то ужом он, положим, извивается; да только вопли из его глотки летят далеко не страдальческие...

    AnalPerOral, 12 Июля 2017

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

    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
    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
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    #include <algorithm>
    #include <exception>
    #include <iostream>
    #include <memory>
    #include <string>
    #include <vector>
    #include <random>
    #include <chrono>
    #define __CL_ENABLE_EXCEPTIONS
    #include "cl.hpp"
    
    using namespace std::string_literals;
    
    
    int main(int argc, char * argv[]) {
      
      
      size_t data_len = (1024 * 1024 * strtoul(argv[1], nullptr, 10)) / sizeof(uint32_t),
             out_len = strtoul(argv[2], nullptr, 10),
             iter = strtoul(argv[3], nullptr, 10),
             block_size = strtoul(argv[4], nullptr, 10);
      
      std::string src = R"(
        typedef unsigned int uint32_t;
    __kernel void bench(global const uint32_t * data, global uint32_t * out) {
        
        uint32_t res = 0, id = get_global_id(0), next = id;
        for(uint32_t i = 0; i < )"s + std::to_string(iter) + R"(; ++i) {
            for(uint32_t j = 0; j < )" + std::to_string(block_size / sizeof(uint32_t)) +  R"(; ++j)
                res ^= data[next + j];
            next = data[next];
        }
        out[id] = res;
        
    }
      
      )"s;
      
      cl::Program::Sources sources = {{src.data(), src.size()}};
    
    
      std::vector<cl::Platform> platforms;
      cl::Platform::get(&platforms);
      
      std::vector<uint32_t> data(data_len);
      std::vector<uint32_t> out(out_len);
      
      std::generate(std::begin(data), std::end(data), [=,gen = std::mt19937{}]() mutable {
        return gen() % (data_len - (block_size / sizeof(uint32_t)));
      });
      
      for(auto & platform : platforms) {
        std::cout << "Using platform: " << platform.getInfo<CL_PLATFORM_NAME>() << "\n";
        std::vector<cl::Device> devices;
        platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
        for(auto & device : devices) {
          try {
            std::cout << "Using device: " << device.getInfo<CL_DEVICE_NAME>() << "\n";
            cl::Context ctx({device});
            cl::Program program(ctx, sources);
            program.build({device});
            
            cl::Buffer data_buffer(ctx, CL_MEM_READ_WRITE, data.size() * sizeof(uint32_t));
            cl::Buffer out_buffer(ctx, CL_MEM_READ_WRITE, out.size() * sizeof(uint32_t));
            cl::CommandQueue queue(ctx, device);
            queue.enqueueWriteBuffer(data_buffer, CL_TRUE, 0, data.size() * sizeof(uint32_t), data.data());
            
            cl::make_kernel<cl::Buffer &, cl::Buffer &> bench(program, "bench");
            cl::EnqueueArgs eargs(queue,cl::NullRange,cl::NDRange(out.size()),cl::NullRange);
            
            auto start = std::chrono::high_resolution_clock::now();
            bench(eargs, data_buffer, out_buffer).wait();
            auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now() - start).count();
            
            size_t ops = out_len * iter;
            size_t total_tp = ops * block_size;
            double miops = (ops / time) / (1000 * 1000);
            double tpgbps = (total_tp / time) / (1024 * 1024 * 1024);
            fprintf(stderr, "Result: %.2fMIOPS, %.2fGB/s, %.2fsec\n", miops, tpgbps, time);
            
            
            queue.enqueueReadBuffer(out_buffer, CL_TRUE, 0, out.size() * sizeof(uint32_t), out.data());   
          
          } catch(cl::Error e) {
            std::cout << e.what() << " : " << e.err() << std::endl;
            std::terminate();
          }
        }
        
      }
    }

    Код Царя
    https://www.linux.org.ru/forum/development/13489159
    https://github.com/superhackkiller1997/gpu_mem_benchmark/blob/master/main.cpp

    j123123, 12 Июля 2017

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private bool CheckBool(string value)
           {
               if (value == "on")
                   return true;
               else
                   return false;
           }

    ////

    selicate, 12 Июля 2017

    Комментарии (2)
  6. Си / Говнокод #23176

    +5

    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
    inline int ms_001(int x){ return    x                                                ;}    //  x * 1
    inline int ms_002(int x){ return    x<<1                                             ;}    //  x * 2  
    inline int ms_003(int x){ return    x<<2 - x                                         ;}    //  x * 3  
    ...
    inline int ms_799(int x){ return    x<<10 - x<<8 + x<<5 - x                          ;}    //  x * 799
    inline int ms_800(int x){ return    x<<10 - x<<8 + x<<5                              ;}    //  x * 800
    
    // массив указателей 
      int ( *mult_shift[800] ) (int) = {
                                            ms_001,              
                                            ms_002,
    ...
                                            ms_799,
                                            ms_800  };

    Очень быстрое целочисленное умножение

    fse, 12 Июля 2017

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

    +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
    if (!empty($tickets)) {
        if (count($tickets)) {
    
            $c_start = strtotime($convetion_details['start']);
            $c_end   = strtotime($convetion_details['end']);
    
            $i = 0;
    
            while ($c_start <= $c_end) {
                if (is_int($i / 4) && $i > 0) $convetion_days_html .= '</tr><tr>';
                $convetion_days_html .= '<td>' . date('d.m', $c_start) . ' ' . __t($days_of_week[date('w', $c_start)]) . ' &nbsp;&nbsp;&nbsp;&nbsp;<img src="' . str_replace('https', 'http', TEMPLATE_WWWPATH) . '/images/checkbox.png"/></td>';
                $c_start             = strtotime('+1 day', $c_start);
                $i++;
            }
    //...

    код из легаси 2007 года от индусов

    seyfer, 11 Июля 2017

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

    +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
    /**
     * "Smart" Escape String
     *
     * Escapes data based on type
     * Sets boolean and null types
     */
    function escape($str)
    {
        if (is_string($str))
        {
            $str = "'".$this->escape_str($str)."'";
        }
        elseif (is_bool($str))
        {
            $str = ($str === FALSE) ? 0 : 1;
        }
        elseif (is_null($str))
        {
            $str = 'NULL';
        }
    
        return $str;
    }

    CodeIgniter 2, "Smart"

    Fike, 11 Июля 2017

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    defmodule Utils.String do
      @moduledoc false
      def comma_split(str), do: String.split(str, " ", trim: true)
    end

    AndrewDryga, 10 Июля 2017

    Комментарии (7)
  10. Python / Говнокод #23172

    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
    import csv
    import json
    
    import requests
    
    from io import StringIO
    
    from lxml import etree
    
    
    class DayPicParser(object):
        url = 'урл_до_сайта'
    
        def get_info(self):
            handler = open('daypic.csv', 'w+')
            page = 1
            rows = []
            tags = set()
            while page <= 1077:
                response = requests.get('{}/page/{}'.format(self.url, page))
                response.connection.close()
                parser = etree.HTMLParser()
                tree = etree.parse(StringIO(response.text), parser)
                posts = tree.xpath('//div[@class="posts"]/div[@class="post"]')
                for i, post in enumerate(posts):
                    title = post.find('./h2/a')
                    link_to_fulltext = title.attrib['href']
    
                    short_text = post.find('./div[@class="text"]//p[1]')
                    response = requests.get(link_to_fulltext)
                    full_parser = etree.HTMLParser()
                    full_tree = etree.parse(StringIO(response.text), full_parser)
                    full_post = full_tree.xpath('//div[@class="text"]//p')
    
                    main_image = None
                    full_text = []
                    for inner in full_post:
                        if inner.find('.//noindex') is not None:
                            continue
                        if inner.find('.//img') is not None:
                            src = inner.find('.//img').attrib['src']
                            if not main_image:
                                main_image = src
                            full_text.append({'image': src})
                        for paragraph in etree.tostring(inner, method="text", encoding='utf-8').decode('utf-8').strip().split("\n"):
                            if paragraph:
                                full_text.append({'text': paragraph})
                    rows.append({'title': title.text.strip(),
                                 'preview': main_image if main_image else '',
                                 'short_text': short_text.text.strip(),
                                 'full_text': full_text})
                    print('Post {} of {}'.format(i, len(posts)))
                page += 1
                print(page)
            handler.write(json.dumps(rows))
            handler.close()
            print(tags)
    
    
    DayPicParser().get_info()

    storvus, 10 Июля 2017

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