Skip to content
Jason A. Heppler

Microblog

Microblog

Developer Notes: Converting Filenames to Metadata

This past week, we had a need to convert a directory of filesnames into some bare-bones metadata. The filenames themselves contained the metadata we wanted, and generally followed a pattern that looked like this: BoxNameYear-001 — or, the name of a box, a four-digit year, and a unique identifier appended by a dash.

It turned out to be simple enough to solve this with bash. The script I came up with was:

#!/usr/bin/bash 

re='[[:alpha:]]+|[0-9]+'

echo "box,year,no,filetype"
for f in *.tiff; do 
    [[ ! -e $f ]] && continue
    grep -Eo $re <<< "$f" | sed 's/ \n/,/g;/^$/d' | paste -d, - - - -
done

The script takes a directory of files that follows this naming convention and generates a CSV file. We set up the structure with the echo, then loop through the files and look for any file with the appropriate extension (in this case, a .tiff). Then, simply enough, we use grep to match our regular expression against the file name, sed to do some in-line editing and add a comma as a separator to each line, and finally use paste -d to convert the newline output into a single line.

Let’s imagine a set of filenames that look like this:

JoeSmith1950-001.tiff
JoeSmith1950-028.tiff
JoeSmith1950-033.tiff
JoeSmith1950-046.tiff

We can run our script from the command line (sh filemetadata.sh > metadata.csv) and we’ll be left with a CSV file that looks like this:

box,year,no,filetype
JoeSmith,1950,001,tiff
JoeSmith,1950,028,tiff
JoeSmith,1950,033,tiff
JoeSmith,1950,046,tiff

It had been a while since I’d done bash scripting, and I have to say I’m pretty pleased with how simple the solution turned out to be. If you have a need for something similar, some minor tweaks to the script above should get you started as well.

Programming

The Break from Twitter

During Advent, I decided to take a break from Twitter. I’ve dipped a toe back in here and there over the past few days, but honestly I might keep away for the most part. Twitter might become, in some tortured computer lingo, more of a write space rather than a read space: a place to broadcast my writing, projects, the work of my colleagues, and so forth, rather than something I mindlessly scroll or jump to out of habit anytime I open a new Safari tab. If I continue to use Twitter much as a reading space, I might lean much more heavily in Twitter Lists (which were already a common way for me to use the platform).

I find myself returning to this piece Caitlin Flanagan from earlier this year:

Twitter is a parasite that burrows deep into your brain, training you to respond to the constant social feedback of likes and retweets. That takes only a week or two. Human psychology is pathetically simple to manipulate. Once you’re hooked, the parasite becomes your master, and it changes the way you think. Even now, I’m dopesick, dying to go back.

Part of my own thinking here is Twitter steals my time: my time for thinking, for writing, for meaningfully engaging in the world. There’s also something enticing about being in the know, as it were: keeping up with the latest news, or the discourse of the day, or the controversy of the week (especially as things unfolded during the previous presidential administration) made me feel informed and ahead of the news curve. But, in reality, it did nothing but fuel anxiety, endless scrolling, an incessant desire to keep up with the news – news that I couldn’t actually act on or influence in any meaningful way.

In some ways, I find this really unfortunate – I’ve found Twitter to be an incredible place for professional connections, networking, even building real friendships. So I stick around, because these are real, tangible things that happened because of the bird site and still do happen – but even this is starting to feel like less of a thing.

I’d rather spend that time reading, writing, building, thinking, creating – and I hope to do this more meaningfully as we enter 2022.

Personal

Julebordet

We’re just a few days away from Christmas, and while there’s a lot I love about this time of year – the people, the cold weather, snow (although, not this year…), extra time at home with the kids – food often takes center stage. We spend much of December baking and cooking things that are only made during this time of year, both for our household and for others. For at least ten years now, my beloved and I bake sweets and candies as Christmas gifts to our family and close friends. It’s a tradition both us and our families look forward to.

We also make plenty of things typically for our household (although we always over-bake, and tend to give out lots of these sweets to others). Over the last couple of years, I’ve added three Scandinavian baked goods to our usual December fare: gingerbread (pepperkaker), St. Lucia saffron buns (lussekatter), and sirupsnipper. And then there’s the Christmas meal itself.

Mains

For Christmas Eve and Christmas Day meals.

  • Oyster stew: My family’s Christmas Eve tradition. As kids, we always attended the Christmas Eve church service, then went to grandma and grandpa’s for oyster stew, before returning home to open a couple of gifts.
  • Broccoli cheese soup: For the vegetarians in the household, I typically make this crowd favorite.
  • Roasted duck: This is a new one for me this year. In previous years I’ve usually cooked ham or pork loin for Christmas Day, but I’m looking forward to trying this out.
  • Gløgg: A Scandinavian-style glüehwein. I’ve made this already this year, but we’re making more. And I’m probably going to use the gløgg to baste the roasted duck.
  • Smoked salmon: Can’t have a julebord without salmon or cod being served. Last year, I cooked cod and sandefjordsmør. This year, we’ve got smoked salmon.
  • A smattering of other roasted vegetables (broccoli, in particular), surkål, and cheeses.

Baking

  • Pepperkaker: Is there anyting more Christmas-y than gingerbread? We usually bake this in late November right before the start of Advent.
  • Lussekatter: Another baked item of Scandinavian origin are the St. Lucia saffron buns, usually made for St. Lucia’s Day on December 13.
  • Sirupsnipper: New this year to me, which I’m probably making tomorrow. These Norwegian Christmas cookies are reminiscent of gingerbread. Diamoned-shaped with a blanched almond in the middle.
  • Cinnamon rolls: My family brough the oyster stew tradition to our household; my wife’s family brough the cinnamon roll tradition. I’ll leave it to the reader to decide who got the better deal. We make these on Christmas morning using a recipe handed down from the grandparents.
  • Lefse: If you have Norwegian family or heritage, you’ve most certainly had these potato flatbrads. Slather with butter topped with cinnamon and sugar, or roll up some smoked salmon, dill, cucumber, and sour cream.

Gledelig jul!

Personal

Christmas Tunes

If Christmas music is your thing, I’ve probably got you covered.

Personal

The Summer Day

I don’t know exactly what a prayer is.
I do know how to pay attention, how to fall down
into the grass, how to kneel down in the grass,
how to be idle and blessed, how to stroll through the fields,
which is what I have been doing all day.
Tell me, what else should I have done?
Doesn’t everything die at last, and too soon?
Tell me, what is it you plan to do
with your one wild and precious life?

Mary Oliver

Poetry

Twitter and Facebook moderating Trump campaign on misinformation

Heather Kelly in the Washington Post:

Facebook and Twitter on Wednesday took extraordinary action against President Trump for spreading coronavirus misinformation after his official and campaign accounts broke their rules, respectively.

Facebook removed from Trump’s official account the post of a video clip from a Fox News interview in which he said children are “almost immune” from covid-19. Twitter required his Team Trump campaign account to delete a tweet with the same video, blocking it from tweeting in the interim.

In the removed video, President Trump can be heard in a phone interview saying schools should open. He goes on to say, “If you look at children, children are almost — and I would almost say definitely — but almost immune from this disease,” and that they have stronger immune systems.

The source video, however, is still on YouTube. It’s simply not true that children are immune from the disease, nor should we forget that there are children and adults in schools.

Tech life

Apple Pledges to Be Carbon Neutral by 2030

Sarah E. Needleman in the Wall Street Journal:

Apple Inc. is pledging to become carbon neutral across its business, including its mostly overseas supply chain, within the next 10 years, the latest corporate giant planning to shift its operations to battle climate change.

The iPhone maker said Tuesday that the new commitment means that by 2030, every Apple device sold will have been produced with no net release of carbon into the atmosphere. The company plans to reduce its emissions by 75% and develop carbon-removal solutions for the remaining 25% of its footprint.

Apple said its global corporate operations are already carbon neutral and that all of its iPhone, iPad, Mac and Apple Watch devices released in the past year are made with some recycled content.

This move doesn’t directly address the right to repair, though in part feels like an attempt to fight off right to repair legislation. But to Apple’s credit, this extends on their commitments in 2017 to make their supply chain a “closed loop.” Plus, Apple is pretty good about encouraging people to hold onto their devices even as it introduces new ones every year: the next version of iOS will run on five year old phones, and macOS Big Sur will run on seven year old Macs.

Tech life

Twitter Begins Limiting the Spread of QAnon Conspiracy Theories

Ben Collins and Brandy Zadrozny:

Twitter will stop recommending accounts and content related to QAnon, including material in email and follow recommendations, and it will take steps to limit circulation of content in features like trends and search. The action will affect about 150,000 accounts, said a spokesperson, who asked to remain unnamed because of concerns about the targeted harassment of social media employees.

The spokesperson said that as part of its new policy, the company had taken down more than 7,000 QAnon accounts in the last few weeks for breaking its rules on targeted harassment.

The sweeping enforcement action will ban QAnon-related terms from appearing in trending topics and the platform’s search feature, ban known QAnon-related URLs and prohibit “swarming” of people who are baselessly targeted by coordinated harassment campaigns pushed by QAnon followers.

This has crossed over from Internet fringe to real-world violent extremism, so it’s a welcome step from Twitter.

Tech life

Newsletter

Occasional writing on the American West, agricultural history, and political culture.