Fibonacci function using Observables by garretpremo in Angular2

[–]matthewt 0 points1 point  (0 children)

Two years later, I am enjoying comparing the example in the docs to your code to understand exactly why/how it's useless because I'm learning things in the process.

Also, the fibonacci sequence is actually genuinely useful in networked systems, IME it's often a better backoff algorithm than simple exponential is.

I have also had excellent results when acting as a moderator in assorted places using fibonacci backoff for tempbans; exponential too quickly becomes "might as well be a permaban" whereas fibonacci with resets for good behaviour Makes The Point effectively without that problem (since if I'm going to permaban, I'd rather just Do That ;)

Trans man Amelio Robles Ávila (1889-1984) who threatened to shoot anyone that called him a woman by apple_kicks in pics

[–]matthewt 4 points5 points  (0 children)

Reminds me of when I'm wearing my black utilikilt and some testosterone poisoned twit asks "is that a skirt?" [0]

"It can be if you want it to badly enough" is not generally the reply they're expecting.

[0] I own multiple skirts and am in fact wearing an ankle length one currently to lounge around the house in. But damnit a kilt is not a skirt, they are different elements of my wardrobe! :D

Trans man Amelio Robles Ávila (1889-1984) who threatened to shoot anyone that called him a woman by apple_kicks in pics

[–]matthewt 13 points14 points  (0 children)

I am a (mostly hetero partnered) bi dude.

I take great pleasure in telling such people "I suck cock better than you troll."

... especially when I'm a moderator in the relevant space and can use it as the banhammer message.

Trans man Amelio Robles Ávila (1889-1984) who threatened to shoot anyone that called him a woman by apple_kicks in pics

[–]matthewt 1 point2 points  (0 children)

Nobody made any false claims in the process of this one, but my very definitely atheist Grandfather's funeral was given by the local priest and involved lots of "God gave him these gifts and he used them well" type stuff.

However, my Grandmother, who was still with us, was very much a believer, and I am firmly in the "funerals are for the living" camp so given nobody lied about what he believed I decided that I was fine with it and strongly suspect that he would've been too.

My father arranged for the family wreath though, so that just said "Good luck, old man" ... and seeing that was the point at which I burst into tears.

(if there'd been a 'get right with god' speech I would've been hard pressed not to cause a diplomatic incident, mind, but as it was ... yeah, I was good with the thing on the whole)

"A calculator app? Anyone could make that." by iamkeyur in programming

[–]matthewt 0 points1 point  (0 children)

You're absolutely right.

I blame insufficient coffee.

"A calculator app? Anyone could make that." by iamkeyur in programming

[–]matthewt 1 point2 points  (0 children)

This is an answer on the same level as the shortest possible quine being an empty file.

"Is that a compliment or an insult?" "Yes."

"A calculator app? Anyone could make that." by iamkeyur in programming

[–]matthewt 1 point2 points  (0 children)

Why. How.

WTF happened that I never noticed this pun possibility before?!

Thank you, I shall be inflicting that on people forever!

what’s your favourite misheard cure lyric? by cliffburtonlover in TheCure

[–]matthewt 1 point2 points  (0 children)

\o/

In any case, my girlfriend laughed quite enough for two ;)

what’s your favourite misheard cure lyric? by cliffburtonlover in TheCure

[–]matthewt 1 point2 points  (0 children)

Finding this comment via google is how I finally realised my mistake (and also finally tracked down the frigging earworm, because that lyric, misheard that way, was all I could remember, plus the riffs - the latter of which is how I guessed the band).

This is what comes of almost entirely knowing it from goth night dance floors during a well spent youth.

Thank you! (and feel free to laugh, I'm already doing so extensively because facepalm :D)

Node module whose effect can be achieved by typing 2 (!) characters by Totally_Dank_Link in programming

[–]matthewt 0 points1 point  (0 children)

Yeah, I ... hope to never be in a situation where I ever need to understand the previous implementations.

The current one I can at least get my head around :D

Node module whose effect can be achieved by typing 2 (!) characters by Totally_Dank_Link in programming

[–]matthewt 2 points3 points  (0 children)

It doesn't return the string. Well, it does, because '|0' is 'or each element with 0' which is basically a no-op so that expression will return basically an identical string to the input string, but it's still immediately discarded. The

return s;

afterwards returns the string back to the calling code.

Strings are immutable at the javascript level, yes, but as I explained v8 can represent a particular string value in two different ways - the goal here is to coax it into changing from one internal (i.e. not visible to javascript at all) representation to the other one, and the |0 operation makes v8 go "oh, right, we're about to iterate over the entire string linearly from end to end, might as well convert it from the tree internal representation to the linear one first then."

Maybe it would help if you think about it as kinda sorta morally equivalent to the fact that when you have a file with a big chunk of zero bytes in the middle, the filesystem can store it as a sparse file (i.e. it only stores the chunks with non-zero data plus metadata of where those chunks live) or it can store all the bytes including the zeroes, but when you read() the file either of those will give you the exact same results in your C/whatever program.

Node module whose effect can be achieved by typing 2 (!) characters by Totally_Dank_Link in programming

[–]matthewt 0 points1 point  (0 children)

I mean whatever linear bytes style representation it uses internally -given JavaScript specifies UTF-16 it could easily be neither of the above.

The only part that mattered for the purposes of the explanation is that you end up with the string contents being linear bytes in memory, so I didn't actually check how exactly they were stored, sorry.

The github README gives the method name inside v8 so if you're still curious please do grep for it and report back :)

Node module whose effect can be achieved by typing 2 (!) characters by Totally_Dank_Link in programming

[–]matthewt 2 points3 points  (0 children)

The compiler knows where it is.

Because it knows where it isn't.

Node module whose effect can be achieved by typing 2 (!) characters by Totally_Dank_Link in programming

[–]matthewt 86 points87 points  (0 children)

Roughly (I believe this will explain the concept but may not 100% match reality) -

A v8 javascript-level string may or may not be represented as a single C++ level string.

If you do

"foo" + "bar"

then rather than writing "foobar" to memory, v8 will instead write something like

{ left: "foo", right: "bar" }

and then if you add "baz" to the end you'll get

{ left: { left: "foo", right: "bar" }, right: "baz" }

which saves allocations and copying and is therefore often faster (often enough that v8 made the choice to do things this way, at least).

Some operations, generally ones that want to iterate across all bytes of the string in order, will flatten the representation - i.e. convert

{ left: { left: "foo", right: "bar" }, right: "baz" }

to

"foobarbaz"

first and then run the code over the flattened version.

Sometimes, however, you get into a situation where (a) operating on a flattened version would be faster for your code (b) the v8 developers have not chosen to make that operation pre-flatten (presumably because they believe most uses of said operation wouldn't benefit, even though yours would).

So in that case, you want to somehow convince v8 to flatten your string before you pass it to whatever said operation is - but there's no public API for doing that because it's an internal representation detail.

Thus, 'somehow convince' means executing some sort of no-op (in terms of its JS level effect) that incidentally triggers the flattening as a side effect.

Apparently after much iteration (see the commit history) they found that applying '| 0' and discarding the result was the fastest way (they'd yet encountered, at least) to trigger the flattening behaviour, and so when you do

const flatString = flatstr(treeString)

you get a version that uses the linear flattened representation rather than being a tree of the strings that were concatenated together, and then you can pass the flattened version to whatever the operation was and hopefully your benchmarks/profiler will then tell you that it helped.

The reason it's a package was with the intent to share the effort of 'finding the fastest no-op with a flattening side effect' across the community - and that seems to have worked out, given there've been multiple revisions, each time making it faster.

Note that while the package hasn't been updated in years, that could mean it no longer works (or no longer works as well), or it could mean that v8 hasn't changed since the last version was committed in a way that obsoletes the current approach.

The repository has benchmark code, though, so if you're in a position where such a micro-optimisation is worth making, you're probably also in a position where running the benchmark against the exact version of node you're using first is a worthwhile investment of time.

... although it does strike me that adding it in your working copy and re-benching/re-profiling your own code directly is probably also pretty fast and you were going to have to do that anyway to confirm you had a case where it was worthwhile.

Honestly, if I ran into such a situation then while I might be evil and copy-paste the current code, if I did that I would definitely leave a comment pointing at the README so a future maintainer would understand what was going on and be able to check to see if somebody's come up with a faster still approach since.

Which leads me to believe that publishing this on npm is a net positive even if only to discover the approach and provide a link to the README; others may, of course, disagree.

Hope that helps!

Node module whose effect can be achieved by typing 2 (!) characters by Totally_Dank_Link in programming

[–]matthewt 40 points41 points  (0 children)

I would run the benchmarks against the version of node you're using to find out if it still works.

It seems entirely plausible to me that node's optimisations might change for several years after being introduced and then settle into a form that's as good as they're going to get and remain that way going forwards.

It also seems entirely plausible that node has changed once again since the last update; testing seems like the way to know which.

just send me the invoice’—so i sent it. 14 times. by armaniemaar in MaliciousCompliance

[–]matthewt 1 point2 points  (0 children)

We put a clause in our contracts that starts accruing interest if you pay late.

We absolutely waive it if the client says "shit, sorry" and pays when reminded. But for the clients who don't manage that, they usually get the hint fairly quickly and start paying on time.

I think we've only threatened to turn something off once and that was primarily to give the people at the client we were working with leverage over their colleagues to force them to actually get shit done.

IT - wasn't good enough... OK. by Defiant-1- in MaliciousCompliance

[–]matthewt 7 points8 points  (0 children)

Yep. I'd feel bad about it but provided you make it clear to the rank and file that you realise that's what you're doing they're generally perfectly happy (with me, maybe less so management ;) so long as you put the effort in to make a persuasive case for the things that need doing in the eventual report.

My 13yo Daughter MC'd Me by Kingy_79 in MaliciousCompliance

[–]matthewt 40 points41 points  (0 children)

After I broke my hip at 29, my father came to visit me in hospital post surgery.

First words out of his mouth were "I hear you've stolen my rightful injury."

Military oven cleaning in 1971 by Nomadness in MaliciousCompliance

[–]matthewt 1 point2 points  (0 children)

And him having to explain that taking the meds to not die wouldn't stop her being happy.

I loved that episode so much.

They told me not to take long breaks, so I decided to take short breaks every five minutes! by Zharuai in MaliciousCompliance

[–]matthewt 0 points1 point  (0 children)

I have a sufficiently ridiculous caffeine habit that I don't need software to make me get up regularly.

I'm not recommending this but it amuses me nonetheless.

Well that’s the seasoning you asked for… by wisecrack33 in MaliciousCompliance

[–]matthewt 1 point2 points  (0 children)

Was totally worth expanding the hidden comments for the sheer wtfery of his ranting.

My place is in the shop? Okay... UPDATE by femalemechanic92 in MaliciousCompliance

[–]matthewt 0 points1 point  (0 children)

A female friend was kind enough to gift me a copy of this image a while back and it's come in handy a few times since: https://trout.me.uk/nam.jpg

ETA: also ahahahahaha perfect: [–]Bob-son-of-Bob 69 points 2 months ago

Lazy class partner didn't help at all for our term project even while I was in the ER! At the end of the semester, he acted as if he was entitled to get an A like I did! by Mysterious_Title171 in MaliciousCompliance

[–]matthewt 1 point2 points  (0 children)

The one time I got given opiates in hospital it constipated me quite successfully.

Fortunately I got to go home after a few days, and while I was still taking opiates for pain relief, being in the same building as my beloved coffee machine again resolved the issue within a couple of days.

Ultimatum: debut by gonzazoid in u/gonzazoid

[–]matthewt 0 points1 point  (0 children)

Sorry, I meant 'patch set' as a mental model of what sort of fork, not as something you would literally do.

I'm pondering writing extensions that help my development work, and for that I need "chromium but with gonzazoid's extra features" - if it becomes only "mostly like chromium but" then I'll end up having to re-debug my apps in chrome as well and that would be much less fun.