Linux Fu: Bash Strings

If you are a traditional programmer, using bash for scripting may seem limiting sometimes, but for certain tasks, bash can be very productive. It turns out, some of the limits of bash are really limits of older shells and people code to that to be compatible. Still other perceived issues are because some of the advanced functions in bash are arcane or confusing.

Strings are a good example. You don’t think of bash as a string manipulation language, but it has many powerful ways to handle strings. In fact, it may have too many ways, since the functionality winds up in more than one place. Of course, you can also call out to programs, and sometimes it is just easier to make a call to an awk or Python script to do the heavy lifting.

But let’s stick with bash-isms for handling strings. Obviously, you can put a string in an environment variable and pull it back out. I am going to assume you know how string interpolation and quoting works. In other words, this should make sense:

echo "Your path is $PATH and the current directory is ${PWD}"

The Long and the Short

Suppose you want to know the length of a string. That’s a pretty basic string operation. In bash, you can write ${#var} to find the length of $var:


#/bin/bash
echo -n "Project Name? "
read PNAME
if (( ${#PNAME} > 16 ))
then
   echo Error: Project name longer than 16 characters
else
   echo ${PNAME} it is!
fi

Continue reading “Linux Fu: Bash Strings”

An snowy city street.

The Road Is Peppered With Rock Salt Alternatives

Every winter, millions of tons of rock salt is sprinkled across roads in the US, mostly in the Midwest and Northeast regions. It’s a cheap and effective way to prevent accidents. Rock salt is chemically the same as the stuff that sits next to the pepper, except it isn’t as finely ground, and it doesn’t have sodium or potassium iodine added to it to prevent goiters. Both table salt and rock salt melt ice by lowering the freezing point of water. So does sugar.

Much of what we salt the Earth with every winter comes from underground networks of salt crystal that formed when various ancient seas dried up. As natural as it may be, rock salt is bad for the environment. For one thing, chloride is forever, and can’t easily be decoupled from the soil and water it taints when it washes away. Rock salt also corrodes concrete, makes its way into the groundwater, and is bad for pets. Worst of all, its efficacy drops along with the temperature. At 15° F (-9° C), rock salt loses more than 86% of its melting power.

Disposable Detroit

All this salt is not great for cars, either — it’s bad for the paint and eats up the frame. In the saltiest parts of the US, aka The Salt Belt, cars only last a handful of years before they become Flintstones mobiles. Well, not really, but salt is terrible for the brake lines and most of the undercarriage. Consumer woes aside, there’s a real environmental impact to manufacturing all these disposable cars to meet the demand.

But the problem is that we need to use salt, or at something like it. Even though millions of people are staying home a whole lot more, the trucking industry still relies on salted highways and local roads. So if you like stocked grocery stores and stuff arriving from the Bezos Barn in a timely fashion, you can see the problem. So what are the alternatives? Are there any?

Continue reading “The Road Is Peppered With Rock Salt Alternatives”

Can Robots Give Good Hugs?

We could all use a hug once in a while. Most people would probably say the shared warmth is nice, and the squishiness of another living, breathing meatbag is pretty comforting. Hugs even have health benefits.

But maybe you’re new in town and don’t know anyone yet, or you’ve outlived all your friends and family. Or maybe you just don’t look like the kind of person who goes for hugs, and therefore you don’t get enough embraces. Nearly everyone needs and want hugs, whether they’re great, good, or just average.

So what makes a good hug, anyway? It’s a bit like a handshake. It should be warm and dry, with a firmness appropriate to the situation. Ideally, you’re both done at the same time and things don’t get awkward. Could a robot possibly check all of these boxes? That’s the idea behind HuggieBot, the haphazardly humanoid invention of Katherine J. Kuchenbecker and team at the Max Planck Institute for Intelligent Systems in Stuttgart, Germany (translated). User feedback helped the team get their arms around the problem.

Continue reading “Can Robots Give Good Hugs?”

Bendy Straws

Compliant Mechanisms Hack Chat

Join us on Wednesday, January 26 at noon Pacific for the Compliant Mechanisms Hack Chat with Amy Qian!

When it comes to putting together complex mechanisms, we tend to think in a traditional design language that includes elements like bearings, bushings, axles, pulleys — anything that makes it possible for separate rigid bodies to move against each other. That works fine in a lot of cases — our cars wouldn’t get very far without such elements — but there are simpler ways to transmit force and motion, like compliant mechanisms.

Compliant mechanisms show up in countless products, from the living hinge on a cheap plastic box to the nanoscale linkages etched into silicon inside a MEMS accelerometer. They reduce complexity by putting the elasticity of materials to work and by reducing the number of parts it takes to create an assembly. And they can help make your projects easier and cheaper to build — if you know the secrets of their design.

join-hack-chatAmy Qian, from the Amy Makes Stuff channel on YouTube,  is a mechanical engineer with an interest in compliant mechanisms, so much so that she ran a workshop about them at the 2019 Superconference. She’ll stop by the Hack Chat to share some of what she’s learned about compliant mechanisms, and to help us all build a little flexibility into our designs.

Our Hack Chats are live community events in the Hackaday.io Hack Chat group messaging. This week we’ll be sitting down on Wednesday, January 26 at 12:00 PM Pacific time. If time zones have you tied up, we have a handy time zone converter.

 

Continue reading “Compliant Mechanisms Hack Chat”

Hackaday Links Column Banner

Hackaday Links: January 23, 2022

When Tonga’s Hunga-Tonga Hunga-Ha’apai volcano erupted on January 15, one hacker in the UK knew just what to do. Sandy Macdonald from York quickly cobbled together a Raspberry Pi and a pressure/humidity sensor board and added a little code to create a recording barometer. The idea was to see if the shock wave from the eruption would be detectable over 16,000 km away — and surprise, surprise, it was! It took more than 14 hours to reach Sandy’s impromptu recording station, but the data clearly show a rapid pulse of increasing pressure as the shockwave approached, and a decreased pressure as it passed. What’s more, the shock wave that traveled the “other way” around the planet was detectable too, about seven hours after the first event. In fact, data gathered through the 19th clearly show three full passes of the shockwaves. We just find this fascinating, and applaud Sandy for the presence of mind to throw this together when news of the eruption came out.

Good news for professional astronomers and others with eyes turned skyward — it seems like the ever-expanding Starlink satellite constellation isn’t going to kill ground-based observation. At least that’s the conclusion of a team using the Zwicky Transient Facility (ZTF) at the Palomar Observatory outside San Diego. ZTF is designed to catalog anything that blinks, flashes, or explodes in the night sky, making it perfect to detect the streaks from the 1,800-odd Starlink satellites currently in orbit. They analyzed the number of satellite transients captured in ZTF images, and found that fully 20 percent of images show streaks now, as opposed to 0.5 percent back in 2019 when the constellation was much smaller. They conclude that at the 10,000 satellite full build-out, essentially every ZTF image will have a streak in it, but since the artifacts are tiny and well-characterized, they really won’t hinder the science to any appreciable degree.

Speaking of space, we finally have a bit of insight into the causes of space anemia. The 10% to 12% decrease in red blood cells in astronauts during their first ten days in space has been well known since the dawn of the Space Age, but the causes had never really been clear. It was assumed that the anemia was a result of the shifting of fluids in microgravity, but nobody really knew for sure until doing a six-month study on fourteen ISS astronauts. They used exhaled carbon monoxide as a proxy for the destruction of red blood cells (RBCs) — one molecule of CO is liberated for each hemoglobin molecule that’s destroyed — and found that the destruction of RBCs is a primary effect of being in space. Luckily, there appears to be a limit to how many RBCs are lost in space, so the astronauts didn’t suffer from complications of severe anemia while in space. Once they came back to gravity, the anemia reversed, albeit slowly and with up to a year of measurable changes to their blood.

From the “Better Late Than Never” department, we see that this week that Wired finally featured Hackaday Superfriend Sam Zeloof and his homemade integrated circuits. We’re glad to see Sam get coverage — the story was also picked up by Ars Technica — but it’s clear that nobody at either outfit reads Hackaday, since we’ve been featuring Sam since we first heard about his garage fab in 2017. That was back when Sam was still “just” making transistors; since then, we’ve featured some of his lab upgrades, watched him delve into electron beam lithography, and broke the story on his first legit integrated circuit. Along the way, we managed to coax him out to Supercon in 2019 where he gave both a talk and an interview.

And finally, if you’re in the mood for a contest, why not check out WIZNet’s Ethernet HAT contest? The idea is to explore what a Raspberry Pi Pico with Ethernet attached is good for. WIZNet has two flavors of board: one is an Ethernet HAT for the Pico, while the other is as RP2040 with built-in Ethernet. The good news is, if you submit an idea, they’ll send you a board for free. We love it when someone from the Hackaday community wins a contest, so if you enter, be sure to let us know. And hurry — submissions close January 31.

Hackers, Fingerprints, Laptops, And Stickers

A discussion ensued about our crazy hacker ways the other night. I jokingly suggested that with as many stickers as we each had on our trusty companion machines, they might literally be as unique as a fingerprint. Cut straight to nerds talking too much math.

First off, you could wonder about the chances of two random hackers having the same sticker on their laptop. Say, for argument’s sake, that globally there are 2,000 stickers per year that are cool enough to put on a laptop. (None of us will see them all.) If a laptop lasts five years, that’s a pool of 10,000 stickers to draw from. If you’ve only got one sticker per laptop, that’s pretty slim odds, even when the laptops are of the same vintage.

Real hackers have 20-50 stickers per laptop — at least in our sample of “real hackers”. Here, the Birthday Paradox kicks in and helps us out. Each additional sticker provides another shot at matching, and an extra shot at being matched. So while you and I are unlikely to have the same birthday, in a room full of 42 people, it’s 90% likely that someone will have their birthday matched. With eight of us in the room, that’s 240 stickers that could match each other. (9999 / 10000) ^ (240 * 210 / 2) = about an eight percent chance of no match, so a better than 90% chance that we’d have at least one matching sticker.

But that doesn’t answer the original question: are our be-stickered laptops unique, like fingerprints or snowflakes? There, you have to match each and every sticker on the laptop — a virtually impossible task, and while there were eight of us in the room, that’s just not enough to get any real juice from the Birthday Paradox. (1/10,000) ^ 30 = something with -120 in the exponent. More than all the atoms in the universe, much less hackers in a room, whether you take things to the eighth power or not.

I hear you mumbling “network effects”. We’ve all gone to the same conferences, and we have similar taste in stickers, and maybe we even trade with each other. Think six degrees of separation type stuff. Indeed, this was true in our room. A few of us had the same stickers because we gave them to each other. We had a lot more matches than you’d expect, even though we were all unique.

So while the math for these network effects is over my head, I think it says something deeper about our trusty boxen, their stickers, and their hackers. Each sticker also comes with a memory, and our collected memories make us unique like our laptops. But matching stickers are also more than pure Birthday Paradoxes, they represent the shared history of friends.

Wear your laptop stickers with pride!

Hackaday Podcast 152: 555 Timer Extravaganza, EMF Chip Glitching 3 Ways, A Magnetic Mechanical Keyboard, And The Best Tricorder Ever

Join Hackaday Editor-in-Chief Elliot Williams and Managing Editor Tom Nardi as they bring you up to speed on the best stories and projects from the week. There’s some pretty unfortunate news for the physical media aficionados in the audience, but if you’re particularly keen on 50 year old integrated circuits, you’ll love hearing about the winners of the 555 Timer Contest. We’ll take a look at a singing circuit sculpture powered by the ESP32, extol the virtues of 3D printed switches, follow one hacker’s dream of building the ultimate Star Trek tricorder prop, and try to wrap our heads around how electronic devices can be jolted into submission. Stick around to the end as we take a close look at some extraordinary claims about sniffing out computer viruses, and wrap things up by wondering why everyone is trying to drive so far.

Take a look at the links below if you want to follow along, and as always, tell us what you think about this episode in the comments!

Direct Download (65 MB)

Continue reading “Hackaday Podcast 152: 555 Timer Extravaganza, EMF Chip Glitching 3 Ways, A Magnetic Mechanical Keyboard, And The Best Tricorder Ever”