A funny thing about Python

2021/09/19

Python has a way to convert arbitrary data types to Boolean (True/False). For example, an integer of value 0 will be converted to False, while any other integer will be converted to True. Empty sets are converted to False, sets that contain things are converted to True. So here are a few examples, as shown in a REPL (read, evaluate, print, loop) session:

>>> bool(0)
False
>>> bool(1)
True
>>> bool(2)
True
>>> bool([])
False
>>> bool([1])
True
>>> bool([1, 2])
True
>>> bool(True)
True
>>> bool(False)
False
>>> bool('True')
True

These should all make sense. Now for the funny part. Observe the REPL output below, which seems to give the wrong answers:


>>> bool('False')
True
>>> bool([False])
True
>>> bool([[]])
True

Of course, the first one is True because the interpreter is just checking to see if the string is empty or not, and it does not care what is in the string. Similarly, in the second and third examples the interpreter is just checking to see if there is an empty set. The False and the empty set are each taking up space and so the sets are not empty.

Python does give a way to check arrays, using the any and all built-in functions. Some examples:

>>> any([False, False])
False
>>> any([True, False])
True
>>> all([True, False])
False
>>> all([True, True])
True

One place to be careful, though, is with empty sets. Observe the following:

>>> any()
Traceback (most recent call last):
  File "<pyshell#75>", line 1, in 
    any()
TypeError: any() takes exactly one argument (0 given)
>>> any([])
False
>>> any([[]])
False
>>> any([[[]]])
True

I included the first to show that there is an error if you do not supply any set at all. The second is an empty set, which returns false since it does not contain anything. The third one is false since the innermost empty set contains one empty set, which converts to False (as we saw above), while the fourth one has a set containing a non-empty set, therefore it is equivalent to any([True]), which returns the expected True as seen above.

The Sportsman's Antics

2021/09/16

The day is spent in nervous anticipation.
As twilight falls, you move to your appointed place.
Darkness hides you, surrounds you,
A light beckons to you; a figure draws your attention.
Amid the roaring crowd you approach.
You size them up, they seem so familiar,
Each night a different person.
The crowds fade away,
The two of you are surrounded by a vast chasm.
You do the dance that is required.
Sweaty bodies clash, pushing, pulling.
Emotions run high, but it is merely for show,
All too soon it is over.
You walk down the dark and empty street,
Wearily, you head for home.

---

This poem was originally written in 2005 for a humanities class assignment, one of those things where you have to write a poem and then analyze your own poem. I happened to come across it while going through my old files, so I decided to keep it here.

Special Delivery by Kris Neville

2021/08/21

I just read the book Special Delivery, by Kris Neville (originally published in 1951). This is an interesting science fiction story, where an alien race is secretly invading the Earth. These aliens have the technology to replicate anything from Earth, and their magnificent plan to soften up the Earth for the invasion amounts to mailing a stack of money to each and every person. Of course this works as the aliens intended: everybody gleefully takes the stacks of money. This leads to immediate shortages as people decide they don't have to work anymore, then rioting and pillaging as people try to get everything for themselves before it is all gone, and then general societal collapse.

Perhaps you can see where I am going here?

Recently in the US, due to the Covid Pandemic, there have been various "stimulus payments" and "increased unemployment payments" and "monthly child tax credits" which all amount to mailing stacks of money to the general public. We should be aware that we are playing with fire here. It seems like there are "help wanted" signs popping up everywhere. Inflation has gotten to the point that people are starting to notice it. There seem to be new shortages of seemingly random items each month. But throughout all this, nobody is stopping to ask the question of whether this is a good idea to hand out free money to everybody, they just keep asking for more! Instead, the media is embroiled in covering the nitty gritty of who picks which side in the manufactured controversy of who "believes in science" more, whether it is the Team Red or the Team Blue and whether they will mandate masks or vaccines or forbid mandates of one or the other, all while breathlessly calling the other side names and completely ignoring the sinking ship of the economy as it tips over the brink of disaster.

The new and improved Scoopbot

2021/07/28

So I threw together an IRC bot (sig) for monitoring RSS feeds and announcing when new blog posts show up. A few years ago I had made one of these, but I seem to have misplaced the library it used for parsing RSS feeds. I started with the IRC bot structure found in Watchglass. I built a little function to pull out the stuff I wanted from the RSS feeds, so now I don't need that external library anymore.

Currently it just announces to all channels anything in the blog list. In the future I want to alter it so that it can take PM's to subscribe individually to feeds. If you have other ideas, please comment below. I also appreciate critiques of my code, whether it is something that I could have done more efficiently or if there is something that is just plain dumb.

Update: Had to change the program a little, I moved where it speaks the posts to a part of the loop that actually gets hit; it was hidden behind a 'continue' previously. Also changed the logic for storing the recent feeds to hold a few recent posts instead of just one, so that if the most recent post is deleted the program will still recognize the older posts and not report them as new.

Update 2: Added blog titles to the information parsed from the RSS and reported to IRC. Patch scoopbot_add_titles.vpatch (sig)

Overview of the Paleo Diet

2021/07/20

The other day I cam across an article about nutrition, and they quoted some guy who had spent time studying a hunter-gatherer society in Africa. This part got me thinking:

If you go out and have a chance to live with a group like the Hadza, you realize that a lot of the stories we tell ourselves about the past, including things like the paleo diet, just kind of fall apart. So there's this idea in the paleo diet world that there's one sort of single natural human diet, and that diet was very meat heavy, hardly any carbs at all and certainly no sugars.

[In reality] the Hadza have a mix of plants and animals in their diets. It changes day to day and year to year, but about half of the calories are coming from plants.

Clearly this guy does not understand what the Paleo Diet is. He has just summarized the Paleo Diet while trying to debunk it. The Paleo diet is not like the Atkins or South Beach diets where you drop everything except meat and then snobbily lecture your friends about your amazing diet while snarfing two pounds of bacon. Instead, the paleo diet focuses on a balance of a small amount of lean meat with an abundance of fruits and vegetables.

A while ago my wife and I went through learning the paleo diet, and more than any particular rules about eat this and not that, it was beneficial for changing the overall way we approached eating and menu planning. Before we studied the paleo diet, if we were at home and hungry and wanted something quick, we would throw on a pot of pasta, cover it in butter and call that dinner. Now, I realize that there are so much better things to eat, both in leaving you feeling better when you are done and also just having better flavors.

So here is a quick summary of the paleo diet:

  • Avoid processed foods - eat fresh stuff.

  • Avoid eating out, cook things yourself.
  • Consume a small to moderate amount of lean meats. Things like fish, a 4 oz steak (not a 24 oz steak), or a grilled chicken breast (not breaded and fried grease bomb with a bit of reconstituted chicken in the center).
  • Eat lots of vegetables, and use a wide variety.
  • Moderate amounts of fruits, berries, and nuts; these are great for adding in more flavors and variety to various recipes.
  • Low or no dairy (some people say none at all, some people say limit to small amounts) - this is one where it helps to do a "cleanse", go a few weeks or a month without it and see how you feel. It is widely documented citation needed? that some populations (like most Europeans) have a gene that allows them to process dairy while other populations (like most Asians) lack that gene and are therefore lactose intolerant, but humans have a tendency to be migratory and promiscuous so you might not be in the group that you think. In other words, try going without dairy and see if you feel a huge difference.
  • Most paleo guides say "no bread" or even "no grains", but this is one where I tend to temper it down to using moderation and less processing. So it is better to use brown rice instead of white rice, and whole grain bread instead of cheapo white bread. Corn-on-the-cob is great, a corn chip (like a Cheeto) is not so good.
  • Eggs are good too.

Overall, using the paleo diet is about rejecting the "progress" that has happened to food, where we are constantly being sold something more bland than we had before. While industrialized agriculture allows growing a huge amount of high fructose corn syrup, and that gives people the food energy they need to live, it does not give the vitamins and minerals that you need to live healthy. I recently saw a commercial for a liquid food replacement named "huel", which to me sounds like a portmanteau of hurl and gruel. Part of me wanted to hurl, part of me wanted to ask if this is some sort of sick joke, and part of me is curious to see who the hell would want that sort of garbage?

The Simple Diet

Somewhat related, I once went through a list of all the vitamins that people need, and made a list of the types of foods that provide each vitamin. Working on the premise that your body knows when it is missing something and so you will be hungry until you fill that need, my hypothesis is that eating something out of each of these categories will help you be healthier and avoid that craving which induces overeating. So here are the categories:

  • Green (leafy) vegetables, such as spinach, broccoli, kale

  • Colorful vegetables, such as carrots, peppers, sweet potatoes
  • Fruits
  • Meat and eggs
  • Whole grains
  • Beans and nuts
  • "Good oils", things like olives, avocados, and fish

So the idea is that if you focus on making sure you get at least a little bit from each of these categories you don't have to count any calories or anything, your body will just have access to the things it needs and you will be healthier.

US VP Debate 2020

2020/10/08

I suppose since I wrote up a review of the first presidential debate I should continue with what happened at the vice-presidential debate as well.

The current vice president, Mike Pence, squared off against the Democrat challenger, Senator Kamala Harris of California. Unlike the presidential debate, this one was mostly civil. More often than not, Pence continued talking long after his time was up, but at least there was no shouting at each other. In fact, they might have gone too far the other direction; there was so little energy that it was fairly boring.

The biggest thing that stuck out to me was that both candidates, but especially Harris, did not always answer the questions asked. There were a couple times where it seemed like Harris hadn't prepped for a certain question, so she just went ahead and answered a different question that she wished they had asked.

The topics covered were very similar to those covered in the presidential debate, so much of this one felt like a rehashing of the same talking points, just from a weaker point of view ("my guy is going to do ..." instead of "I am going to do ..."). The topic of whether the Democrats would try adding extra supreme court justices was again asked, and again the Democrat refused to address the question. Isn't that why we have the debates, so people know where you stand on issues? Why would they refuse to answer the question, unless they don't think voters would like the answer they give? What a non-answer should tell you is that voting for this guy would give you the opposite result of what you want - left-wingers should proceed as if she said "Our supreme court has had nine members for hundreds of years, we are not going to change it", and right-wingers should proceed as if she answered "We are going to nominate five of the most liberal judges we can find on our first day in office".

So instead of answering the question asked about the supreme court, Harris said something like "You want to talk about court packing, of the 30 federal judges appointed to life-time positions by this administration not a single one of them was Black!". Now, Pence did not really get a chance to answer, but it only takes a second to remember that on the current Supreme Court there is only one Black guy, and he was nominated by a Republican. Would Harris have been satisfied if a clone of Clarence Thomas had been nominated to the Appeals court? Furthermore, unlike Biden, Trump has published a list of people he would consider nominating to the supreme court, and it does include a couple Black guys.

The way the debate was formatted did not allow a lot of conversation between the candidates, but over the course of a couple questions this general back-and-forth happened:

Pence: The Trump administration passed a tax cut that saved the Average American Family1 $2000 per year on income taxes.
...
Harris: On day one of the Biden administration we are going to repeal the Trump tax cuts2.
Pence: There you have it, she said they are going to raise taxes.
Harris: I never said that!
Pence: You just said you are going to repeal a tax cut, which is the same as passing a tax increase.
Harris: Under a Biden administration taxes will not go up for anybody making under $400,000 a year.

Wait, where did we suddenly pull the number $400,000 from? Is that supposed to be the top of the middle class or something? I seem to remember Barak Obama promising not to raise taxes on anybody making below $250,000, and even then I thought the number was a bit on the high side. I guess that is inflation for you.

One interesting thing I noticed was the way the VP candidates referred to their presidential candidates. Pence always called him "President Trump", as if trying to emphasize his current position, perhaps to build up the image of a respectable person that voters could more easily support than the boorish name-caller that we saw on display during the last debate. Harris, on the other hand, was constantly calling her running mate "Joe", as if the playbook from their campaign is to emphasize his down-to-earth persona, somebody you could have a beer with, as they say. Marketing, it's all just marketing.

Overall, I would say that both candidates came across as sleazy politicians who play loose with the facts, but I disliked Harris more. For as much as she was touted as a former DA who could handle herself in a debate, she was underwhelming and fell far below my expectations. Pence came across as the kind of guy who has convictions and will go ahead and quietly do whatever it is that he wants to do (a stark contrast to the president, who picks random directions of travel but does it as loudly and crassly as possible).

  1. This mythical family of four makes something like $100,000 a year. []
  2. Nevermind that the president can't actually do that, it would take an act of Congress to change the tax code, but people running for president usually ignore that fact. []

Sad rant from a horny teenager

2020/10/01

The other day I was driving with my teen-aged daughter who was in a sad, weepy mood. I asked her what was bothering her. She started to sob and said to me "I am so stressed because I am so horny all the time. I see a cute boy and my body says 'I would fuck that', but I don't even know how to fuck!" Sob, sob, sob ...

This is the same daughter who struggles with tampons because, as she says, "I know it's supposed to go in my vagina, but I can't figure out where my vagina is."

The struggle is real.

US Presidential Debate 2020-1

2020/09/30

Donald Trump and Joe Biden, the two candidates for president nominated by the US duopoly held a debate last night. "Minor candidates" were pointedly not invited. If you didn't watch it you did not miss much. There was a lot of shouting, interrupting, and name calling in between most of the same talking points that are spouted by anonymous commenters on the internet.

The two men are quite old, but overall Biden looked more affected by age, where he would sometimes struggle to remember something. Biden also has a much slower way of talking, almost like he knows he doesn't have much to talk about and so talks slow to use up all the time on one idea. This might be the election where the VP choice is the most important, Donald Trump is already the oldest US president, and Joe Biden is even older.

The tone of the debate was not so much a serious presidential forum, but more like two trolls in an internet comment section going back and forth and arguing over each other. For example, the zingiest comeback of the night:

Biden: "First of all, my opponent does not know what he is talking about, and number two -"
Trump: "You're a number two."

There were a lot of loaded questions of the form: "Mr. Trump, given the fact that (leftwing talking point) why should voters listen to you?", and "Mr. Biden, since it is true that (rightwing talking point) how will you handle things?", which many times led to the moderator never actually finishing the question because the candidates wanted to jump in and challenge the assumptions he was loading into each question. The moderator should have just stuck to questions to prompt the debate, not interjecting his own point of view into it. The moderator also did a poor job of getting the candidates to not talk over each other.

Trump spent the night talking to the people in the room with him, Biden and the moderator, which seemed natural. Biden, on the other hand, took several moments to look into the camera and try to talk directly to the people watching. It came across as uncomfortable and slightly condescending, like he was trying to tell me what I was supposed to believe.

There were a few questions that each candidate sort of dodged or only answered vaguely before moving on to their own pet topics, but there was one question that stood out where Biden actually refused to answer the question. The topic was the Supreme Court, and the moderator asked something like "Some on the left have suggested 'packing the court', adding additional justices, would you do that if you were elected?" and Biden flatly refused to address the topic. Trump then asked him who he would pick, where is his list (Trump has published a list of possible judges to pull from for the Supreme Court, which was one thing that got some of his less enthusiastic supporters on his side, they figured they at least knew what sort of judges he would appoint) and Biden basically ignored the challenge.

Overall, I would say Trump won this debate. He came across as more lively, more in command of his facts, and more assertively executive. He may have said some things that were not true, but he sounded like he believed every last one of them and you should too. Biden seemed to be trying to take credit for anything good that happened during the Obama administration, but everybody knows the VP pretty much does nothing so the brags sounded hollow.

The Dumbest Internet Comment re. Amy Coney Barrett

2020/09/23

Since the death of Ruth Bader Ginsberg has left an opening on the US Supreme Court, and the attention of the media has turned to Amy Coney Barrett, who appears to be President Trump's leading candidate for the spot. Trump has said that he will announce his nominee on Saturday, but of course nobody wants to wait that long before talking about the possible nominees. In the comments section of one news article, a random commenter said:

Why does everybody keep using her middle name? Does she think she is special or something?

Seriously? The seat was left vacant by the death of Ruth Bader Ginsberg. She was the second female justice on the US Supreme Court, having followed Sandra Day O'Connor. If the 2016 presidential election had gone differently, the new justice would have been named by Hillary Rodham Clinton. You don't have to look very far to find professional women who are commonly referred to using both their maiden and married names.

Anyway, my impression of the situation is that the president and the senators were elected for a set period of time, and so even though we are close to an election it is still their job to nominate and approve (or reject) new justices. This despite the arguments that the Republican senators made in 2016 that it was too close to the election to move on a new justice; they were wrong then and the argument is still wrong now. One theory that I saw recently was that in 2016 the Republicans never voted to reject Obama's nominee so that if Trump lost they could still hold hearings and approve Garland after the election, because he was probably a better choice than whoever Clinton would nominate.

As to the rumored nominee Amy Coney Barrett, in my admittedly brief reading of some of her rulings she seems OK. On a scale of BAD (Breyer, Kagan) - (Sotomayor) - (Roberts) - (Thomas, Alito, Kavanaugh) - (Gorsuch) GOOD, my guess is that she will fall somewhere between Kavanaugh and Gorsuch.

Things I have learned about setting tiles

2020/08/25

For some time now my shower faucet has been leaky. I have tried to fix it a couple times, but it seems the problem requires replacing the whole housing instead of just the handle part. Meanwhile, a little while ago somebody slipped in my bathtub and tried to steady themself by bracing their hand against the soap holder. It snapped off, leaving a hole in the tiles and a long crack across the rest of the wall. The tiles in the bathtub were put up by a previous owner, they are plain white and rather boring. So my wife and I thought this would be a great opportunity to upgrade our bath with a new set of tiles and at the same time get the plumbing to the shower replaced. We contacted a contractor with whom we have worked in the past, got a bid, and ordered some tiles. We waited a few weeks for when the contractor said he would have time for us, and on the day he was scheduled to start working we waited for him to show up. And then we waited. And waited, all day. No contractor, no call, no text message, nothing. And nothing the next day. Or the whole next week. How do you agree to do a job and then not even answer your phone anymore? Maybe he died, I have no idea.

Meanwhile, we had taped some plastic over the hole in the wall to try to keep water out and the faucet seemed to be leaking more than ever, more of a flow now rather than a drip, and the hot water steaming up the house was fighting with the air conditioning so our bills were doubled from the month before. We gave up on the first guy and contacted a new contractor.1 This guy actually showed up a couple weeks later. He ripped out the wall around the tub and found out the insulation behind it had become moldy around where the hole in the tile was, and so he replaced the insulation and put up new wall boards. That doesn't seem like so much, tear out a wall and insulation and replace the wall, right? Well, this had taken him a week and a half. He showed up late every day he was working, he was doing this as a side job so he could only work every other day or so, and when he was at our house he spent more time outside smoking or talking on his phone than actually working. And one of the two major problems we wanted to fix in the first place, changing out the plumbing, he finally admitted he didn't know how to do so we had to get a different guy to come in and do that for him. And he never cleaned anything up, the whole house was a mess. So at about 10:30 on a day he was supposed to be there before 9 we finally called and told him to come get his tools and stop work.

That left us with a bathroom that still needed tiles, so I got to learn how to put up tiles. I watched a few videos online, it didn't seem like it would be so hard. Now that I am done putting up the tiles, here are some things I learned:

About the mortar: it is important to get the mortar the right consistency, it should be a thick paste; it should be just thick enough that if you scoop some on a trowel and hold it vertical the mortar does not flow off. If you have too much water it will be too runny and will just drip everywhere and make a mess and not stick to the wall. If you don't have enough water you will get clumps and it just won't spread evenly or stick to the wall. Sticking to the wall is important, that is the whole point of the mortar. I found that it is better to mix small batches of mortar more frequently rather than having one big batch; as it sits the mortar gets thicker and harder to work with, and you end up having to throw a bunch of it away at the end of the day if you make too much.

Speaking of messes, in one of the videos they mentioned taping a sheet of plastic down to protect the tub. I didn't think that would be important, since I was going to be careful, but I am glad I did. Even if you are careful you are going to drop some globs of mortar, and you end up knocking down lots of dried bits of mortar, so it is good to have that plastic sheet to catch everything.

Measurement is important, and don't assume that whoever built the walls before you made everything square. As the old adage goes, "Measure twice, cut once. Measure once, cut twice." Measure across the bottom, measure across the top, measure both sides top and bottom. I found out my back wall was slightly wider at the top than the bottom, and because I had only measured at the bottom I ended up having to re-cut a few tiles to be slightly longer.

Speaking of measurements, I hate feet, inches, and fractional inches. I wish everything would just switch to metric. For example, you need to cut a tile to fit in a space (2 foot 5 and 3/4 inch - 2 inch - 10 and 7/16 inch - 15 and 7/8 - (4 x 3/8 inch)). Easy peasy, right?

The way the pattern was going up the wall I had a bunch of different sized pieces cut for going along the corner of the wall. I found it useful to write the sizes on the back of the tile as I cut them so that it was easy to grab the right piece as I was putting them into the pattern.

We tried two ways of cutting the tiles. These tiles are roughly 8 inches by 16 inches, roughly 20 by 40 cm. For most of the cuts I used a manual tile cutter, it has a blade that scores the tile and then you press down on a handle and it cracks the tile along the scoring. Super simple, it took about ten seconds per cut and they turned out nice and clean. The place where it did not work was if I needed to cut a very small edge off a long tile, like the top row of tiles where I needed to take off less than an inch for the length of the tile. What would happen was either the cut would only come off part of the way or the whole tile would crack in half. So for these long cuts I borrowed my brother-in-law's angle grinder and used a ceramic cutting blade. You could rent a water cooled table tile saw from the hardware store for about $50 for a few hours to do this and it would probably turn out neater; using the hand-held angle grinder the cut was a bit rougher that the other cuts. If I could start over again, I would shift the pattern up by about half a tile so that the cuts would be in the middle of the tile instead of right along the edge.

It is better to get a little more tile than you think you will need based on measurement of the wall than to try for an exact amount. It may cost a couple more dollars to get that extra tile, but if you are trying to make the tiles fit in a pattern you will end up cutting a few inches off some of them, and then you end up realizing that you are one edge tile short in the evening when the hardware store is already closed. I also (as I said above) cracked a few tiles while trying to cut them.

So on to putting up tile. You spread the mortar on the wall, spread some on the back of the tile, and put some lines of mortar on the wall using the notched side of the mortar trowel. We found this is a place where having two people working makes it go much quicker - one person can be putting mortar on the wall while the other person puts mortar on the tile. The thing to keep in mind is that the mortar dries fairly quickly, and so if you are stopping at the end of the night or to do some more cutting and you leave those lines of mortar they will dry and then you won't be able to get the next row of tiles to lie flat against the wall. So before you leave use the mortar trowel to scrape off any excess mortar and leave it smooth for when you come back to start working again. The first night when we stopped I did not do that, so the next morning I took a chisel and spent about fifteen minutes carefully scraping off the dried mortar lines to get back to a smooth surface for the next row of tiles.

  1. There is another contractor that we have hired in the past and he does really good work and we would have hired again, but he is booked out a year and a half and we wanted this done right away. []