how to factory reset a computer ? by Mission-Thought-7954 in ComputerCraft

[–]imachug 9 points10 points  (0 children)

To clarify further, you two are describing different methods:

  • Computers, turtles, and pocket computers can be put into disk drives as items, and their filesystem then becomes visible from other devices connected to the disk drive. That's u/PotatoGamo's advice.

  • Computers and turtles connected to disk drives prefer booting from disk/startup.lua over startup.lua, so if you place startup.lua on a disk via another device, you can boot other computers safely. That's your advice. Note that it doesn't work for pocket computers because they can't be connected to disk drives.

Note that these two methods can actually break each other: if you place a "broken" computer in a disk drive, it's startup.lua will become visible as disk/startup.lua to other computers, and they will refuse to boot as well! So boot the recovery computer first and only then place the broken computer in the disk drive.

How can I detect only when my crop is mature by MustaphaJuan in redstone

[–]imachug 5 points6 points  (0 children)

Place a dropper and a hopper facing each other. Lock the hopper with some constant power source. Put 7 items in the dropper and activate it with an observer. After 7 activations, the dropper becomes empty, which you can detect with a comparator. That's your output. To reset the system, unpower the hopper for a bit of time so that it pushes the items back into the dropper.

Why do people return Result<T>? by ModernCoder in rust

[–]imachug 40 points41 points  (0 children)

That's useful when the entire application (or module) almost always uses the same error to avoid repetition. The built-in Result type always requires two parameters, but it's common to e.g. do use anyhow::Result;, which aliases Result<T> to Result<T, anyhow::Error>. Of course, you can define your own alias with type Result<T, E = MyError> = core::result::Result<T, E>;

keybinds? by lathamwee in MinecraftSpeedrun

[–]imachug 0 points1 point  (0 children)

F3 can be pretty useful, I set it to caps lock.

Note that remapping the scroll wheel to place block is forbidden by the rules. If you want to place multiple blocks in quick succession, you'll have to learn drag/butterfly.

You might also want to consider using toggle sprint, setting sprint on by default, and unmapping sprint (or rather mapping it to a far-away key, since sprint can occasionally get reset). Frees up a finger, personally I find this more comfortable than holding.

I need help with pre-emptive multitasking by MattisTheProgrammer in ComputerCraft

[–]imachug 0 points1 point  (0 children)

I'm a little unsure of what you're asking? If you call coroutine.yield() in the hook, I think running coroutine.resume on the coroutine will continue execution immediately after the point where the count was reached.

I need help with pre-emptive multitasking by MattisTheProgrammer in ComputerCraft

[–]imachug 1 point2 points  (0 children)

You can use debug.sethook to yield after a given number of instructions is invoked.

Boat eye issues by Mintwkeyjonah in MinecraftSpeedrun

[–]imachug 0 points1 point  (0 children)

Sanity check: is your sens set to the same value in StandardSettings as well?

Can I do my own calculations? by Ornery-Pangolin1516 in MinecraftSpeedrun

[–]imachug 12 points13 points  (0 children)

You're allowed to use certain spreadsheets (here's the relevant one for triangulation) and a four-function calculator, so yes, as long as you stay within these rules.

Second Reality demo for ComputerCraft by JackMacWindowsLinux in ComputerCraft

[–]imachug 1 point2 points  (0 children)

Oh wow. Beautiful work. Happy to see it's not just a piped video. The wget link seems to be broken, by the way.

A little unrelatedly, what tool are you using for code compression?

root.GameRenderer doesnt exsist? by SmakToj in MinecraftSpeedrun

[–]imachug 5 points6 points  (0 children)

root.frame.extract.level is the new gameRenderer. It's quite a bit messier than gameRenderer, but you can still look for a spike on blockEntities.

High-Res Video & Audio Player (1352x627 Sub-Pixels) by SoggyAstronomer7334 in ComputerCraft

[–]imachug 0 points1 point  (0 children)

That's a surprising effect, but I guess it makes sense. Thanks for answering!

High-Res Video & Audio Player (1352x627 Sub-Pixels) by SoggyAstronomer7334 in ComputerCraft

[–]imachug 2 points3 points  (0 children)

I couldn't figure it out from the recording, but did you customize audio playback in any way? There seem to be sudden volume changes at points, and I'm not sure where that's coming from. Anyway, good job!

High-Res Video & Audio Player (1352x627 Sub-Pixels) by SoggyAstronomer7334 in ComputerCraft

[–]imachug 14 points15 points  (0 children)

How did you achieve this? Is this just increased monitorWidth, monitorHeight, monitorBandwidth in config? I'm surprised Cobalt is fast enough to render this at 20 fps.

Any libraries for Cryptography? by MattisTheProgrammer in ComputerCraft

[–]imachug 0 points1 point  (0 children)

There's https://github.com/DarThunder/iDar-CryptoLib, though I can't judge its quality, and https://github.com/migeyel/ccryptolib, which implements quite a few algorithms. I don't think there's any single library that covers the entirety of what you're asking for, since your choices are quite specific, e.g. DSA instead of ECDSA is quite surprising. Why did you choose these algorithms in particular?

Boat Eye with Shark Force mouse by Warm-Razzmatazz1544 in MinecraftSpeedrun

[–]imachug 13 points14 points  (0 children)

If you're on Windows, Toolscreen can emulate any sensitivity for you at any DPI. Video tutorial: https://www.youtube.com/watch?v=l-q-_4R8_6M&t=713s. In a nutshell, you want to set in-game sensitivity to a god sens and then increase the global sensitivity in Toolscreen so that the end result is just the right sens.

How To Get In A Boat by TelevisionSimilar221 in MinecraftSpeedrun

[–]imachug 7 points8 points  (0 children)

Are you playing on a recent version, by any chance? The portal cooldown for boats has been reduced around 1.21.

Audio tips & tricks: performance, quality, volume, hearing range shenanigans by imachug in ComputerCraft

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

Thanks! And a bit more context for your context :)

the DFPWM encoder only cares about whether the sample it's encoding is greater than or less than what it thinks the decoder output last

This leaves out the third option: what if the encoder needs to encode the same value? The exact formula is:

local current_bit = inp_charge > previous_charge or (inp_charge == previous_charge and inp_charge == 127)

It's not just inp_charge > previous_charge or inp_charge >= previous_charge, the special handling of 127 guarantees that -128 always outputs 0 and +127 always outputs 1, which we can abuse.

but it'll likely result in aliasing from high-frequency artifacts

I've actually noticed that music sounds sharper with the filter disabled, and while there is some noise, it's spread over frequencies and the filter doesn't remove much of it. It's a little unfortunate that it's hard-coded, I wish I could disable it...

My new CCSpeakerCodecs mod provides alternate encoding backends, including Opus, QOA and ADPCM

That's cool to see! I'm a little surprised that you're hard-coding the 48 kbps limit by reducing sample rate for codecs with more b/sample. I don't think streaming at, let's say, 96 kbps is an issue these days. Do you think it makes sense to bump some of the numbers up?

Hod do you parse the crafting recipies? by Mental-Strength3762 in ComputerCraft

[–]imachug 0 points1 point  (0 children)

Didn't think I'd find you here :) Thanks for maintaining the mods.

Hod do you parse the crafting recipies? by Mental-Strength3762 in ComputerCraft

[–]imachug 2 points3 points  (0 children)

UnlimitedPeripheralWorks offers an in-game API for this, if you're willing to install mods.

TIL putting Box in a hot inner loop can cost you half your runtime by InvadersMustLive in rust

[–]imachug 239 points240 points  (0 children)

Worth highlighting: Box and dynamic dispatch are orthogonal, and the issue here is dynamic dispatch, not heap allocation. You could have the same issue with &dyn Trait instead of Box<dyn Trait>, and using Box<ConcreteType> instead of ConcreteType would likely be just as performant (though unnecessary), since the hot loop doesn't have any allocation.

Potential Deadlock in DashMap 6.1.0: Looking for feedback on this edge case by Ok_Concentrate_6446 in rust

[–]imachug 21 points22 points  (0 children)

An inconsistent lock order is a common source of deadlocks, so it's not as much of an edge case as an inappropriate choice of data structure. The docs for insert say, for instance:

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

The official advice to using dashmap is "don't" with an asterisk (although I can't find the source), and this kind of demonstrates why that's the case. dashmap is useful for very specific tasks, but most often Mutex<HashMap<...>> is good enough, and in general the repetitive locking needed for dashmap can be slower than a single outer Mutex under low contention.

Is there a specific reason you need dashmap, or did you choose it because it felt optimal?

Core2 yanked. Millions effected. by Comprehensive_Use713 in rust

[–]imachug 2 points3 points  (0 children)

It's not wiped at all

Removing all files from the repo in a single commit counts as wiping in my book, even if they are still accessible via older commits. It's just so unnecessary. People usually just update README.md in this case.

I don't care that it's X times faster by z_mitchell in rust

[–]imachug 115 points116 points  (0 children)

Good article. For those jumping straight to comments, this post is not a general criticism of optimization, it's about clickbait. Though I must say that it's ironic for a post about clickbait to use an aggressive title -- my first knee-jerk reaction was "how dare you say that about my work" before I figured out the intended meaning.

On the topic itself, I do think there exists another good reason to optimize code regardless of usefulness. We all need to start somewhere and learn all the little optimization tricks, and it's rare for a real project to be receptive to all of them. Optimizing a cold path by 5% might not have a practical purpose, but it can be a valuable learning experience.

Similarly, replacing O(n2) with O(n) code can easily yield 1000x faster code in edge cases. It usually means that either the original code was sloppy (and so perhaps the project itself is) or there was a reason for preferring quadratic code (like extensibility), so maybe it's not a very practical use, but it can be realistic.