Is Your Mental Model Of Bash Pipelines Wrong?

[Michael Lynch] encountered a strange situation. Why was compiling then running his program nearly 10x faster than just running the program by itself? [Michael] ran into this issue while benchmarking a programming project, pared it down to its essentials for repeatability and analysis, and discovered it highlighted an incorrect mental model of how bash pipelines worked.

Here’s the situation. The first thing [Michael]’s pared-down program does is start a timer. Then it simply reads and counts some bytes from stdin, then prints out how long it took for that to happen. When running the test program in the following way, it takes about 13 microseconds.

$ echo '00010203040506070809' | xxd -r -p | zig build run -Doptimize=ReleaseFast
bytes: 10
execution time: 13.549µs

When running the (already-compiled) program directly, execution time swells to 162 microseconds.

$ echo '00010203040506070809' | xxd -r -p | ./zig-out/bin/count-bytes
bytes: 10
execution time: 162.195µs

Again, the only difference between zig build run and ./zig-out/bin/count-bytes is that the first compiles the code, then immediately runs it. The second simply runs the compiled program. Continue reading “Is Your Mental Model Of Bash Pipelines Wrong?”

User Beware: The Fine Line Between Content And Code

Everyone loves themes. Doesn’t matter if it’s a text editor or a smart display in the kitchen, we want to be able to easily customize its look and feel to our liking. When setting up a new device or piece of software, playing around with the available themes may be one of the first things you do without giving it much thought. After all, it’s not like picking the wrong one is going to do something crazy like silently delete all the files on your computer, right?

Unfortunately, that’s exactly what happened a few days ago to [JeansenVaars] while trying out a Plasma Global Theme from the KDE Store. According to their Reddit post, shortly after installing the “Gray Layout” theme for the popular Linux graphical environment, the system started behaving oddly and then prompted for a root password. Realizing something didn’t seem right they declined, but at that point, it was already too late for all of the personal files in their home directory.

Continue reading “User Beware: The Fine Line Between Content And Code”

Video Poker Takes Your Money In 10 Lines Of BASIC

It wasn’t easy, but [D. Scott Williamson] succeeded in implementing Jacks or Better Video Poker in 10 lines of BASIC, complete with flashing light and sound! Each round, one places a bet then plays a hand of 5-card draw, hoping to end up with Jacks or better.

This program is [Scott]’s entry into the 2024 BASIC 10 Liner Contest, which at this writing has concluded submissions and expects to announce results on April 6th 2024. Contestants may choose any 8-bit computer system BASIC, and must implement their program within ten lines of code (classically limited to 80 characters per line, but there are different categories with different constraints on line width.)

10 lines of BASIC is truly an exercise in information density.

We’ve seen impressive 10-line BASIC programs before, like this re-implementation of the E.T. video game. (Fun fact: while considered one of the worst video games of all time, there’s a compelling case to be made that while it was a flop, it was ahead of its time and mostly just misunderstood.)

These programs don’t look much like the typical BASIC programs many of us remember. They are exercises in information density, where every character counts. So we’re delighted to see [Scott] also provides a version of his code formatted and commented for better readability, and a logical overview that steps through each line.

He spends a little time talking about the various challenges, as well. For example, hand ranking required a clever solution. IF…THEN conditionals would rapidly consume the limited lines of code, so hands are ranked programmatically. The 52-card deck is also simulated, rather than simply generating random cards on the fly.

The result looks great, and you can watch it in action in the video, just under the page break. If this sort of challenge tweaks your interest, there’s plenty of time to get started on next year’s BASIC 10 Liner Contest. Fire up those emulators!

Continue reading “Video Poker Takes Your Money In 10 Lines Of BASIC”

A ZX Spectrum Raytracer, In BASIC

[Gabriel Gambetta] knows a few things about ray tracers, being the author of Tiny Raytracer, a raytracer written in just 912 bytes of JavaScript. As a long-time fellow sufferer of the UK-designed ZX Spectrum, could these two love affairs be merged? Could the Tiny Raytracer fit on the ZX Spectrum? In BASIC? The answer is an affirmative, albeit with our beloved speccy’s many limitations.

Ray tracing with only 15 primary colours

The story starts with [Gabriel]’s Computer Graphics From Scratch (CGFS) raytracer algorithms and an existing code base that was ported to the ZX Spectrum’s very limited BASIC dialect, using VSCode for editing, BAS2TAP to generate a tape image file (essentially an audio track) and executed with FUSE. With the toolchain sorted, [Gabriel] adds just enough code to deal with the ray intersection equations of a sphere, and renders a three-sphere scene to a 32×22 pixel colour image, taking a mere 15 minutes of runtime. Fellow sufferers will remember the spectrum had a 32×22 block attribute array (or colour array) with two colour values for foreground and background pixels. Each attribute block contains 8×8 pixels, each of which could be foreground (on) or background (off.) The next stage was then to expand the code to handle pixels as well as blocks, by simply expanding the raytracing to the full 256×176 resolution, and for each block simply determine the two most common colours, and run with those for the whole block. It sort of works, in a very spectrum-esq ‘attribute clash’ kind of fashion.

Continue reading “A ZX Spectrum Raytracer, In BASIC

Beyond The Basics: Exploring More Exotic Scope Trigger Modes

Last time, we looked at some powerful trigger modes found on many modern scopes, including the Rigol DHO900 series we used as an example. Those triggers were mostly digital or, at least, threshold-based. This time, we’ll look at some more advanced analog triggers as well as a powerful digital trigger that can catch setup and hold violations. You can find the Raspberry Pi code to create the test waveforms online.

In addition to software, you’ll need to add some simple components to generate the analog waveform. In particular, pin 21 of the Pi connects to  2uF capacitor through a 10K resistor. The other side of the capacitor connects to ground. In addition, pin 22 connects directly to the capacitor, bypassing the 10K resistor. This allows us to discharge the capacitor quickly. The exact values are not especially important.

Runt Triggers

A runt pulse is one that doesn’t have the same voltage magnitude as surrounding pulses. Sometimes, this is due to a bus contention, for example. Imagine if you have some square waves that go from 0 to 5V. But, every so often, one pulse doesn’t make it to 5V. Instead, it stops at 3V.

Continue reading “Beyond The Basics: Exploring More Exotic Scope Trigger Modes”

Clever Mechanism Makes A Linear Control From A Rotary Hall Sensor

Every once in a while we stumble across something so simple yet so clever that we just have to call it out. This custom linear Hall effect sensor is a perfect example of this.

By way of backstory, [Nixieguy], aka [The Electronic Mercenary], offers up a relatable tale — in the market for suitable hardware to make the game Star Citizen more enjoyable, and finding the current commercial joystick offerings somewhat wanting, he decided to roll his own controllers. This resulted in the need for a linear sensor 100 mm in length, the specs for which — absolute sensing, no brushes or encoders, easily sourced parts — precluded most of the available commercial options, like linear pots. What to do?

The solution [Nixieguy] settled on was to use a Hall effect sensor and a diametrally magnetized neodymium ring magnet. The magnet is rotated through 180 degrees by a twisted aluminum bar, which is supported in a frame by bearings. A low-friction slider with a slot captures the bar; moving the slider along the length of the control rotates the bar, which rotates the magnet, which allows the Hall sensor to measure the angle of the magnetic field. Genius!

The parts for the prototype sensor are all made from 0.8-mm aluminum sheet stock and bent to shape. The video below shows the action better than words can describe it, and judging by the oscilloscope trace, the output of the sensor is pretty smooth. There’s clearly a long way to go to tighten things up, but the basic mechanism looks like a clear win to us.

Hats off to [Nixieguy] for this one, which we’ll surely be following for more developments. In the meantime, if you need to brush up on the Hall effect, [Al Williams] did a nice piece on that a while back.

Continue reading “Clever Mechanism Makes A Linear Control From A Rotary Hall Sensor”

Git Your PCBs Online

Last time, I’ve shown you how to create a local Git repository around your PCB project. That alone provides you with local backups, helping you never lose the changes you make to your files, and always be able to review the history of your project as it developed.

However, an even more significant part of Git’s usefulness is the ability to upload our creations to one of the various online Git repository hosting services, and keep it up to date at all times with a single shell command. I’d like to show you how to upload your project to GitHub and GitLab, in particular!

Continue reading “Git Your PCBs Online”