My talented wife has been learning to code. Specifically, she’s been learning front-end web development, starting with HTML and CSS.
One of her projects as part of a coding bootcamp she joined is to build a basic site with the HTML and CSS she’s learned. She experimented with a CSS-powered dropdown menu on her project site, and hit a snag with it, so I took a look at it last night.
In the process of working out a solution, we found something new we can do as a coding couple … submit and merge pull requests (no pun intended there 😜).
The city's new center boulevard is coming along nicely. It was recently left open for pedestrians, so I took my camera for a morning walk/
My quest to automate parts of my workflows usually involves writing Python scripts to streamline some of my tasks as a Happiness Engineer.
One output has confused me for far longer than it should have, and I was shown the light today (in the form of a pretty simple solution).
My dilemma
Many of my scripts generate template documents. These include meeting agendas, hangout notes, and team reports. These documents include a couple components that I’ve largely automated using Python, such as –
Calculating dates and times in reports (sometimes including timezone conversions);
Taking inputs I provide in response to command line prompts, running calculations, and adding those to fields in my reports; and so on.
Many of my documents have a static list of team members that I ping much like Twitter mentions when I publish them as posts on internal blogs (we use internal blogs quite a lot, as you can imagine). Those lists each need to be updated manually every time there’s a change in the team composition, in each of the documents the list appears in.
Although the team composition doesn’t change frequently, I often find myself re-using a script for a team report, or hangout agenda, for example, in another group I work with. This means another set of documents where I need to manually create a list of people, and maintain that.
I was planning on using Python Classes to do this, but quickly realised that I don’t understand Classes nearly well enough to using this feature for this aspect of my documents.
I realised that there’s actually a simpler solution using .csv files and the csv module available in Python instead, after watching Corey Schafer‘s tutorial on this, here:
As an aside, Schafer’s tutorials are wonderful!
I was able to borrow from Schafer’s solutions to write a script that produced a list that looks something like this:
import csv
with open('people.csv', 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)
members = []
for line in csv_reader:
wpuser = f"@{line['wp_user']}"
members.append(wpuser)
print(f'Pinging: {members}')
I couldn’t work out how to just generate a list of usernames separated by spaces. I ran into a similar issue with other scripts where I similarly loop over a list of items to produce some sort of list-generated output.
In other words, I couldn’t figure out how to output the list of usernames without the []' characters you see in my initial output.
Clearly, I need to work on my Googling skills when it comes to finding solutions to my coding challenges.
Anyway, the solution that JohnnyJordaan suggested is pretty simple. Instead of using something like print(f'Pinging: {members}'), I could rather join the items in the list with a statement like this:
print(f'Pinging: {", ".join(members)}')
As I suspected, the solution is pretty simple. It just eluded me, completely. So thank you to JohnnyJordaan for the pointer!
I also like the * that came up in one of the StackOverflow solutions, but it doesn’t work with the f strings that I tend to use. Still, there are other ways to use them. Trey Hunner has an interesting post about these operators here (if you’re interested).
Sacha Baron Cohen recently spoke about how social media services have become the “greatest propaganda machine in history”.
Much of the media’s focus, when reporting on his remarks, was on his attack on Facebook. While he certainly targeted Facebook, he also spoke about how Google, YouTube, and Twitter shape online discourse, and how they help spread lies, bigotry, and attacks on fact-based discussions.
Think about it. Facebook, YouTube and Google, Twitter and others—they reach billions of people. The algorithms these platforms depend on deliberately amplify the type of content that keeps users engaged—stories that appeal to our baser instincts and that trigger outrage and fear. It’s why YouTube recommended videos by the conspiracist Alex Jones billions of times. It’s why fake news outperforms real news, because studies show that lies spread faster than truth. And it’s no surprise that the greatest propaganda machine in history has spread the oldest conspiracy theory in history—the lie that Jews are somehow dangerous. As one headline put it, “Just Think What Goebbels Could Have Done with Facebook.”
As much as we embrace free expression, we find it difficult to draw a line when liars and bigots abuse their right to free expression because doing that feels like hypocrisy.
Free expression isn’t unlimited, though. And pushing back against channels that help propagate misinformation, abuse, and false statements that impact substantial segments of the population is becoming more important.
At the very least, it’s worth watching Cohen’s talk, or reading his remarks:
We should also think carefully about how much trust we place in services that profit from the social chaos we see around us.
Last week I ran my first timed 5km race as part of the annual Modiin Race. I set myself the goal of running in the 5km race last year when my wife and son competed in last year’s Modiin Race, and I’m pretty proud of myself for achieving my goal.
I started running again towards the end of 2018/beginning of 2019, and was pretty consistent until about April when I stopped running.
Then, as the race approached, I decided to start running again at the beginning of November when the weather started to cool.
My November runs
My pace was predictably relatively slow to begin with (I hadn’t done much exercise for months, after all), but I feel like I improved nicely over the following two weeks.
I was hoping to complete the race in under 30 minutes, although I just realised that I based that goal on the assumption that the race course was 5km.
It was actually a little more, so my time was pretty good for my first 5km race in years (I ran a 5km fun run years ago in Johannesburg).
I wouldn’t say that I enjoy running, necessarily, but I do like getting out and exercising. I also enjoy the feeling of progress when I run further without slowing to walk, and the feeling of having accomplished something for myself afterwards.
Tal Kravitz performed in the park as part of Modiin's Autumn Festival
Tal Kravitz performed at one of our city’s annual Autumn music festival events in a neighbourhood park yesterday. According to his bio on his Facebook Page –
Tal Kravitz is a musician and a singer educated at Israel’s finest music institutions. He is also a traveler who journeyed on a personal search for original tribal music in far corners of the world not yet exposed to Western civilization. Tal plays piano, harp, guitar, a variety of bagpipes, the musical saw, African percussion instruments and more.
We really enjoyed the event. Kravitz is really engaging, and involves the audience (who loved him).
Fortunately we arrived early enough to find good seats. I took advantage of that for some photographs.
Kravitz used a range of musical instruments including an Irish harp, a saw (the kind you use to cut wood), bagpipes, and some sort of electromagnetic/sonic device.