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

    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
    class RayTracer {
        private maxDepth = 5;
    
        private intersections(ray: Ray, scene: Scene) {
            let closest = +Infinity;
            let closestInter: Intersection = undefined;
            for (let i in scene.things) {
                let inter = scene.things[i].intersect(ray);
                if (inter != null && inter.dist < closest) {
                    closestInter = inter;
                    closest = inter.dist;
                }
            }
    
            return closestInter;
        }
    
        private testRay(ray: Ray, scene: Scene) {
            let isect = this.intersections(ray, scene);
            if (isect != null) {
                return isect.dist;
            } else {
                return undefined;
            }
        }
    
        private traceRay(ray: Ray, scene: Scene, depth: number): Color {
            let isect = this.intersections(ray, scene);
            if (isect === undefined) {
                return Color.background;
            } else {
                return this.shade(isect, scene, depth);
            }
        }
    
        private shade(isect: Intersection, scene: Scene, depth: number) {
            let d = isect.ray.dir;
            let pos = Vector.plus(Vector.times(isect.dist, d), isect.ray.start);
            let normal = isect.thing.normal(pos);
            let reflectDir = Vector.minus(d, Vector.times(2, Vector.times(Vector.dot(normal, d), normal)));
            let naturalColor = Color.plus(Color.background,
                this.getNaturalColor(isect.thing, pos, normal, reflectDir, scene));
            let reflectedColor = (depth >= this.maxDepth) ? Color.grey : this.getReflectionColor(isect.thing, pos, normal, reflectDir, scene, depth);
            return Color.plus(naturalColor, reflectedColor);
        }
    
        private getReflectionColor(thing: Thing, pos: Vector, normal: Vector, rd: Vector, scene: Scene, depth: number) {
            return Color.scale(thing.surface.reflect(pos), this.traceRay({ start: pos, dir: rd }, scene, depth + 1));
        }
    
        private getNaturalColor(thing: Thing, pos: Vector, norm: Vector, rd: Vector, scene: Scene) {
            const addLight = (col: Color, light: Light) => {
                let ldis = Vector.minus(light.pos, pos);
                let livec = Vector.norm(ldis);
                let neatIsect = this.testRay({ start: pos, dir: livec }, scene);
                let isInShadow = (neatIsect === undefined) ? false : (neatIsect <= Vector.mag(ldis));
                if (isInShadow) {
                    return col;
                } else {
                    let illum = Vector.dot(livec, norm);
                    let lcolor = (illum > 0) ? Color.scale(illum, light.color)
                        : Color.defaultColor;
                    let specular = Vector.dot(livec, Vector.norm(rd));
                    let scolor = (specular > 0) ? Color.scale(Math.pow(specular, thing.surface.roughness), light.color)
                        : Color.defaultColor;
                    return Color.plus(col, Color.plus(Color.times(thing.surface.diffuse(pos), lcolor),
                        Color.times(thing.surface.specular(pos), scolor)));
                }
            }
            //return scene.lights.reduce(addLight, Color.defaultColor);
            let resColor = Color.defaultColor;
            for (const light of scene.lights) {
                resColor = addLight(resColor, light);
            }
    
            return resColor;
        }
    
        render(scene: Scene, screenWidth: number, screenHeight: number) {
            const getPoint = (x: number, y: number, camera: Camera) => {
                const recenterX = (x: number) => (x - (screenWidth / 2.0)) / 2.0 / screenWidth;
                const recenterY = (y: number) => - (y - (screenHeight / 2.0)) / 2.0 / screenHeight;
                return Vector.norm(Vector.plus(camera.forward, Vector.plus(Vector.times(recenterX(x), camera.right), Vector.times(recenterY(y), camera.up))));
            }
    
            for (let y = 0; y < screenHeight; y++) {
                for (let x = 0; x < screenWidth; x++) {
                    let color = this.traceRay({ start: scene.camera.pos, dir: getPoint(x, y, scene.camera) }, scene, 0);
                    let c = Color.toDrawingColor(color);
                    //ctx.fillStyle = "rgb(" + String(c.r) + ", " + String(c.g) + ", " + String(c.b) + ")";
                    //ctx.fillRect(x, y, x + 1, y + 1);
    		// next line eats stack (or memory?)
    		print(`<rect x="${x}" y="${y}" width="1" height="1" style="fill:rgb(${c.r},${c.g},${c.b});" />`);
                }
            }
        }
    }
    
    
    function defaultScene(): Scene {

    шас я вас залью кодик т.к. все не влазит ловите код на https://pastebin.com/qMZmnCqT так вот это вот компилиться и работает на новом компиляторе

    ASD_77, 08 Ноября 2021

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

    +1

    1. 1
    npm install

    очередной npm пакет с трояном

    https://www.bleepingcomputer.com/news/security/popular-coa-npm-library-hijacked-to-steal-user-passwords/

    Her, 05 Ноября 2021

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

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    interface Surface {
    	n: number;
    }
    
    let shiny: Surface = {
    	n: 10.0
    }
    
    function main() {
    	print(shiny.n);
    }

    шах и мат С/C++ девелоперам :) (постов не будет - сайт все блокирует)

    ASD_77, 02 Ноября 2021

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

    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 Something {
        r: number;
        g: number;
        b: number;
        toString: () => string;
    }
    
    function main() {
        const something = {
            r: 11.0, g: 12.0, b: 13.0, toString() {
                return "Hello " + this.b;
            }
        };
    
        const iface = <Something>something;
        print(iface.toString());
    
        print("done.");
    }

    Интерфесы для абстрактых обьектов.. а ваш говно компилятор может так?

    ASD_77, 28 Октября 2021

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    let textarea = document.querySelector('textarea')
    let list = document.querySelector('ol')
    let newTask = document.createElement('li')
    newTask.innerText = textarea.value
    
    function submitTask() {
        list.appendChild(newTask)
    }

    При попытке добавлять новый HTML элемент функция добавления срабатывает только один раз, к тому же для добавления используется не то значение которое я ввожу в текстовое поле, а только дефолтное. Так как я перепробовал уже массу вариантов и с инпутом, и с событием нажатия Enter, какие-то варианты, которые уже забыл, я подозреваю, что проблема, вероятно, в appendChild, но не уверен, и не понимаю её.

    shuric, 22 Октября 2021

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

    −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
    let glb1 = 0;
    
    class Color {
        static constructor() {
            glb1++;
            print("Static construct");
        }
    
        constructor(public r: number,
            public g: number,
            public b: number) {
        }
    
        static white = 1;
    }
    
    class Color2 {
        static constructor() {
            glb1++;
            print("Static construct 2");
        }
    }
    
    function main() {
        assert(glb1 == 2);
        print("done.");
    }

    добавил статические кострукторы... а то забыл эту хню сделать

    ASD_77, 21 Октября 2021

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

    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
    function main4() {
    
        let i = 0;
    
        try {
            try {
                throw 1.0;
            }
            catch (e: number) {
                i++;
                print("asd1");
                throw 2.0;
            }
            finally {
                print("finally");
            }
        }
        catch (e2: number) {
            i++;
            print("asd3");
        }
    
        assert(i == 2);
    }
    
    function main() {
        main4();
        print("done.");
    }

    Ну вот и все.. шах и мат С/C++ девелоперы... последняя хитровые...аная инструкция finally сделана. (надо еще для линуха сделать .. а то они разные)

    ASD_77, 13 Октября 2021

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

    +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
    function main() {
        let c = 0;
    
        try {
            c++;
            print("try");
            throw "except";
            c--;
            print("after catch");
        } finally {
            c++;
            print("finally");
        }
    
        assert(2 == c);
    }

    ну вот и все... проимплементил последний keyword в языке... (осталось только темплейты - ну и головняк меня ждем)

    ASD_77, 29 Сентября 2021

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

    +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
    alex@ASD-PC:~/TypeScriptCompiler/3rdParty/llvm-wasm/debug/bin$ node mlir-translate.js --help
    OVERVIEW: MLIR Translation Testing Tool
    USAGE: mlir-translate.js [options] <input file>
    
    OPTIONS:
    
    Color Options:
    
      --color                                              - Use colors in output (default=autodetect)
    
    General options:
    
      --dot-cfg-mssa=<file name for generated dot file>    - file name for generated dot file
      --mlir-disable-threading                             - Disabling multi-threading within MLIR
      --mlir-elide-elementsattrs-if-larger=<uint>          - Elide ElementsAttrs with "..." that have more elements than the given upper limit
      --mlir-pretty-debuginfo                              - Print pretty debug info in MLIR output
      --mlir-print-debuginfo                               - Print debug info in MLIR output
      --mlir-print-elementsattrs-with-hex-if-larger=<long> - Print DenseElementsAttrs with a hex string that have more elements than the given upper limit (use -1 to disable)
      --mlir-print-op-on-diagnostic                        - When a diagnostic is emitted on an operation, also print the operation as an attached note
      --mlir-print-stacktrace-on-diagnostic                - When a diagnostic is emitted, also print the stack trace as an attached note
      -o=<filename>                                        - Output filename
      --split-input-file                                   - Split the input file into pieces and process each chunk independently
      Translation to perform
          --deserialize-spirv                                 - deserialize-spirv
          --import-llvm                                       - import-llvm
          --mlir-to-llvmir                                    - mlir-to-llvmir
          --serialize-spirv                                   - serialize-spirv
          --test-spirv-roundtrip                              - test-spirv-roundtrip
          --test-spirv-roundtrip-debug                        - test-spirv-roundtrip-debug
      --verify-diagnostics                                 - Check that emitted diagnostics match expected-* lines on the corresponding line
    
    Generic Options:
    
      --help                                               - Display available options (--help-hidden for more)
      --help-list                                          - Display list of available options (--help-list-hidden for more)
      --version                                            - Display the version of this program
    program exited (with status: 0), but EXIT_RUNTIME is not set, so halting execution but not exiting the runtime or preventing further async execution (build with EXIT_RUNTIME=1, if you want a true shutdown)
    alex@ASD-PC:~/TypeScriptCompiler/3rdParty/llvm-wasm/debug/bin$

    сказ о том как я LLVM на WASM компилял :)

    ASD_77, 28 Сентября 2021

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

    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
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    const range = (count) => Array.from(Array(count).keys());
    class Matrix {
    
        static Dot(A, B) {
            // Dot production
            const wA = A[0].length;
            const hA = A.length;
            const wB = B[0].length;
            const hB = B.length;
    
            if (wA != hB)
            {
                throw "A width != B height";
            }
    
            const C = range(hA).map((_, i) => range(wB).map((_, j) => 0));
    
            for (let i = 0; i < hA; ++i)
                for (let j = 0; j < wB; ++j) {
                    let sum = 0;
    
                    for (let k = 0; k < wA; ++k) {
                        const a = A[i][k];
                        const b = B[k][j];
                        sum += a * b;
                    }
    
                    C[i][j] = sum;
                }
    
            return C;                
        }
    
        static Mul(A, B) {
            // Dot production
            const wA = A[0].length;
            const hA = A.length;
            const wB = B[0].length;
            const hB = B.length;
    
            if (wA != wB || hA != hB)
            {
                throw "A width != B width, A height != B height";
            }
    
            const C = range(hA).map((_, i) => range(wA).map((_, j) => A[i][j] * B[i][j]));
            return C;
        }            
    
        static Add(A, B) {
            const wA = A[0].length;
            const hA = A.length;
            const wB = B[0].length;
            const hB = B.length;
    
            if (wA != wB || hA != hB)
            {
                throw "A width != B width, A height != B height";
            }
    
            const C = range(hA).map((_, i) => range(wA).map((_, j) => A[i][j] + B[i][j]));
            return C;
        }
    
        static Sub(A, B) {
            const wA = A[0].length;
            const hA = A.length;
            const wB = B[0].length;
            const hB = B.length;
    
            if (wA != wB || hA != hB)
            {
                throw "A width != B width, A height != B height";
            }
    
            const C = range(hA).map((_, i) => range(wA).map((_, j) => A[i][j] - B[i][j]));
            return C;
        }
    
            static Translate(A, shift) {
            const wA = A[0].length;
            const hA = A.length;
    
            const R = range(hA).map((_, i) => range(wA).map((_, j) => A[i][j] + shift));
            return R;                        
        }         
    
        static Sigmoid(A) {
            const wA = A[0].length;
            const hA = A.length;
    
            const R = range(hA).map((_, i) => range(wA).map((_, j) => 1 / (1 + Math.exp(-A[i][j]))));
            return R;                                        
        }
    //...
    }

    лаба по математике матрици :)

    ASD_77, 26 Сентября 2021

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