1. Go / Говнокод #27883

    −7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    keys := make([]keyType, 0, len(myMap))
    values := make([]valueType, 0, len(myMap))
    
    for k, v := range myMap {
    	keys = append(keys, k)
    	values = append(values, v)
    }

    Как в "Go" у карты взять keys(), и values()?
    Нужно написать цикл.

    3_dar, 20 Декабря 2021

    Комментарии (40)
  2. JavaScript / Говнокод #27882

    −7

    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
    // @strict: true
    interface IFace {
        cond0: boolean;
        cond1?: boolean;
    }
    
    function main() {
    
        const a : IFace = { cond0: true };
    
        print (a.cond0);
        print (a.cond1 == undefined);
        print (a.cond1);
    
    	// a.cond1?.value
    
        print("done.");
    }

    я вам принес новую фичу. называется опциональные поля в interface-ах. а твой с++ умеет так?

    ASD_77, 19 Декабря 2021

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

    −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
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    template distance(b1, b2: AstronomicalBody): float64 = dist(b1.pos, b2.pos)
    
    proc attractionForce(body_1, body_2: AstronomicalBody): DVec3 =
      let r = distance(body_1, body_2)
      let module = (body_1.m * body_2.m) / (r.pow(2))
      return normalize(body_2.pos - body_1.pos) * module
    
    proc updateForce(body: var AstronomicalBody, bodies: seq[AstronomicalBody]) =
      body.F = dvec3(0, 0, 0)
      for other_body in bodies:
        if other_body != body:
          body.F += attractionForce(body, other_body)
    
    template acceleration(body: AstronomicalBody): float64 = body.F / body.m
    
    template updateAcceleration(body: var AstronomicalBody) = body.a = acceleration(body)
    
    template velocity(body: AstronomicalBody, dt: float64) = body.V + body.F.normalize * body.a * dt
    
    template updateVelocity(body: var AstronomicalBody, dt: float64) = body.V = velocity(body, dt)
    
    template updatePosition(body: var AstronomicalBody, dt: float64) = body.pos += (body.V * dt)
    
    proc updateProperties(body: var AstronomicalBody, bodies: seq[AstronomicalBody], dt: float64) =
      body.updateForce(bodies)
      body.updateAcceleration()
      body.updateVelocity(dt)
      body.updatePosition(dt)

    Как же "Nim" хорош, как же "Nim" красив, изящен и элегантен!

    JloJle4Ka, 19 Декабря 2021

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

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    #include <stdbool.h>
    
    struct two_val
    {
      const int32_t a[2];
    };
    
    struct two_val_and_status
    {
      const bool is_swap;
      const struct two_val t_v;
    };
    
    struct array
    {
      const int32_t a[10];
    };
    
    struct array_and_status
    {
      const bool is_swap;
      const size_t pos;
      const struct array arr;
    };
    
    // Эта суперфункцональная функция сортировки двух элементов не просто сортирует два элемента
    // но и еще сообщает о том, нужно ли было для этого обменивать два значения
    struct two_val_and_status sort2(const struct two_val a)
    {
      return (a.a[0] > a.a[1]) ? (struct two_val_and_status){true, {{a.a[1], a.a[0]}}} : (struct two_val_and_status){false, a};
    }
    
    struct two_val read_two_val(const struct array arr, const size_t pos)
    {
      return (struct two_val){{arr.a[pos], arr.a[pos+1]}};
    }
    
    struct array store_val(const struct array arr, const int32_t val, size_t pos)
    {
      return (struct array) // Царский анролл
      {{
        pos != 0 ? arr.a[0] : val,
        pos != 1 ? arr.a[1] : val,
        pos != 2 ? arr.a[2] : val,
        pos != 3 ? arr.a[3] : val,
        pos != 4 ? arr.a[4] : val,
        pos != 5 ? arr.a[5] : val,
        pos != 6 ? arr.a[6] : val,
        pos != 7 ? arr.a[7] : val,
        pos != 8 ? arr.a[8] : val,
        pos != 9 ? arr.a[9] : val
      }};
    }
    
    struct array store_two_val(const struct array arr, const struct two_val val, const size_t pos)
    {
      return store_val(store_val(arr,val.a[0],pos),val.a[1],pos+1);
    }
    
    // суперохуительная рекурсивная функция сортировки пузырьком
    struct array_and_status bubble_sort_rec(struct array_and_status state) 
    {
      if (state.pos == 9)
      {
        if (state.is_swap == false) // Ура! Сортировка пузырьком завершена!
        {
          return state;
        }
        else
        { // а иначе нам надо по-новой сортировать!
          return bubble_sort_rec((struct array_and_status){.is_swap = false, .pos=0, .arr = state.arr});
        }
      }
      else
      {
        const struct two_val_and_status tmp = sort2(read_two_val(state.arr, state.pos));
        return bubble_sort_rec(
          (struct array_and_status)
          {
            .is_swap = tmp.is_swap || state.is_swap,
            .pos=state.pos+1,
            .arr = store_two_val(state.arr, tmp.t_v, state.pos)
          }
        );
      }
    }
    
    int main(void)
    {
      const struct array_and_status a = {.is_swap = false, .pos = 0, .arr = {{8,2,4,1,3,5,7,0,6,9}} };
      const struct array_and_status a_sort = bubble_sort_rec(a);
      for(size_t i = 0; i < 10; i++) // ох уж это убогое императивное программирование!!!
      {
        printf("%" PRIu32 ", ", a_sort.arr.a[i]);
      }
      return EXIT_SUCCESS;
    }

    Функциональная сортировка пузырьком
    https://wandbox.org/permlink/dGyvo82lgQGInD0Y

    j123123, 19 Декабря 2021

    Комментарии (107)
  5. Куча / Говнокод #27879

    −1

    1. 1
    Я скажу вам по секрету: плохо быть гомосексуалистом.

    Попахивает ли твой хуй говном, bormand?

    MaaKut, 18 Декабря 2021

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

    +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
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    EXAMPLE
    
    To specify what kind of authorization is needed to execute the program /usr/bin/pk-example-frobnicate as another user, simply write an action definition file like this
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE policyconfig PUBLIC
      "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
      "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
    <policyconfig>
    
      <vendor>Examples for the PolicyKit Project</vendor>
      <vendor_url>http://hal.freedesktop.org/docs/PolicyKit/</vendor_url>
    
      <action id="org.freedesktop.policykit.example.pkexec.run-frobnicate">
        <description>Run the PolicyKit example program Frobnicate</description>
        <description xml:lang="da">Kør PolicyKit eksemplet Frobnicate</description>
        <message>Authentication is required to run the PolicyKit example program Frobnicate (user=$(user), program=$(program), command_line=$(command_line))</message>
        <message xml:lang="da">Autorisering er påkrævet for at afvikle PolicyKit eksemplet Frobnicate (user=$(user), program=$(program), command_line=$(command_line))</message>
        <icon_name>audio-x-generic</icon_name>
        <defaults>
          <allow_any>no</allow_any>
          <allow_inactive>no</allow_inactive>
          <allow_active>auth_self_keep</allow_active>
        </defaults>
        <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/pk-example-frobnicate</annotate>
      </action>
    
    </policyconfig>

    Simply write an action definition file like this, they said...

    bormand, 17 Декабря 2021

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // Интерполяция строк в "Go"
    
    koko := "pituh"
    text = `
    ehal ` + koko + `
    cherez ` + koko + `
    vidit ` + koko + ` v reke ` + koko + `
    sunul
    `

    P.S. Её нет

    3_dar, 16 Декабря 2021

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

    +2

    1. 1
    2. 2
    3. 3
    export $(grep PROJECT_NAME .env | xargs)
    export $(grep USERID .env | xargs)
    docker exec -it -u ${USERID} ${PROJECT_NAME}_application bash -l

    На минуточку в проекте написанный лично разрабом до меня docker-compose.

    TrueGameover, 15 Декабря 2021

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

    +3

    1. 1
    2. 2
    3. 3
    if err != nil {
        return nil, err
    }

    Как же заебало

    3_dar, 15 Декабря 2021

    Комментарии (104)
  10. JavaScript / Говнокод #27874

    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
    interface F1 {
        a: number;
        a2: boolean;
    }
    
    interface F2 {
        b: string;
        b2: number;
    }
    
    type t = F1 & F2 & { c: number };
    
    interface t2 extends F1, F2 {
        c: number;
    }
    
    type tt = { a: boolean };
    type tt2 = { b: number };
    type tt3 = { c: string };
    
    type r = tt & tt2 & tt3;
    
    function main() {
    
        const f1: F1 = { a: 10.0, a2: true };
        print(f1.a, f1.a2);
    
        const f2: F2 = { b: "Hello1", b2: 20.0 };
        print(f2.b, f2.b2);
    
        const a: t = { a: 10.0, a2: true, b: "Hello", b2: 20.0, c: 30.0 };
        print(a.a, a.a2, a.b, a.b2);
    
        const b: t2 = { a: 10.0, a2: true, b: "Hello", b2: 20.0, c: 30.0 };
        print(b.a, b.a2, b.b, b.b2, b.c);
    
        const c: r = { a: true, b: 10.0, c: "Hello" };
        print(c.a, c.b, c.c);
    
        print("done.");
    }

    я вам тут conjunctions наговнокодил.... а нужен дампик?

    ASD_77, 15 Декабря 2021

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