I’m learning to use GitHub Copilot. So far so good. Today I read:
Category Archives: Programming
New website: Take Two
Hey Craig. I’ve made some changes (hopefully improvements!) to the website:
Only the home page is working at the moment. I will get the other pages working soon, hopefully today.
Please do let me know (in no uncertain terms!) what you think of the new design. I’ve gone “mobile first”, so it should look respectable on your smart phone.
Context object versus global variables
I’m reading A Philosophy of Software Design by John Ousterhout and he says:
The context object unifies the handling of all system-global information and eliminates the need for pass-through variables. If a new variable needs to be added, it can be added to the context object; no existing code is affected except for the constructor and destructor for the context. The context makes it easy to identify and manage the global state of the system, since it is all stored in one place. The context is also convenient for testing: test code can change the global configuration of the application by modifying fields in the context. It would be much more difficult to implement such changes if the system used pass-through variables.
Contexts are far from an ideal solution. The variables stored in a context have most of the disadvantages of global variables; for example, it may not be obvious why a particular variable is present, or where it is used. Without discipline, a context can turn into a huge grab-bag of data that creates nonobvious dependencies throughout the system. Contexts may also create thread-safety issues; the best way to avoid problems is for variables in a context to be immutable. Unfortunately, I haven’t found a better solution than contexts.
Okay, so I’m just gonna step way out of line over here and suggest something heretical… but shouldn’t you just use global variables? You only introduced the context object so you could tweak it in unit tests, and you could just change your tests so that each one ran in a new process. Just sayin’.
…I suppose for the sake of completeness I should add a little more from Ousterhout which he said prior to the above:
Another approach is to store the information in a global variable, as in Figure 7.2(c). This avoids the need to pass the information from method to method, but global variables almost always create other problems. For example, global variables make it impossible to create two independent instances of the same system in the same process, since accesses to the global variables will conflict. It may seem unlikely that you would need multiple instances in production, but they are often useful in testing.
…so he is bending over backward to support multiple tests in one process, but he could just run each test in its own process and his problem evaporates.
lol, ChatGPT rickrolled me
Transferring large files with Salt file.managed
Well, this took me a few hours to figure out.
If you’re going to be transferring large files using file.managed in your salt state, make sure you specify show_changes: False, otherwise salt will start trying to boil the ocean and calculate the unified diff of your enormous files.
The clue that this is the problem you're having is if one of your CPU cores pegs at 100% and your state doesn't apply in a reasonable amount of time (minutes, I guess).
Also you probably want to make sure you're not trying to use your large file as any sort of template. By default file.managed will assume no template, which is what you want for large files that aren't templates. I've never used large files which are templates, but I suspect if you tried that you'd have a bad time.
Final round of Silicon Chip books
My good friend Dubz shouted me another round of Silicon Chip books as can be seen here. I now own all the books which have been marked and I’ve pretty much purchased everything that was left.
Humble Bundles
There are a couple of decent looking ebook bundles available via Humble Bundle at the moment:
Lisp irony
I’m reading Software Design for Flexibility: How to Avoid Programming Yourself into a Corner which in its Appendix B has a description of the Scheme programming language. Rather hilariously the first line on page 394 is a sentence with unbalanced parentheses. I mean… unbalanced parentheses in the Scheme language description! :)
ChatGPT on dd block size
I was pretty impressed by this:
ChatGPT 3.5
User:
if you’re going to use dd to write random data over a hard drive device what block size is best?ChatGPT:
When using the dd command to write random data over a hard drive device, the choice of block size can impact the performance of the operation. The optimal block size can vary depending on the specific circumstances, but there are some general guidelines you can follow.A common recommendation is to use a block size that is a multiple of 4 KB (4096 bytes), which is often the physical sector size of modern hard drives. This alignment can improve performance because it matches the underlying hardware.
Here’s an example of using dd with a block size of 4 KB:
$ dd if=/dev/urandom of=/dev/sdX bs=4K
Replace /dev/sdX with the actual device name you want to overwrite, and adjust the block size (bs) according to your needs.
However, keep in mind that there is no one-size-fits-all answer, and performance may vary depending on your specific hardware and use case. You might want to experiment with different block sizes to see what works best for your situation.
Additionally, when overwriting a hard drive for security reasons (e.g., before decommissioning or selling it), consider using tools specifically designed for secure erasure, such as shred or wipe. These tools often implement more sophisticated algorithms to ensure data is thoroughly and securely overwritten.
vDSO (virtual dynamic shared object)
Today I learned about the vDSO on the Linux man page: vdso(7) — Linux manual page. It’s a facility for replacing syscalls with normal user-space function calls for things like getting the time of day for better performance.
