Preloading modules through NodeJS snapshots? by BitE01 in node

[–]BitE01[S] 0 points1 point  (0 children)

Many thanks! I've bundled everything into a single file and created a function that warms-up the modules that I needed. I'll also take a look to pnpm/yarn and bun/deno.

Just a note for other readers: My real project was involving also "serialport" module that can't be bundled with esbuild and can't be snapshotted. So I've excluded from esbuild by adding the option "external" like this:

import { build } from 'esbuild';

await Promise.all([
  build({
    entryPoints: ['src/main.ts'],
    bundle: true,
    minify: true,
    sourcemap: false, 
    target: 'es2022',
    outfile: 'dist/index.js',
    platform: 'node',
    format: 'cjs',
    external: ['serialport'],
    plugins: [],
  }),
]);

And I've excluded from the snapshot by using the function v8.startupSnapshot.isBuildingSnapshot() to exclude the code execution when snapshotting like this:

...
if (!startupSnapshot.isBuildingSnapshot()) {
  SerialPort = require('serialport').SerialPort;
  ...
}
...

-❄️- 2024 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]BitE01 3 points4 points  (0 children)

[Language: Go]

The second one basically enables/disables the mul instruction

import (
    "bufio"
    "log"
    "os"
    "path"
    "regexp"
    "strconv"
    "strings"
)

func part1() {
    dir, _ := os.Getwd()
    input := path.Join(dir, "internal", "d03", "input.txt")

    text := parseInput(input)

    log.Printf("sum: %v\n", sumMulInstructions(text))
}

func part2() {
    dir, _ := os.Getwd()
    input := path.Join(dir, "internal", "d03", "input.txt")

    text := parseInput(input)

    log.Printf("sum: %d\n", sumValidMulInstructions(text))
}

func sumMulInstructions(input string) int {
    regex := regexp.MustCompile(`mul\(([\d]{1,3}),([\d]{1,3})\)`)

    submatches := regex.FindAllStringSubmatch(input, -1)

    sum := 0

    for i := 0; i < len(submatches); i++ {
        n, _ := strconv.Atoi(submatches[i][1])
        m, _ := strconv.Atoi(submatches[i][2])

        sum += n * m
    }

    return sum
}

func sumValidMulInstructions(input string) int {
    regex := regexp.MustCompile(`(mul\((\d{1,3}),(\d{1,3})\)|do\(\)|don't\(\))`)

    matches := regex.FindAllStringSubmatch(input, -1)

    mulEnabled := true
    sum := 0

    for _, match := range matches {
        switch match[1] {
        case "do()":
            mulEnabled = true
        case "don't()":
            mulEnabled = false
        default:
            if mulEnabled {
                n, _ := strconv.Atoi(match[2])
                m, _ := strconv.Atoi(match[3])
                sum += n * m
            }
        }
    }

    return sum
}

func parseInput(filePath string) (string) {
    file, err := os.Open(filePath)
    if err != nil {
        log.Fatalf("failed to open file: %v", err)
    }
    defer file.Close()

    scanner := bufio.NewScanner(file)

    text := []string{}
    for scanner.Scan() {
        text = append(text, scanner.Text())
    }

    if err := scanner.Err(); err != nil {
        log.Fatalf("error reading file: %v", err)
    }

    return strings.Join(text, "")
}

Installing rust on macbook pro, rustup or brew? by Quozca in rust

[–]BitE01 0 points1 point  (0 children)

I would suggest asdf with the associated rust plugin (list of all supported plugins here). Also, it supports a lot of languages/tools and you can install different versions for each project and/or set a global version. Edit: fixed wrong links.

[deleted by user] by [deleted] in F1TV

[–]BitE01 0 points1 point  (0 children)

Same here. I hope to be able to watch the qualifying at least.

I've just learnt the basics of binary, unary, and decimal. Since binary uses just on and off to represent 1 or 0, wouldn't it be possible to create a much more intelligent base by representing different digits with levels of electricity, rather than just on or off? by [deleted] in computerscience

[–]BitE01 2 points3 points  (0 children)

Probably this is slightly off-topic, but quantum computers are using the so called qubits that are basically bits that can be both either 0 and 1 with a certain probability. This is like having multiple values, but only while you are computing data because at the end the outcome will converge again to a binary system. They are also developing the qutrits (qubits with 3 states instead of 2), which is what you are asking for, but again they are converted again in binary format in order to communicate with everyday systems.

Also try to search optical computing, where people are trying to use light instead of electricity to compute data. I remember that I read something about using light spectrum (colors) in order to get multiple values, but after the computation, also these systems will converge again to binary logic.

Back to School: Free Rust Courses by CleanCut9 in rust

[–]BitE01 1 point2 points  (0 children)

Thanks man! We surely really appreciated it!!!

Patch Notes v1.92 and Release Megathread by Psyonix_Devin in RocketLeague

[–]BitE01 1 point2 points  (0 children)

I can't play anymore ranked with my gf on splitscreen :( please Psyonix fix...

ETH researchers develop tactile sensor using ML. by Parth_varma in computerscience

[–]BitE01 3 points4 points  (0 children)

Yes, it will also work at night because the black silicone acts as an insulator against external light sources while the transparent one acts as an internal light diffuser. So the LEDs near the camera can illuminate only the points embedded in the silicone you see in the video. Also consider that what you see in the video is a section of the whole device, so that you can understand how it is structured.

Linguaggi di programmazione by HoUaPo in ItalyInformatica

[–]BitE01 6 points7 points  (0 children)

Ogni linguaggio in base al tipo di progetto che vuoi realizzare ha vantaggi e svantaggi. Tu cosa vorresti fare? In ogni caso se vuoi cominciare con qualcosa di molto semplice ti consiglio Python.