Readit News logoReadit News
pksadiq commented on CLI tool to insert spacers when command output stops   github.com/samwho/spacer... · Posted by u/freetonik
zmw · a year ago
Related shameless plug: I have a small tool that prepends each output line with a timestamp (can be absolute, relative, or elapsed since last line), might be useful or pair well with this tool in similar scenarios (not needed when dealing with already timestamped logs, of course).

https://github.com/zmwangx/ets

pksadiq · a year ago
I wrote a similar tool[0] a few days back because I wanted a bit more accuracy with timestamp (to measure CPU/idle time) and `ts` occasionally had a deviation of several 10ms. If I knew this, and is accurate enough for me, I might not have written one.

[0] https://www.sadiqpk.org/projects/tis

Deleted Comment

pksadiq commented on Wikipedia switches to CC BY-SA 4.0 license   diff.wikimedia.org/2023/0... · Posted by u/skilled
RicoElectrico · 3 years ago
Why every goddamn thing has to be exciting? Surely American organizational culture is becoming a parody of itself. If anything, this reminds us that American non-profits are run just like corporations.
pksadiq · 3 years ago
This specific change shall excite many as CC BY-SA 4.0 is one way GPLv3 compatible, but CC BY-SA 3.0 is not. Which means that free software developers can now embedded many Wikimedia contents in their GPLv3 applications. This seems not mentioned in the blog post though.

Deleted Comment

pksadiq commented on Fast midpoint between two integers without overflow   lemire.me/blog/2022/12/06... · Posted by u/ibobev
slymon99 · 3 years ago
Isn't (32 bit) INT_MAX 2^31-1 and INT_MIN -2^31, so this is an acceptable solution (since the decimal average is -0.5)?
pksadiq · 3 years ago
> since the decimal average is -0.5

The C standard says: When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded (This is often called ‘‘truncation toward zero’’).

So it should be 0 (as per C standard, not sure what C++ standard says)

pksadiq commented on Fast midpoint between two integers without overflow   lemire.me/blog/2022/12/06... · Posted by u/ibobev
naasking · 3 years ago
> Then the majority come up with (a / 2) + (b / 2) until they run the unit tests and realize it's wrong.

Seems like you can cover the corner case easily enough:

    x/2 + y/2 + (x & y & 0x01)
A few more operations than the article though so not the most efficient solution.

pksadiq · 3 years ago
> x/2 + y/2 + (x & y & 0x01)

This returns -1 for x = INT_MIN and y = INT_MAX were the answer should be 0 (for an example). so not a correct solution

pksadiq commented on Fast midpoint between two integers without overflow   lemire.me/blog/2022/12/06... · Posted by u/ibobev
pksadiq · 3 years ago

  int mid(int x, int y) {
    return (x/2 + y/2) + (1 & x & y);
  }
would be a more readable solution

edit: Actually, this fails on mid(INT_MIN, INT_MAX) and possibly other mixed sign values (returns: -1, expected: 0 (or -1 is okay?), where the precise answer is -0.5)

more edit: The C standard says: When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded (This is often called ‘‘truncation toward zero’’).

So -1/2 should be 0.

u/pksadiq

KarmaCake day509October 27, 2015
About
https://www.sadiqpk.org
View Original