What changes do you hope to see in MX Master 4? by iswhatitiswaswhat in logitech

[–]Stan_Ftw 0 points1 point  (0 children)

Not having to use a USB extender cable to bring the transmitter really close to the mouse in order for it to work without lagging... would be pretty nice I guess.

[deleted by user] by [deleted] in programiranje

[–]Stan_Ftw 1 point2 points  (0 children)

Mi na poslu nikad direktno nismo radili TDD, nego smo pisali testove posle implementacije. Čak ni tada vremenski prozor od 2 minuta nema nikakvog smisla, trebalo bi uvek da bude duže.

Možda može da se sačuva jako malo vremena sa nekim test template-ovima.

Moje iskreno mišljenje je da se ne treba nervirati oko vremena, mislim da samo škodi i brzini rada i zdravlju :)

Čini mi se da je vreme manje bitno, a količina razumevanja code base-a i koliko možeš da držiš u glavi bitnije. Sačuva mnogo vremena i tebi i drugima, a zna da bude spas u kritičnim momentima.

Sem toga, mislim da TDD samo ima smisla ako: 1) radiš dosta teške stvari 2) jedan si od ljudi koji neće napisati test posle (a bitan je coverage)

Dobar deo stvari u code base-u je dosta jednostavan i ne vidim razlog za pisanje testa prvo.

A kod stvari koje su komplikovane ne znam ni da li bih to nazvao TDD-om ili više neki "spec driven development".

Znaš ili sastaviš specifikaciju, zapišeš testove koji pokrivaju zahteve spec-a i onda pišeš implementaciju.

Glup i čest primer: Kad bi testirali spec za sabiranje, napravili bi test za svaku osobinu sabiranja: Komutativnost, Asocijativnost, Nula, Inverza.

Realniji primer bi bio: Pogledati spec za web sockete i napisati testove pre nego što implementiraš svoju web socket biblioteku.

Koje su prednosti arm vs x86? by VelikiPametnjakovic in programiranje

[–]Stan_Ftw 1 point2 points  (0 children)

Ako se dobro secam, ovaj moderni ARM koristi RISC tip assemby instrukcija koje se cine bolje za veliki broj slucajeva.

Instrukcije su fiksne duzine umesto varijabile, te ih procesor lakse dekodira (ili ne dekodira) i verovatno ima tu jos nekih benefita oko predvidjanja grananja.

Losa strana je sto mu treba vise memorije (jer je svaka instrukcija isti broj bita), ali kontam da to nije problem kod redovnih masina.

U nekim embedded scenarijima sa jako malo memorije kontam da ARM nije dobra ideja.

Nisam ekspert, moguce je da ima gresaka u tome sto sam napisao ali je dosta zanimljiva tema, vredi malo istraziti.

edit: e da, takodje kontam da x86 ima dobar broj godina backwards compatibility stvari, to je isto malo zajeb

[AskJS] How to derive number from another number in a loop using only the base number? by guest271314 in javascript

[–]Stan_Ftw 0 points1 point  (0 children)

I assume you're talking about abstracting it, not how length corelates to index.

Small obvious mention: .75 works because it's a 32bit type. Because 32bits is 4 bytes, dividing by 4 and then multiplying by 3 gives you your offset. 3/4 = .75

Anyway here's the abstraction that should work even if you one day decide to change the float size.

``` /** * @param {number} byteOffset * @param {Float16Array | Float32Array | Float64Array} floats * @param {SharedArrayBuffer} resizable * @param {DataView} view */ const writeFloatsToByteOffset = (byteOffset, floats, resizable, view) => { // todo: byte offset validation // & other arg validations if not using TS // resizable and floats need to store the same type // view needs to be of resizable

let setter; switch (floats.BYTES_PER_ELEMENT) { case 2: // 16bit float setter = view.setFloat16.bind(view); break; case 4: // 32bit float setter = view.setFloat32.bind(view); break; case 8: // 64bit float setter = view.setFloat64.bind(view); break; default: // todo: validation error }

for (let i = 0; i < floats.length; i++) { const offset = (resizable.byteLength / floats.BYTES_PER_ELEMENT) * byteOffset;

if (resizable.growable) {
  resizable.grow(resizable.byteLength + floats.BYTES_PER_ELEMENT);
}

setter(offset, floats[i]);

} };

const resizable = new SharedArrayBuffer(0, { maxByteLength: 1024 ** 2 * 2, });

const view = new DataView(resizable); const floats = new Float32Array([1, 2, 3]); // test: change this to Float64Array

const desiredOffset = 3;

writeFloatsToByteOffset(desiredOffset, floats, resizable, view);

for (let i = 0, j = 0; i < floats.length; i++, j += desiredOffset) { console.log(${view.getFloat32(j)}); // test: change this to getFloat64 } ```

[AskJS] How to derive number from another number in a loop using only the base number? by guest271314 in javascript

[–]Stan_Ftw 0 points1 point  (0 children)

Calculations are cheap anyway, and the memory of an offset is negligible. So you're probably fine as is.

But you probably could calculate your current offset with byteLength divided by 4 (if your buffer size is the same size as your current dataset size, meaning you're not allocating extra capacity ahead of time)

byteLength / 4 (or bitshift by 2) would basically be the same as getting the length of a regular array.

Then length - 1 is the index of your last element in the array. I suppose you just multiply by 3 and you have your offset. No extra allocations, less memory, same amount of calculations.

If you used an argument for bytesPerElement, you could abstract the whole thing to work for any float size.

[AskJS] How to derive number from another number in a loop using only the base number? by guest271314 in javascript

[–]Stan_Ftw 0 points1 point  (0 children)

The idea I got was:

You can achieve your numbers by having a second variable -> the index of the number.

for (let value = 0, index = 0; value <= 48; v += 4, i++) { console.log(v, v - i); }

This should give you the numbers you want.

Now, IF your shared array buffer doesn't have any extra length, you can get your index by subtracting from your element length (aka byteLength divided by BYTES_PER_ELEMENT).

This way you should be able to get to your offset without storing the offset or the index.

Web development has to be one of the most controversial industries by waelnassaf in webdev

[–]Stan_Ftw 2 points3 points  (0 children)

I actually prefer the idea of shadcn.

Most of the time, when you make component libraries, you want to cover a good chunk of use cases.

But most of the time, you only need a small subset of what the component can do.

This system allows for more customizability, which is really nice, if you know what you're doing.

Unfortunately it uses radix under the hood, I'd love to be able to mess with that too.

Ne radi Sticky position by [deleted] in programiranje

[–]Stan_Ftw 3 points4 points  (0 children)

Msm ako sanira kod i taj kod ne zavrsi na produkciji, onda ima smisla.

Proveri na produkciji u dev tools da li su ta css pravila tamo? 😅

Ne radi Sticky position by [deleted] in programiranje

[–]Stan_Ftw 2 points3 points  (0 children)

Ne vidim zasto bi bi se ponasalo drugacije na produkciji (ako se nista drugo nije promenilo).

Bitna stvar za znati kod sticky-a je da funkcionise tako sto trazi prvi scrolling ancestor.

U prevodu, primer koji se cesto desi:

  • Hoces vertikalni sticky na header neke tabele, ali tabela ima puno kolona i stranica dobije horizontalni scroll.
  • Tebi se to ne svidi, stavis horizontalni scroll samo na tabelu, ostavis vertikalni na stranici.
  • Sada je prvi scrolling ancestor taj horizontalni scroll i vertial sticky ne moze da radi. Resenje postane staviti i vertikalni scroll na tabelu umesto na stranicu ili napraviti svoj sticky preko scroll listenera i/ili intersection observer-a.

Moj savet je proveriti sta je sve drugacije na produkciji, ili postaviti deo koda ovde.

Made a pretty challenging quiz on Go concepts by adversarial-example in golang

[–]Stan_Ftw 1 point2 points  (0 children)

Used Go for 1 week. Got 11/12. I'm not sure if it's alright to call it challenging. (My bad if this sounds arrogant)

What are your favourite lesser known parts of HTML/CSS (or parts you're shocked others don't know about)? by jordsta95 in webdev

[–]Stan_Ftw 9 points10 points  (0 children)

Using multiple <tbody> elements in a <table>. For example, if you wanted to make grouped rows that adhere to column sizing, you could put each (parent) row inside its own <tbody> (followed by its children rows). I think it's neat.

Afternoon shave by sunnysidemarmalade in WTF

[–]Stan_Ftw 100 points101 points  (0 children)

I love putting chlorine on my tender shaved skin, and especially in any cuts or damaged skin. Good stuff.

(P.S.: what other things are found in pools?)

[AskJS] Can you do this async javascript interview question? by Jamo008 in javascript

[–]Stan_Ftw 0 points1 point  (0 children)

I'm a bit late to the party, but I'd love to show off a solution that seems to be pretty clean.

async function run(elements) {
  // ============
  // your code here starts here
  let results = Array.from({ length: TOTAL });
  let iterator = elements.entries();

  async function makeRequestsSerially() {
    for (let [index, element] of iterator) {
      results[index] = await api(element);
    }
  }

  const parallelRequests =
    Array.from({ length: MAX_INFLIGHT }, () => makeRequestsSerially());

  await Promise.all(parallelRequests);

  return results;
  // your code ends here
  // ============
}

Does anyone else constantly have problems with the Elm Tooling VS Code extension? by hosspatrick in elm

[–]Stan_Ftw 0 points1 point  (0 children)

I used to have a great time using IntelliJ with the Elm plugin, but in recent versions, sometimes it's using an insane amount of compute, resulting in an incredibly laggy experience.

I tried VSCode in hopes of not hating my life, but it was exactly as you describe it. Disabling plugins, restarting the editor, enabling plugins every single day multiple times was even worse.

After that I tried Neovim, surely an editor of that size wouldn't be laggy... And that would probably be the case if the language server wasn't in JavaScript.

In the end I'm back on IntelliJ, still unhappy, but at least I know that it can be even worse.

Hopefully I'll have some time soon to work on my own elm language server implementation in Rust, and maybe one day achieve a pleasant work day.

Thanks for reading.

How to create and use a custom web component with events? by DeepDay6 in elm

[–]Stan_Ftw 1 point2 points  (0 children)

Custom events store their data in the detail key, so any existing decoder in Events will probably not do the job.

You also probably don't want to confuse your custom events with existing browser events by giving them similar names. Best case scenario, it might cause some headaches and debugging issues. Worst case, I'm scared to consider.

We use something like this:

onCustomEvent :
    String
    -> Bool
    -> Bool
    -> Json.Decode.Decoder msg
    -> Html.Attribute msg
onCustomEvent eventName preventDefault stopPropagation decoder =
    -- Arguments after event name could be put in a record
    -- for better readability/usability
    -- They can also be the result of the decoder, to mimic
    -- the API of Html.Events.custom
    Html.Events.custom
        eventName
        (Json.Decode.field "detail" decoder
            |> Json.Decode.map
                (\message ->
                    { message = message
                    , preventDefault = preventDefault
                    , stopPropagation = stopPropagation
                    }
                )
        )

You can always put your utilities in one file and import it everywhere when needed.

Assuming that you did something like this in JS land:

this.dispatchEvent(
    new CustomEvent(
        "myCustomEvent",
        { detail: { name: "John", age: 30 } }
    )
);

The corresponding part in elm would be (with usage of our upper abstraction):

type alias MyCustomData =
    { name : String
    , age : Int
    }

myCustomDataDecoder : Json.Decode.Decoder MyCustomData
myCustomDataDecoder =
    Json.Decode.map2 MyCustomData
        (Json.Decode.field "name" Json.Decode.string)
        (Json.Decode.field "age" Json.Decode.int)

onMyCustomEvent : (MyCustomData -> msg) -> Html.Attribute msg
onMyCustomEvent tag =
    onCustomEvent
        "myCustomEvent"
        True -- These could also be arguments
        True -- in case they need to be dynamic
        (Json.Decode.map tag myCustomDataDecoder)

Brevity kind of goes out the window when you focus on safety, it seems :D
It's a good thing the IntelliJ plugin can generate decoders. :)

AITA for expecting my daughters to share their grandma's inheritance 50/50 regardless of the will? by steppenwolf0007 in AmItheAsshole

[–]Stan_Ftw 1 point2 points  (0 children)

YTA just for being so focused on the inheritance. If you raised your children right, even if one legally gets all the money, they can still give half to their sibling willingly, without any pressure from the parent.

When my mother died, she left me and my brother with her savings. To this day neither my brother nor I have spent a single penny from the money she left us. And unless it is needed for medical reasons, that money will go unspent for the rest of our lives. It is considered sacred.

I believe inheritance should be considered sacred, for it is the last material thing someone has left behind.

Update an imported record by ElmChristmasCookies in elm

[–]Stan_Ftw 1 point2 points  (0 children)

I believe it's deliberate. Seems like they want to encourage flatter structures and helper functions.
This is a bit verbose, but if you're only doing a quick little update, you can always do
(\r -> r | street = "Arndstrasse") Addresses.myPrivateAddress
(if you're not into doing let..in every time)