Linux Fu: Customizing Printf

When it comes to programming in C and, sometimes, C++, the printf function is a jack-of-all-trades. It does a nice job of quickly writing output, but it can also do surprisingly intricate formatting. For debugging, it is a quick way to dump some data. But what if you have data that printf can’t format? Sure, you can just write a function to pick things apart into things printf knows about. But if you are using the GNU C library, you can also extend printf to use custom specifications. It isn’t that hard, and it makes using custom data types easier.

An Example

Suppose you are writing a program that studies coin flips. Even numbers are considered tails, and odd numbers are heads. Of course, you could just print out the number or even mask off the least significant bit and print that. But what fun is that?

Here’s a very simple example of using our new printf specifier “%H”:

printf("%H %H %H %H\n",1,2,3,4);
printf("%1H %1H\n",0,1);

When you have a width specification of 1 (like you do in the second line) the output will be H or T. If you have anything else, the output will be HEADS or TAILS.

Continue reading “Linux Fu: Customizing Printf”

Retrotechtacular: The $175,000 Laser Printer

Laser printers today are cheap and readily available. But in 1976, they were the height of printing technology. The IBM 3800 was the $175,000 printer to have in that year. (Video, embedded below.) But you couldn’t have one on your desktop. Even if you could afford it, the thing is the size of a car, and we don’t even want to guess what it weighs. The printer took tractor-fed continuous form paper and could do 167 pages a minute at about 150 dots per inch (actually 180 x 144). For the record, that was as much as 1.7 miles of paper an hour!

In those days, people who would use this printer traditionally had massive banks of noisy impact printers. We imagine this device saved many data processing person’s hearing. Compared to a modern laser printer, though, it needed a lot of maintenance. For example, the initial models needed a xenon flash lamp replaced every month, although later models could go years on one bulb. Looking at some of the hardware in the video, it was probably made closer to the end of life for these printers which were made through 1999.

Continue reading “Retrotechtacular: The $175,000 Laser Printer”

Hackaday Links Column Banner

Hackaday Links: October 22, 2023

The second of three major solar eclipses in a mere six-year period swept across the United States last week. We managed to catch the first one back in 2017, and still have plans for the next one in April of 2024. But we gave this one a miss, mainly because it was “just” an annular eclipse, promising a less spectacular presentation than a total eclipse.

Looks like we were wrong about that, at least judging by photographs of last week’s “Ring of Fire” eclipse. NASA managed to catch a shot of the Moon’s shadow over the middle of the US from the Deep Space Climate Observer at Lagrange Point 1. The image, which shows both the compact central umbra of the shadow and the much larger penumbra, which covers almost the entire continent, is equal parts fascinating and terrifying. Ground-based photographers were very much in the action too, turning in some lovely shots of the eclipse. We particularly like this “one-in-a-million” shot of a jet airliner photobombing the developing eclipse. Shots like these make us feel like it was a mistake to skip the 10-hour drive to the path of annularity.

Continue reading “Hackaday Links: October 22, 2023”

The Eternal Dilemma

It’s two weeks until Supercon! We can almost smell the solder from here. If you’re coming, and especially if it’s your first time, you’re soon to be faced with the eternal dilemma of hacker cons, only at Supercon it’s maybe a trilemma or even a quadralemma: hang out with folks, work on the badge, go to talks, or show off all the cool stuff you’ve been working on the past year?

Why not all four? That’s exactly why we start off with a chill-out day on Friday, when we don’t have much formally planned. Sure, there’s a party Friday night, and maybe a badge talk or some workshops, but honestly you’ll have most of the day free. Ease into it. Have a look at the badge and start brainstorming. Meet some new people and start up a team. Or just bathe in the tremendous geekery of it all. This is also a great time to show off a small project that you brought along. Having the widget that you poured brain, sweat, and tears into sitting on the table next to you is the perfect hacker icebreaker.

On Saturday and Sunday, there will definitely be talks that you’ll want to attend, so scope that out ahead of time and plan those in. But don’t feel like you have to go to all of them, either. Most of the talks will be online, either right away or eventually, so you won’t miss out forever. But since our speakers are putting their own work out there, if you’re interested in the subject, having questions or insight about their talk is a surefire way to strike up a good conversation later on, and that’s something you can’t do online. So plan in a few talks, too.

You’ll find that the time flies by, but don’t feel like you have to do it all either. Ask others what the coolest thing they’ve seen is. Sample as much as you can, but it’s not Pokemon – you can’t catch it all.

See you in two weeks!

(PS: The art is recycled from a Supercon long, long ago. I thought it was too nice to never see it again.)

Hackaday Podcast Ep 241: Circuit Bending, Resistor Filing, The Butterfly Keyboard, And The Badge Reveal

Hackaday Editors Elliot Williams and Tom Nardi meet up virtually to talk about the week’s top stories and hacks, such as the fine art of resistor trimming and lessons learned from doing overseas injection molding. They’ll go over circuit bending, self-driving cars, and a solar camera that started as a pandemic project and turned into an obsession. You’ll also hear about Linux on the Arduino, classic ICs etched into slate, and an incredible restoration of one of the most interesting Thinkpads ever made. Stay tuned until the end to hear about a custom USB-C power supply and the long-awaited Hackaday Supercon 2023 Vectorscope badge.

Check out the links below if you want to follow along, and as always, tell us what you think about this episode in the comments!

Download your own, unlimited-edition MP3 of this week’s podcast.

Continue reading “Hackaday Podcast Ep 241: Circuit Bending, Resistor Filing, The Butterfly Keyboard, And The Badge Reveal”

This Week In Security: Browser Exploits, Play Protect, And Turn ON Your Firewall!

Google Chrome has done a lot of work on JavaScript performance, pushing the V8 engine to more and more impressive feats. Recently, that optimization has one more piece, the Maglev compiler, which sits between Sparkplug and TurboFan, as a mid-tier optimization step. With a Just In Time (JIT) system, the time saving of code optimization steps has to be carefully weighed against the time costs, and Maglev is another tool in that endless hunt for speed. And with anything this complicated, there’s the occasional flaw found in the system. And of course, because we’re talking about it here, it’s a security vulnerability that results in Remote Code Execution (RCE).

The trick is to use Maglev’s optimization against it. Set up a pair of classes, such that B extends A. Calling new B() results in an attempt to use the constructor from A. Which works, because the compiler checks to make sure that the constructors match before doing so. There’s another way to call a constructor in JS, something like Reflect.construct(B, [], Array);. This calls the B constructor, but indicates that the constructor should return an Array object. You may notice, there’s no array in the A class below. Tricking the compiler into using the parent class constructor in this fashion results in the array being uninitialized, and whatever happens to be in memory will set the length of the array. Continue reading “This Week In Security: Browser Exploits, Play Protect, And Turn ON Your Firewall!”

2023 Hackaday Supercon: The Rest Of The Talks

The 2023 Hackaday Superconference is only two weeks away, and we’re happy to announce the second half of the slate. As always, this is a great mix of well-known Hackaday faces, and folks we haven’t yet met. Whether they’re fixing up the Apollo Guidance Computer, building their own airplanes, trapping rubidium atoms, or teaching robots to sail, this is another super interesting round of talks.

Tickets are sold out, the badges are almost done, and we’re in the home stretch! We can smell the tacos from here. If you’re joining us, we hope you’re excited. If you’re not able to, we’ll stream as much as we can.

All that remains is the mystery of the keynote speaker.  Stay tuned! Continue reading “2023 Hackaday Supercon: The Rest Of The Talks”