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

    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
    function main()
    {
      let a: [string, number] = ["asd", 1.0];
      print(a[0], a[1]);  
    
    
      const b: [string, number] = ["asd", 1.0];
      print(b[0], b[1]);  
    
      const c = ["asd", 1.0];
      print(c[0], c[1]);  
    }

    Продолжаем будни говнописания говнокомпилятора. Хотел спросить а ваш компилятор может так, но думаю может. В кратце - это работа с таплами(tuples) а не с масивами :)

    ASD_77, 13 Мая 2021

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function main() {    
        const x = 21;
        let s = "foo";
        const r = `a${x * 2}X${s}X${s}Z`;
        print(r);
    }

    Продолжаем будни говно-писания говно-компилятора на LLVM. серия - а ваш говно-компилятор может так...

    и результат работы
    >>
    C:\temp\MLIR_to_exe>out.exe
    a42XfooXfooZ

    ASD_77, 10 Мая 2021

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

    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
    // Define the man site module
    define(function(require) {
        // Require function that runs when button is clicked
        var run = require('./run').run;
    
        // Where the application starts its work
        var genTextButton = document.getElementById("button-gen-text");
        genTextButton.onclick = run;
    });
    
    define(function(require) {
      // Require value error
      var ValueError = require('./errors/value_errors').ValueError;
    
      // Require EmptyListError
      var EmptyListError = require('./errors/property_errors').EmptyListError;
    
      // Require functions that returns data for text generation
      var getData = require('./utils/get_data');
      var getTextLength = getData.getTextLength;
      var getTemplateList = getData.getTemplateList;
      var getWordList = getData.getWordList;
      var getStyleOption = getData.getStyleOption;
    
      // Require function for setting output text
      var makeText = require('./utils/set_text');
    
      // Require function for validating form and validate form
      var validateForm = require('./utils/validateForm');
      validateForm({
        formId : 'form-text-gen',
        inputErrorClass : 'input-error',
        formInvalidClass : 'form-invalid'
      });
    
      // Runs tasks for text generation
      var run = function() {
        try {
          var textLength = getTextLength();
          var templateList = getTemplateList();
          var wordList = getWordList();
          var styleOption = getStyleOption();
    
          makeText({
            styleOption : styleOption,
            textLength : textLength,
            templateList : templateList,
            wordList : wordList
          });
        } catch (error) {
           if (error instanceof ValueError) {
             console.log(error.stack);
           } else if (error instanceof EmptyListError)  {
              console.log(error.stack);
           } else {
             throw error;
           }
        }
      }
    
      return {
        run : run
      }
    });

    Божественная кнопка

    JaneBurt, 08 Мая 2021

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    function display(id:number, name:string)
    {
        print("Id = " + id + ", Name = " + name);
    }
    
    function main() {                                                 
    	display(1, "asd");
    }

    А ваш говно компайлер умеет так делать?

    >> Output:
    Id = 1., Name = asd

    ASD_77, 07 Мая 2021

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

    +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
    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
    // Define the module
    define(function(require) {
      // Require empty list error
      var EmptyListError = require('../errors/property_errors').EmptyListError;
    
      // Character-rank list class
      function WeightedList(/* ...keys */) {
        this._total = 0;
        this._generateList.apply(this, arguments);
      }
    
      WeightedList.prototype._generateList = function() {
        var collection;
        if (typeof arguments[0] == 'object') {
          collection = arguments[0];
        } else {
          collection = arguments;
        }
    
    
        for (var i = 0; i < collection.length; i++) {
          this[collection[i]] = this[collection[i]] === undefined ? 1 : this[collection[i]] + 1;
          this._total++;
        }
      }
    
      WeightedList.prototype.getRandomKey = function() {
        if (this._total < 1)
          throw new EmptyListError();
    
        var num = Math.random();
        var lowerBound = 0;
    
        var keys = Object.keys(this);
        for (var i = 0; i < keys.length; i++) {
          if (keys[i] != "_total") {
            if (num < lowerBound + this[keys[i]] / this._total) {
              return keys[i];
            }
            lowerBound += this[keys[i]] / this._total;
          }
        }
    
        return keys[keys.length - 1];
      };
    
      WeightedList.prototype.increaseRank = function(key) {
        if (key !== undefined && key != "_total") {
          if (this[key] !== undefined) {
            this[key]++;
          } else {
            this[key] = 1;
          }
    
          this._total++;
        }
      };
    
      WeightedList.prototype.clearRanks = function() {
        var keys = Object.keys(this);
        for (var i = 0; i < keys.length; i++) {
          if (keys[i] != "_total") {
            this._total -= this[keys[i]] - 1;
            this[keys[i]] = 1;
          }
        }
      };
    
      return WeightedList;
    });

    Вот почему я за четкое разделение объектов/структур и хэшей (ассоциативных массивов).

    JaneBurt, 07 Мая 2021

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

    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
    function test3()
    {
    		const a = 10.5
    	        switch (a) 
    		{                                            
    		    case 10.5:
            	        print("cool. 10.5");                          
    			break;                                          
    	        }
    }
    
    function test3()
    {		
    	        switch ("kokoko") 
    		{                                            
    		    case "kokoko":
            	        print("pituh");                          
    			break;                                          
    	        }
    }

    Продолжаем говнокомпилить...

    А ваш С такое прокомпилирует? мой - запросто :)

    ASD_77, 05 Мая 2021

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

    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
    // В одном файле
    
    // Getting gif by url
    const getGifUrl = (searchQuery, gifRating) => {
      const fullUrl = `${giphyUrl}${giphyApiKey}&tag=${searchQuery}&rating=${gifRating}`;
      let gifSource;
      let girSourceOriginal;
    
      fetch(fullUrl).then(response => {
        return response.json();
      }, networkError => {
        console.log(networkError);
      }).then(jsonResponse => {
        if (!jsonResponse)
          gifSource = '';
        else {
          gifSource = jsonResponse.data.images.preview_gif.url;
          gifSoucreOriginal = jsonResponse.data.image_original_url;
        }
    
        renderGif(gifSource, gifSoucreOriginal);
      });
    };
    
    // Где-то в другом файле
    
    // incapsulating image
    const incapsulateImage = (gifUrl, gifUrlOriginal) => {
      // creating gif preview tile
      const image = document.createElement('img');
      image.src = gifUrl;
    
      // create link to the original gif
      const linkOriginal = document.createElement('a');
      linkOriginal.href = gifUrlOriginal;
    
      // incapsulating gif tile into link
      linkOriginal.appendChild(image);
    
      // create container-tile
      const tile = document.createElement('div');
      tile.className = "container-tile";
    
      // incapsulating linked gif into tile
      tile.appendChild(linkOriginal);
    
      return tile;
    }
    
    // Rendering one gif image
    const renderGif = (gifUrl, gifUrlOriginal) => {
      if (gifUrl) {
        const imageTile = incapsulateImage(gifUrl, gifUrlOriginal);
        $gifContainer.append(imageTile);
      } else if (!$gifContainer.html()) {
        const notFoundHeading = document.createElement('h1');
        notFoundHeading.innerHTML = NOT_FOUND_TEXT;
        $gifContainer.append(notFoundHeading);
      }
    };
    
    const render = () => {
       // Rendering whole block of gifs
      const renderContainer = (searchQuery, gifCount, gifRating) => {
        for (let i = 0; i < gifCount; i++) {
          getGifUrl(searchQuery, gifRating);
    
          const heading = $gifContainer.find('h1');
          if (heading && heading.text() == NOT_FOUND_TEXT) {
            break;
          }
        }
      }
    
      // ...Сетап всяких обработчиков событий на элементы...
    }

    Когда толком не знал про промисы (а уж тем более про модули), городил такую дичь.

    JaneBurt, 02 Мая 2021

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function main() {    
    	(function () {
    		print("Hello World!");
    	})();
    }

    а ваш С компилятор может так говнокодить? а мой компилятор может :)

    ASD_77, 30 Апреля 2021

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

    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
    function f1() 
    {               
      print("Hello World!");    
    }
    
    function run(f: () => void)
    {
      f();
    }
    
    function main() {    
     const x = f1;
     x();                                
     run(x);
    }
    
    // LLVM IL 
    
    ; ModuleID = 'LLVMDialectModule'
    source_filename = "LLVMDialectModule"
    target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
    target triple = "x86_64-pc-windows-msvc"
    
    @frmt_11120820245497078329 = internal constant [4 x i8] c"%s\0A\00"
    @s_11208736881023205110 = internal constant [14 x i8] c"Hello World!\00\00"
    
    declare i8* @malloc(i64)
    
    declare void @free(i8*)
    
    declare i32 @printf(i8*, ...)
    
    define void @f1() !dbg !3 {
      %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11120820245497078329, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @s_11208736881023205110, i64 0, i64 0)), !dbg !7
      br label %2, !dbg !9
    
    2:                                                ; preds = %0
      ret void, !dbg !9
    }
    
    define void @run(void ()* %0) !dbg !10 {
      %2 = alloca void ()*, align 8, !dbg !11
      store void ()* %0, void ()** %2, align 8, !dbg !11
      %3 = load void ()*, void ()** %2, align 8, !dbg !11
      call void %3(), !dbg !13
      br label %4, !dbg !14
    
    4:                                                ; preds = %1
      ret void, !dbg !14
    }
    
    define void @main() !dbg !15 {
      %1 = alloca void ()*, align 8, !dbg !16
      %2 = alloca void ()*, align 8, !dbg !19
      store void ()* @f1, void ()** %2, align 8, !dbg !19
      %3 = load void ()*, void ()** %2, align 8, !dbg !19
      call void %3(), !dbg !20
      %4 = load void ()*, void ()** %2, align 8, !dbg !19
      %5 = bitcast void ()** %1 to i8*, !dbg !16
      call void @llvm.lifetime.start.p0i8(i64 8, i8* %5), !dbg !16
      store void ()* %4, void ()** %1, align 8, !dbg !16
      %6 = load void ()*, void ()** %1, align 8, !dbg !16
      call void %6(), !dbg !21
      %7 = bitcast void ()** %1 to i8*, !dbg !22
      call void @llvm.lifetime.end.p0i8(i64 8, i8* %7), !dbg !22
      br label %8, !dbg !23
    
    8:                                                ; preds = %0
      ret void, !dbg !23
    }
    
    ; Function Attrs: argmemonly nofree nosync nounwind willreturn
    declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #0
    
    ; Function Attrs: argmemonly nofree nosync nounwind willreturn
    declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #0
    
    attributes #0 = { argmemonly nofree nosync nounwind willreturn }

    продолжаем говнокодить компилятор аля TypeScript в нативный код. ну это как С компилятор только без тупо-уродо-* у имен переменных

    1) компилим точно также как и до этого в постах
    2) получаем результат

    >> Hello World!
    Hello World!

    ASD_77, 29 Апреля 2021

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

    −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
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    const connectToServerEpic = (
      action$,
    ) => (
      action$
      .pipe(
        ofType(CONNECT_TO_SERVER),
        switchMap(({
          hostname,
          port,
          protocol,
          protocolVersion,
          reconnectionTimeout,
        }) => (
          action$
          .pipe(
            ofType(RECONNECT_TO_SERVER),
            takeUntil(
              action$
              .pipe(
                ofType(DISCONNECT_FROM_SERVER),
              )
            ),
            startWith(null),
            map(() => (
              webSocket({
                protocol: protocolVersion,
                url: (
                  protocol
                  .concat('://')
                  .concat(hostname)
                  .concat(':')
                  .concat(port)
                ),
                WebSocketCtor: WebSocket,
              })
            )),
            switchMap((
              webSocketConnection$,
            ) => (
              webSocketConnection$
              .pipe(
                takeUntil(
                  action$
                  .pipe(
                    ofType(
                      RECONNECT_TO_SERVER,
                      DISCONNECT_FROM_SERVER,
                    ),
                  )
                ),
                catchError(() => (
                  timer(
                    reconnectionTimeout,
                  )
                  .pipe(
                    takeUntil(
                      action$
                      .pipe(
                        ofType(
                          RECONNECT_TO_SERVER,
                          DISCONNECT_FROM_SERVER,
                        ),
                      )
                    ),
                    mapTo(reconnectToServer()),
                  )
                )),
                map(receivedWebSocketMessage),
                startWith(
                  connectionReady(
                    webSocketConnection$,
                  )
                ),
              )),
            )),
          )
        )),
      )
    )

    https://itnext.io/simplifying-websockets-in-rxjs-a177b887f3b8

    DypHuu_niBEHb, 21 Апреля 2021

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