1. JavaScript / Говнокод #27928

    −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
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    const files = {
      "main.pcg": "funcTion text print hello;startFunction text;"
    };
    const functions = {};
    const values = {};
    function startc(text) {
      var code = text.trim();
      let strings = code.split(";");
      for(var i = 0; i < strings.length; i++) {
        let currentString = strings[i];
        let words = currentString.split(" ");
        if(words[0].toLowerCase() == "print") {
          console.log(words[1]);
        };
        if(words[0].toLowerCase() == "printValue") {
          console.log(values[words[1]]);
        };
        if(words[0].toLowerCase() == "value") {
          values[words[1]] = words[2];
        };
        if(words[0].toLowerCase() == "ws") {
          values[words[1]] = new WebSocket(words[2]);
        };
        if(words[0].toLowerCase() == "printcycle") {
          for(var i = 0; i < words[1]; i++) {
            console.log(words[2]);
          };
        };
        if(words[0].toLowerCase() == "function") {
          functions[words[1]] = words[2] + " " + words[3];
        };
        if(words[0].toLowerCase() == "startfunction") {
          startc(functions[words[1]]);
        };
      };
    };
    function start(file) {
      startc(files[file]);
    };

    govnokoder666, 06 Января 2022

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

    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
    interface I<T> {
        foo(x: number): T;
    }
    
    interface A extends I<number>/*, I<string>*/ { }
    
    class AI
    {
    	foo(x: number) { return x; }
    }
    
    function main()
    {
    	let x: A = new AI();
    	const r = x.foo(1); // no error
    	//const r2 = x.foo(''); // error
    
    	print("done.");
    }

    ура... первая имплементация generic интерфейса... ну с почином на генериках

    ASD_77, 04 Января 2022

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

    −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
    window.spam = (function () {
      function spam (els) {
             
        }
         
        var spam = {
            get: function (selector) {
             
            }   
        };
         
        return spam;
    }());

    govnokodishe!

    govnokoder666, 03 Января 2022

    Комментарии (0)
  4. JavaScript / Говнокод #27915

    −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
    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
    let SPAM = {
      "lastWsMessage": null,
      "lastWsLink": null,
      "specialFunctionWS": (urlws) => {
        SPAM.lastWsLink = urlws;
        let ws = new WebSocket(urlws);
        ws.onopen = () => {
          console.log("connected");
          return "connected";
        };
        ws.onclose = () => {
          console.log("disconnected");
          return "disconnected";
        };
        ws.onerror = () => {
          console.log("error");
          return "error";
        };
        ws.onmessage = (event) => {
          console.log("message ${event.data}");
          SPAM.lastWsMessage = event.data;
        };
      },
      "spammer": (text, amount) => {
        for(let a = 0; a < amount; a++) {
          console.log(text);
        };
        return amount;
      },
      "wsConnecting": (url) => {
        let splitter = url.split(":");
        if(splitter[0] == "ws") {
          console.log("WARNING: it is not advised to use the value \"ws\"!");
          SPAM.specialFunctionWS(url);
        };
        if(splitter[0] == "wss") {
          SPAM.specialFunctionWS(url);
        };
        if(splitter[0] == "http" || splitter[0] == "https") {
          console.log("WARNING: don't use the values http/https for socket connecting!\nLink changed: wss://" + url);
          SPAM.specialFunctionWS("wss://" + url);
        };
        if(splitter.length == 1) {
          console.log("WARNING: script is using the value \"wss\"!");
          SPAM.specialFunctionWS("wss://" + url);
        };
      },
      "SendWs": (message) => {
        if(SPAM.lastWsLink != null) {
          let ws = new WebSocket(SPAM.lastWsLink);
        ws.onopen = () => {
          console.log("connected");
          return "connected";
        };
        ws.onclose = () => {
          console.log("disconnected");
          return "disconnected";
        };
        ws.onerror = () => {
          console.log("error");
          return "error";
        };
        ws.onmessage = (event) => {
          console.log("message ${event.data}");
          SPAM.lastWsMessage = event.data;
        };
        } else {
          console.log("ERROR: last connection not found!");
        };
      }
    };

    govnokod!

    govnokoder666, 03 Января 2022

    Комментарии (0)
  5. JavaScript / Говнокод #27913

    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
    function move1(direction: "up" | "down") {
        switch (direction) {
            case "up":
                return 1;
            case "down":
                return -1; 
        }
    
        return 0;
    }
    
    function main() {
    
        print(move1("up"));
        print(move1("down"));
    
        print("done.");
    }

    а ты умеешь так говнокодить на C/C++?

    ASD_77, 02 Января 2022

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

    +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
    type CreateMutable<Type> = {
      -readonly [Property in keyof Type]: Type[Property];
    };
     
    type LockedAccount = {
      readonly id: string;
      readonly name: string;
    };
    
    type UnlockedAccount = CreateMutable<LockedAccount>;
    
    function main() {
        let a: LockedAccount;
        let b: UnlockedAccount;
    
        print("done.");
    }

    Я вам наговнокодил новую фичу.. называется "mapped type"

    ASD_77, 01 Января 2022

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

    0

    1. 1
    2. 2
    3. 3
    var x1: number;
    x1 = value;
    (x1) = value;

    чем одна строка отличается от другой?

    ASD_77, 01 Января 2022

    Комментарии (58)
  8. JavaScript / Говнокод #27906

    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
    'use strict'
     
    const {TheCtrl} = require('the-controller-base')
    const {withAuthorized} = require('the-controller-mixins')
     
    async function tryExample () {
      class MyCtrl extends withAuthorized(TheCtrl) {
        /* ... */
      }
    }
     
    tryExample().catch((err) => console.error(err))

    Mixins for the-controller

    Installation
    $ npm install the-controller-mixins --save

    Очень полезный и нужный пакет. Пользуйтесь.
    https://www.npmjs.com/package/the-controller-mixins/v/2.1.0

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

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

    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
    export type Maybe<T> = null | undefined | T;
    
    export interface Path {
        readonly prev: Path | undefined;
        readonly key: string | number;
        readonly typename: string | undefined;
    }
    
    /**
     * Given a Path and a key, return a new Path containing the new key.
     */
    export function addPath(
        prev: Readonly<Path> | undefined,
        key: string | number,
        typename: string | undefined,
    ): Path {
        return { prev, key, typename };
    }
    
    /**
     * Given a Path, return an Array of the path keys.
     */
    export function pathToArray(
        path: Maybe<Readonly<Path>>,
    ): Array<string | number> {
        let curr = path;
        let flattened = [];
        while (curr) {
            flattened.push(curr.key);
            curr = curr.prev;
        }
        //flattened.reverse();
        return flattened;
    }
    
    function main() {
        let pathArray = pathToArray({
            key: "path",
            prev: undefined,
            typename: undefined,
        });
        for (let x of pathArray) {
            print(x);
        }
    }

    последний коммит позволяет скомпилить и выполнить данный код. это невиданный прогресс в компиляторе :)

    и уже традиционный вопрос ... а ты там можешь наговнокодить на С/C++?

    ASD_77, 31 Декабря 2021

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

    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
    interface Animal {
      live(): void;
    }
    interface Dog extends Animal {
      woof(): void;
    }
     
    type Example1 = Dog extends Animal ? number : string;
     
    type Example2 = RegExp extends Animal ? number : string;
    
    function main() {
    
        let a: Example1;
        a = 10.0;
    
        print(a);
      
        let b: Example2;
        b = "asd";
    
        print(b);
    
        print("done.");
    }

    "Условные типа" подвезли.... ура ... теперь можно всякую х. наговнокодить..

    ASD_77, 28 Декабря 2021

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