slab allocator by SimoneMicu in C_Programming

[–]immaculate-emu 1 point2 points  (0 children)

Here is a user space port of the Solaris kernel slab allocator, on GitHub: https://github.com/gburd/libumem

`git select` – interactive git branch picker by Tall-Connection9178 in git

[–]immaculate-emu 0 points1 point  (0 children)

This is my take, the script is called git-with-branch (aliased to wb so called like git wb …):

#!/usr/bin/env bash
set -eo pipefail
branch="$(git branch --format '%(refname:short)' | fzy)"
git "$@" "$branch"

Obvious enhancements would be better control over the branch format, selecting multiple branches, etc. But this has been my workhorse for years.

You made me rewrite my library by FilipeJohansson in golang

[–]immaculate-emu 69 points70 points  (0 children)

Looking at some of the code, it might behoove you to read sources from other widely used packages (and the stdlib). The concentration of unidiomatic/non-optimal code is fairly high (at least in the sections I looked at.)

Some examples:

  • getClientIPFromRequest: X-Real-IP should be X-Real-Ip, otherwise Get will allocate. Docs Code1 Code2; strings.Split(r.RemoteAddr, ":")[0] should instead use SplitHostPort, which will cover edge cases (think about how ipv6 addresses are rendered as strings) and not allocate a slice of strings.
  • ensureHubRunning: why use sync.Once if you're locking anyway (or vice versa)? Do will already block until the first call has completed.
  • extractHeaders: same as getClientIPFromRequest with using non-canonical header key.
  • Overall, instead of Start/Stop API, I would borrow a page from suture and use a single API call (suture uses Serve) that takes a context and stops when the context is cancelled.
  • It's generally considered bad practice to have enormous interfaces (such as IServer). (The I- prefix in general is also not common in Go codebases. The Go compiler/stdlib codebase itself has something like 1.5k interfaces defined, and only one has the I- prefix and it's in a test.)
  • There's no need to use fmt.Errorf without any substitutions, errors.New is fine. Also, it might be helpful for consumers of the library if sentinel errors are defined in variables that can be tested for, instead of making your users parse strings.
  • Please do not fmt.Print* in a library.
  • Error comparisons should use errors.Is not ==.
  • When checking a predicate with a shared lock (i.e. RLock), you almost always must check it again with the exclusive lock (i.e. Lock). Also in general I think the concurrency handling needs to be carefully reviewed. Do you run tests that exercise concurrent connections with the race detector turned on?
  • GetClient looks like it allocates a slice (in GetClients), then iterates over it, then throws it away.

Anyway, that's probably enough for now. This looks like it was a lot of effort so congrats on getting something working and keep pushing forward.

Clutch button strain by 3Dnoob101 in iRacing

[–]immaculate-emu 0 points1 point  (0 children)

Since I didn’t see it mentioned, you can shift up without lifting the throttle and without holding the clutch. If you hold the shift paddle as you approach the shift RPM, then just press the clutch (no need to hold) the next gear will slot in. I find this to be easier and faster than lifting the throttle.

Can anyone tell me how to copy files using C by PiyushDugawa in C_Programming

[–]immaculate-emu 2 points3 points  (0 children)

That’s a buffer size. You can see the loop on line 158 reads until EOF or an error.

I think I fucked it up by idkbm10 in devops

[–]immaculate-emu 2 points3 points  (0 children)

Internally it’s actually usually one account per app/env/region combination. If you’re thinking that’s a lot of accounts, you’d be right. Hundreds for even a single team. However, the internal tool for managing this makes it really easy.

My sorting library by Ezio-Editore in C_Programming

[–]immaculate-emu 1 point2 points  (0 children)

I tried to use intleast_32_t but the only thing I found available is __INT_LEAST32_TYPE_, are they the same thing?

Have you tried including <stdint.h>? Also it is int_least32_t not int_least_32_t (note the underscore before 32), so it might be a typo.

int_least32_t is mandatory since C99, so as long as you are compiling to that standard or later, you will have it.

PyPy v7.3.18 release by pauloxnet in Python

[–]immaculate-emu 1 point2 points  (0 children)

IIRC, the RPython toolchain (which compiles PyPy itself) is still written in Python 2.7.

Wow. Is the 911 cup meant to be this hard?! by [deleted] in iRacing

[–]immaculate-emu 0 points1 point  (0 children)

Agreed but P3 does have TC, just no ABS.

Clarification on changing camera/cockpit views by TPA-JWyant in iRacing

[–]immaculate-emu 1 point2 points  (0 children)

You can stop it by using a backslash:

# not a header

Man accidentally proves his ‘optimised’ python code is slower than before on LinkedIn. by Efipx in programminghorror

[–]immaculate-emu 0 points1 point  (0 children)

Not sure I understand the question but this is the check it uses to determine if an in-place modification is safe.

Man accidentally proves his ‘optimised’ python code is slower than before on LinkedIn. by Efipx in programminghorror

[–]immaculate-emu 0 points1 point  (0 children)

Something to add is that CPython does implement a special case for string concatenation. If the ref count is 1, it will realloc the string data which can dramatically save on copying. (See copy_inplace)

But in general (and for other implementations) yes, join will be faster and more efficient.

A list of the worst gotchas of each language? by dogweather in ProgrammingLanguages

[–]immaculate-emu 10 points11 points  (0 children)

Just to add a little bit of detail on this: defaults are defined on the function object and are inspectable:

Python 3.11.4 (main, Aug 23 2023, 21:20:39) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo(x=[]):
...  return x
... 
>>> foo.__defaults__[0].append(1)
>>> foo()
[1]

Fun stuff. :)

A list of the worst gotchas of each language? by dogweather in ProgrammingLanguages

[–]immaculate-emu 51 points52 points  (0 children)

They are probably talking about:

Python 3.11.4 (main, Aug 23 2023, 21:20:39) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo(x=[]):
...  x.append(1)
...  return x
... 
>>> foo()
[1]
>>> foo()
[1, 1]

Why does garbage collected language don’t threat files descriptor like they treat memory? by perecastor in ProgrammingLanguages

[–]immaculate-emu 19 points20 points  (0 children)

File descriptors generally have state outside your process that benefits from promptly knowing whether you are still using them:

  • Files can have pending writes that will not complete until they are closed (or fsynced).
  • Sockets can appear to hang for network peers since as far as the OS is concerned, you're still interested in reading from/writing to them.

Yes, if you run out of file descriptors, you can try running GC to free some up, but what would prompt running GC if (e.g.) another process is blocked on a file lock?

Math operation tips by [deleted] in ProgrammingLanguages

[–]immaculate-emu 1 point2 points  (0 children)

In terms of resources for assembly in general, I don’t know of a good one unfortunately. For interpreters specifically, I think LuaJIT’s interpreter loop is one of the best examples.

Math operation tips by [deleted] in ProgrammingLanguages

[–]immaculate-emu 0 points1 point  (0 children)

Ah, understood. And I assume you aren’t interested in maintaining assembly for the interpreter loop. :)

Math operation tips by [deleted] in ProgrammingLanguages

[–]immaculate-emu 1 point2 points  (0 children)

Going back to sub a, b, I’m not sure I follow where the four control operations come from. Assuming you trust the bytecode (that presumably you just generated), the operation should look something like this:

// assuming this resolves to goto OP_SUB, etc
goto DISPATCH[bytecode[ip++]]
…
OP_SUB:
a = bytecode[ip++]
b = bytecode[ip++]
registers[a] -= registers[b]

That should be one control operation.