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

    −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
    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
    /* Q: Can someone recommend a more elegant way to achieve these compile-time constants? */
    template <int> struct Map;
    template <> struct Map<0> {static const int value = 4;};
    template <> struct Map<1> {static const int value = 8;};
    template <> struct Map<2> {static const int value = 15;};
    
    template <int> struct MapInverse;
    template <> struct MapInverse<4> {static const int value = 0;};
    template <> struct MapInverse<8> {static const int value = 1;};
    template <> struct MapInverse<15> {static const int value = 2;};
    
    
    /* A: Another TMP approach for a linear search using C++11: */
    #include <type_traits>
    
    // === Types:
    // Usage:
    //    Function<Map<x1,y1>,Map<x2,y2>,...>
    template<int D, int R> struct Map { enum { domain=D, range=R }; };
    template<typename ...A> struct Function {};
    
    // === Metafunctions:
    // Usage:
    //    ApplyFunction<x,F>::value
    template<int I, typename M> struct ApplyFunction;
    // Usage:
    //    ApplyFunctionInverse<x,F>::value
    template<int I, typename M> struct ApplyFunctionInverse;
    
    // ==== Example:
    // Define function M to the mapping in your original post.
    typedef Function<Map<0,4>,Map<1,8>,Map<2,15>> M;
    
    // ==== Implementation details
    template<typename T> struct Identity { typedef T type; };
    template<int I, typename A, typename ...B> struct ApplyFunction<I, Function<A,B...> > {
       typedef typename
          std::conditional <I==A::domain
                           , Identity<A>
                           , ApplyFunction<I,Function<B...>> >::type meta;
       typedef typename meta::type type;
       enum { value = type::range };
    };
    template<int I, typename A> struct ApplyFunction<I, Function<A>> {
       typedef typename
           std::conditional <I==A::domain
                            , Identity<A>
                            , void>::type meta;
       typedef typename meta::type type;
       enum { value = type::range };
    };
    // Linear search by range
    template<int I, typename A> struct ApplyFunctionInverse<I, Function<A>> {
       typedef typename
           std::conditional <I==A::range
                            , Identity<A>
                            , void>::type meta;
       typedef typename meta::type type;
       enum { value = type::domain };
    };
    template<int I, typename A, typename ...B> struct ApplyFunctionInverse<I, Function<A,B...> > {
       typedef typename
           std::conditional <I==A::range
                            , Identity<A>
                            , ApplyFunctionInverse<I,Function<B...>> >::type meta;
       typedef typename meta::type type;
       enum { value = type::domain };
    };
    
    // ==============================
    // Demonstration
    #include <iostream>
    int main()
    {
       // Applying function M
       std::cout << ApplyFunction<0,M>::value << std::endl;
       std::cout << ApplyFunction<1,M>::value << std::endl;
       std::cout << ApplyFunction<2,M>::value << std::endl;
    
       // Applying function inverse M
       std::cout << ApplyFunctionInverse<4,M>::value << std::endl;
       std::cout << ApplyFunctionInverse<8,M>::value << std::endl;
       std::cout << ApplyFunctionInverse<15,M>::value << std::endl;
    }

    Элегантненько.
    s: https://stackoverflow.com/questions/26075969/compile-time-map-and-inverse-map-values

    gost, 25 Апреля 2018

    Комментарии (10)
  2. Куча / Говнокод #24194

    −6

    1. 1
    https://github.com/syn2cat/pidor

    dm_fomenok, 24 Апреля 2018

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

    −10

    1. 1
    Вопрос

    Кто знает, как динамически выделить память, заполнить её нужными инструкциями, и исполнить этот код, не испытав при этом анальной боли и не получить Segmentation Fault ?

    yet_another_one_shit, 23 Апреля 2018

    Комментарии (19)
  4. Python / Говнокод #24190

    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
    class Task:
    
        def set_activity( activity_method ):
            # проанализировать исходный код activity_method 
            # разделить цепочку команд на N частей
            pass
    
        def _get_parts_number():
            return N
    
        def _run_part( part_num ):
            # выполнить часть part_num
            pass
    
    
    def run(tasks):
    
        execution = True
        part_num = 0
        while execution:
            execution = False
            for task in tasks:
                if part_num < task._get_parts_number():
                    task._run_part( part_num )
                    execution = True
            part_num += 1

    Попросил коллегу реализовать concurrency многозадачность, он на питоне нагавнякал такое.

    ded_mazay, 21 Апреля 2018

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

    +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
    public static class MyExtensions {
      private static Random _random = new Random(); 
      
      public static bool IsMnogo(this object value) {
        try {
          var n = double.Parse(value.ToString());
          return n > 9999999999;
        } catch {
          return true;
        }
      }
      
      public static bool IsDavno(this DateTime value) {
        return value < new DateTime(1900 + _random.Next(10, 90), 04, 17);
      }
    }

    mazhuravlev, 21 Апреля 2018

    Комментарии (4)
  6. bash / Говнокод #24183

    −2

    1. 1
    2. 2
    3. 3
    for word in {"Блять", "пишите", "красивые" ,"коды" ,"уёбки", ",", "ради", "энтузиазма", "и", "плодотворного", "труда", ",", "почитайте", "книжку", "сталина", "и", "поймёте", "как", "надо", "делать", "сруны", "говнокодерные!"}; do
        echo "$word"
    done

    хули?

    fuckercoder, 21 Апреля 2018

    Комментарии (8)
  7. Куча / Говнокод #24182

    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
    <!DOCTYPE html>
    <html>
     <head>
      <title></title>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <link rel="stylesheet" href="css/style.css">
      <!--[if IE]>
       <script src="https://raw.githubusercontent.com/aFarkas/html5shiv/master/dist/html5shiv.min.js"></script>
      <![endif]-->
      <style>
       article, aside, details, figcaption, figure, footer,header,
       hgroup, menu, nav, section { display: block; }
      </style>
     </head>
     <body>
      <form id="form">
        <input type="date">
        <input id="inp" type="email" required>
        <input type="submit">
      </form><br>
      <section itemtype="http://data-vocabulary.org/Person" itemscope>
        <h1 itemprop="name">Mark Pilgrim</h1>
        <p><img itemprop="photo" src="http://www.example.com/photo.jpg" alt="[me smiling]"></p>
        <p><a itemprop="url" href="http://diveintomark.org/">weblog</a></p>
      </section>
      <progress id="pg" value="50" max="100">
        <br>
    
      <script>
        let forward = true;
        function pgset() {
          if(forward) {
            pg.value = +pg.value + 1;
            if(+pg.value == 100)
              forward = false;
          }
          else {
            pg.value = +pg.value - 1;
            if(+pg.value == 0)
              forward = true;
          }
        }
        //setInterval(pgset, 100); //нахуй!
      </script>
     </body>
    </html>

    Куда мне ещё говно скидывать??

    fuckercoder, 21 Апреля 2018

    Комментарии (1)
  8. Куча / Говнокод #24181

    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
    <!DOCTYPE html>
    <html>
     <head>
      <title></title>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <link rel="stylesheet" href="css/style.css">
      <!--[if IE]>
       <script src="https://raw.githubusercontent.com/aFarkas/html5shiv/master/dist/html5shiv.min.js"></script>
      <![endif]-->
      <style>
       article, aside, details, figcaption, figure, footer,header,
       hgroup, menu, nav, section { display: block; }
      </style>
     </head>
     <body>
      <input id="inp" type="number" placeholder="num" min="-2" max="37" step="7" value="17">
      <br>
      <input type="button" value="+" onclick="plus()">
      <input type="button" value="-" onclick="minus()">
      <br>
      <div id="info"></div><br>
      <input id="rng" type="range" min="0" max="255" step="1" value="0" onchange="info2.innerHTML = rng.value; info2.style.color = 'rgb('+rng.value+','+0+','+rng.value+')'">
      <div id="info2"></div>
      <br>
      <input type="date">
      <input type="time">
      <br>
      <input type="search">
      <script>
        function plus() {
          inp.stepUp(3);
          Info();
        }
        function minus() {
          inp.stepDown(3);
          Info();
        }
        function Info() {
          info.innerHTML = inp.valueAsNumber;
        }
      </script>
     </body>
    </html>

    fuckercoder, 21 Апреля 2018

    Комментарии (0)
  9. Куча / Говнокод #24180

    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
    <!DOCTYPE html>
    <html>
     <head>
      <title></title>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <link rel="stylesheet" href="css/style.css">
      <!--[if IE]>
       <script src="https://raw.githubusercontent.com/aFarkas/html5shiv/master/dist/html5shiv.min.js"></script>
      <![endif]-->
      <style>
       article, aside, details, figcaption, figure, footer,header,
       hgroup, menu, nav, section { display: block; }
      </style>
     </head>
     <body>
      <div id="example">
      Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. Test test test test test. 
    </div>
    <style>
      #example {
        width: 300px;
    
        height: 200px;
    
        border: 25px solid #E8C48F; /* рамка 25px */
    
        padding: 20px;              /* поля 20px */
    
        overflow: auto;             /* прокрутка */
      }
    </style>
      <input type="button" value="Размер снизу" onclick="below()">
      <input type="button" value="Ширина полосы прокрутки" onclick="widthScroll(example)">
      <script>
        function below() {
          alert(example.scrollHeight-example.scrollTop-example.clientHeight);
        }
        function widthScroll(elem) {
          alert((elem.offsetWidth-(elem.clientLeft*2))-elem.clientWidth+'px');
        }
      </script>
     </body>
    </html>

    1488 плохое число

    fuckercoder, 21 Апреля 2018

    Комментарии (0)
  10. Куча / Говнокод #24179

    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
    <!DOCTYPE html>
    <html>
     <head>
      <title></title>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <link rel="stylesheet" href="css/style.css">
      <!--[if IE]>
       <script src="https://raw.githubusercontent.com/aFarkas/html5shiv/master/dist/html5shiv.min.js"></script>
      <![endif]-->
      <style>
       article, aside, details, figcaption, figure, footer,header,
       hgroup, menu, nav, section { display: block; }
    
       #moving-div {
        border: 5px groove green;
        padding: 5px;
        margin: 10px;
        background-color: yellow;
      }
      </style>
     </head>
     <body>
    
    Before Before Before
    
    <div id="moving-div">
    Text Text Text<br>
    Text Text Text<br>
    </div>
    
    After After After
    
    <script type="text/javascript">
      'use strict';
      let empty = document.createElement('div');
      let mdiv = document.getElementById('moving-div');
      let cs = getComputedStyle(mdiv);
    
      function clone_Node(elem) { //плохая релизация глючит:(((
        let r = document.createElement(elem.tagName);
        for(let k of getComputedStyle(elem)) {
          try {
            r.style[k] = getComputedStyle(elem)[k];
          }
          catch(e) { /*пофиг!*/ }
        }
        r.innerHTML = elem.innerHTML;
        return r;
      }
      let copy = mdiv.cloneNode(true);
    
      mdiv.style.opacity = '0';
    
      copy.style.position = 'absolute';
      copy.style.right = copy.style.top = 0;
      mdiv.after(copy);
    </script>
     </body>
    </html>

    хуй!

    fuckercoder, 21 Апреля 2018

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