A Subtle Python Bug

Feb 23, 2018

I recently had a very subtle bug with an OrderedDict in my Python code at work. I constructed the contents of this object from a SQL query that was output in a specific order (can you spot the bug?):

qs = models.MyModel.objects.all().order_by("-order")
data = OrderedDict({x.id: x.name for x in qs})

My expectation was output like the following, which I was seeing on my development system (Python 3.6):

OrderedDict([(4, 'Four'), (3, 'Three'), (2, 'Two'), (1, 'One')])

However, on my official sandbox test system (which we use for internal testing, running Python 3.5), I was seeing output like this:

OrderedDict([(1, 'One'), (2, 'Two'), (3, 'Three'), (4, 'Four')])

There are actually two issues in play here, and it took me a while to figure out what was going on.

  1. First, I'm constructing the OrderedDict element incorrectly. I'm using a dictionary comprehension as the initialization data for the object's constructor. Dictionaries are (until recently) not guaranteed to preserve insertion order when iterated over. This is where my order was being screwed up.
  2. Second, the above behavior for dictionary order preservation is an implementation detail that changed in Python 3.6. As of 3.6 (in the CPython implementation), dictionaries now preserve the insertion order when iterated over. My development system, running on 3.6, was therefore outputting things as I expected them. The sandbox system, still running 3.5, did not. What an annoyance!

I've learned two valuable lessons here: (a) make sure you're running on the same levels of code in various places, and (b) don't initialize an OrderedDict with a dictionary comprehension.

As I age, my vision is getting worse (and it's already pretty bad). At work, I use a three monitor setup: my laptop is the middle screen, and two external monitors sit to either side. Given the large screen real estate, and given my increasingly bad eyesight, I've been having a tough time finding my mouse pointer. Windows has an option to show the location of the mouse pointer when you press the Ctrl key, but that has limited usefulness (though I do use it from time to time).

I recently stumbled upon a neat feature in Windows 10 that has helped me tremendously. There are several mouse-specific features in the Ease of Access section of the Windows settings. The pointer size can be adjusted (which is helpful to a degree), but the most helpful feature is the Pointer Color setting. There's an option to adjust the pointer color based on whatever color is beneath it. It took a little getting used to, but I can now find the mouse pointer a lot easier than I could before.

I have always liked a good flashlight. As a kid, I even asked for a 5-cell D Maglite for Christmas (which Santa brought!). This past December, I picked up the ThruNite Archer 2A flashlight from Amazon, based on a review from The Wirecutter. At $30 it's not cheap, but boy is this thing great.

It uses two AA batteries and puts out an incredible amount of light. There are four brightness settings, ranging from dim (great for when your eyes are adjusted to the dark) to blindingly bright. I also like the fact that it's compact; you could easily store this in a bag, car console, or junk drawer without taking up much space.

Since I bought it, I've put it to use in a number of ways (looking for dropped items in the car, using it on walks at night, and hunting under furniture for lost cat toys). I highly recommend this spectacular flashlight.

This post serves as a notice that all Firefox content on this website has been removed. This includes:

  • CoLT
  • Googlebar Lite
  • Firefox Toolbar Tutorial
  • Firefox Profile Tutorial
  • Automatic Extension Updates Tutorial

All links to that content should now redirect to this notice statement. If you're looking for information on the above, here are a few external references for your use:

I have removed my Firefox toolbar tutorial from this site, since it is now woefully out of date. If you're looking for Firefox extension development information, turn to the official documentation.

I have a fairly old bread machine (late 90s / early 2000s model) that I use all the time. A few years ago, my dad found a great recipe for bread machine cinnamon rolls that he shared with me. After a minor tweak or two from the original, we've hit upon one of the best cinnamon roll recipes I've ever tried.

Wet Ingredients

  • 1 cup warm milk
  • 2 eggs
  • 6 Tbsp butter

Dry Ingredients

  • 1 tsp salt
  • 1/3 cup white sugar
  • 4 cups bread flour
  • 1 Tbsp yeast

Put all ingredients in the machine in the typical order (most machines call for wet first, then dry). Use the 2-pound dough setting, and let the machine do its thing. Once the machine is done, dump the dough out onto a flat surface (lightly floured if you like to avoid sticking). Roll the dough into a rectangle about 1/4 inch thick.

Filling

  • 2 Tbsp softened butter for spreading
  • 1/4 cup brown sugar
  • 1/4 cup white sugar
  • 2 Tbsp cinnamon
  • 1/2 cup raisins (optional; golden raisins are particularly good)

Spread the butter on the rolled out rectangle, and then sprinkle the sugar/cinnamon mixture on top of the butter. Also add the raisins (if using them). Roll the rectangle into a tight log (starting with long edge) and keep the seam side down to keep it sealed. Cut the log into the desired pieces (I typically get about 15 or so of these at about 1/2" or so thick), and place them in greased pans. Let rise in a warm place for 30 minutes to 1 hour. Bake at 350° for 10 to 15 minutes, or until golden brown.

Icing

  • 1 cup powdered sugar
  • 1/4 tsp vanilla
  • Enough milk to make it thick (this is the tricky part)

I typically use about 1 Tbsp of milk, but it's an art form to guess-timate the right amount. You don't want the icing too thick, and you don't want it too runny. I always double the icing recipe above because I love icing (if I can see the bread of the cinnamon roll, I don't have enough icing on it). Enjoy!

As of today, I am officially withdrawing my development support for the Googlebar Lite Firefox extension. I'm aware that the extension no longer works well in the latest builds of Firefox, and I have absolutely no desire to fix them. Mozilla's development environment has gotten pretty irritating as of late, and I just don't have the cycles (or the drive) to fix the issues that exist.

The future of Firefox add-ons lies in WebExtensions, and toolbar support in that arena is pretty bare-bones (last I looked). The default Firefox search box meets most needs, which has motivated me to drop this extension.

For those that are so-inclined, I will accept pull requests at the official googlebarlite repo. Or, you can fork the project and roll your own.

Back in March of 2010, I mentioned that I had a goal of visiting and photographing every single state park in my home state of North Carolina. In May of that same year, I narrowed my definition slightly to be those parks that have public facilities and for which attendance records are taken. At the time, there were 40 such parks (another has since joined their ranks, for a total of 41 as of this writing).

On Saturday, October 29, after over six years of park visits, I finally completed my goal!

My final state park visit was at Hammocks Beach State Park, the only park with ferry-service to its primary land parcel, Bear Island.

One question I'm often asked when sharing my love of state parks with others is: which park is your favorite? This is a really difficult question to answer, as every single park in our state has something unique to offer (which, incidentally, makes visiting them all so worthwhile). That said, I thought it would be fun to rank some of the state parks from the viewpoint of my favorite park pastime: hiking. In this post, I'll provide a breakdown of my favorite parks to hike in for all three regions of our state: mountains, Piedmont, and coast. I'll also post a list of my least favorite parks for hiking.

Best of the Mountains

North Carolina is blessed with terrific mountain state parks. Here are my favorite mountain state parks to hike:

  1. Gorges: The westernmost park in our state, Gorges is my favorite mountains park. It has a particularly beautiful visitor's center, and though the hikes are very challenging, they offer some of the most beautiful scenery in the state as a reward.
  2. Stone Mountain: Hiking up the giant granite dome is one of the most enjoyable things to do at this fantastic park. Views from the top are great, especially on a clear day, and several waterfalls can't be missed!
  3. Pilot Mountain and Hanging Rock: These two parks are a tie for me. Both have challenging, but rewarding, hiking trails, fantastic views, and lots to do. Regardless of the season you visit, there's always something fascinating to see.

Best of the Piedmont

The Piedmont area of North Carolina is typically very heavily forested, which makes for some great spots to walk in the woods. Here are my favorite Piedmont parks:

  1. Eno River: Easily my favorite Piedmont state park (probably because of its proximity to where I live), Eno River has the best network of diverse hiking trails. For an area that has so many people, this park offers a terrific slice of solitude.
  2. Raven Rock: A popular park with some great trails to interesting geological features. The staircase down the namesake cliff is quite lengthy, so come prepared for a climb!
  3. Weymouth Woods-Sandhills Nature Preserve: This small park is a hidden gem. The hiking trails here are very easy, winding through a very unique long-leaf pine forest. Underbrush in this forest is nearly non-existent, which means you can see a long ways through the stands of trees. Definitely a park not to be missed!

Best of the Coast

Some of the most unique state parks in North Carolina are located along the coast. Here are my favorites:

  1. Jockey's Ridge: Walking up the tallest living sand-dune on the east coast of the United States is something everyone should do. Just be sure to have your shoes on in the summertime: the sand can get quite hot!
  2. Goose Creek: Tucked along the Pamlico River, this park has an impressive boardwalk system. Strolling these boardwalks makes for some terrific sightseeing, and provides a glimpse at what natural life is like in the swamp along a river. Another hidden gem!
  3. Carolina Beach: Have you ever hiked in a forest at the beach? You can do so at this state park, where you'll also find carnivorous plants in their native habitats. Keep your eyes peeled for Venus fly-traps and pitcher plants!

Honorable Mention

Of all the state parks I've visited, I had more pure fun at Merchants Millpond than any other. Canoeing in the millpond there is a delight, especially on a comfortable day. You'll see plenty of wildlife (including alligators!) and you won't want the experience to end. This park has good hiking opportunities too, so it's win-win.

My Least Favorites

Three state parks truly stand out in my mind for least impressive hiking opportunities:

  1. Pettigrew: With only one hiking trail (and a poorly maintained one at that, at least when I visited), this park isn't for hikers. If you like boating, however, you'll love the lake at this park, which happens to be North Carolina's second largest natural one.
  2. Lake Waccamaw: Again, this is primarily a boater's paradise. Hiking here is difficult (the trails aren't very well maintained), and the hike isn't very interesting.
  3. Singletary Lake: This park is only open to large groups, so hiking here is a challenge. The trails that are offered, like many lake-centered state parks, are fairly short.

I hope you've enjoyed this round-up of my visits to various North Carolina state parks. I encourage everyone to visit them all, as it's a great way to see our beautiful state!

Green Chicken Soup

Oct 10, 2016

I grew up eating this soup, which also goes by the name chicken soup with herbs. My family, however, called it "green chicken soup" because the soup has a greenish hue to it. This is a favorite!

  • 2-3 cups diced, cooked chicken
  • 1 cup raw rice
  • 1/2 cup plain flour
  • 1/2 cup butter
  • 2 cups milk (*)
  • 2 cups cream (*)
  • 4 cups chicken stock
  • 4 tsp. chives
  • 4 tsp. marjoram
  • 2 tsp. dill weed
  • 1/4 tsp. nutmeg
  • 1/2 tsp. turmeric
  • Salt & pepper to taste
  • Green onions (optional)

(*) Can substitute 1 quart of half-and-half for these two ingredients

Start by cooking rice separately. We do this by combining 1 cup of rice, 2 cups water, and 1/2 Tbsp. salt in a Pyrex cooking dish, covered, microwaving for 18 minutes on 50% power.

While rice is cooking, and in a large saucepan, dutch oven, or boiling pot, melt butter and blend in the flour. Cook this roux for one minute. Add the milk and cream and, stirring constantly, cook until the mixture thickens. Add the chicken stock, cooked rice, chicken, chives, marjoram, dill, nutmeg, and turmeric. Green onions may also be added, if desired. Stir well. Season to taste with salt and pepper. Can be garnished with chopped parsley and/or toasted sesame seeds. Pairs well with hearty breads.

This soup is very thick (more like a stew), so when reheating it, you may need to thin with milk or water (it thickens as it sits in the refrigerator).

Last week, while on vacation in the northwestern corner of the United States, I was notified by a few people that my article Stack Overflow Hates New Users had made it onto a news site I was previously unfamiliar with, hackernoon (actually, the article was a part of a longer piece entitled The decline of Stack Overflow). It's rather amusing that an article I wrote over four years ago is still being cited by people, and I think that says a lot about the community surrounding the venerable question and answer site. I've been a user at said site for over four and a half years, and I have a few additional things I'd like to discuss.

Seeing as I have already written about things I learned using Stack Overflow, a list of my gripes with Stack Overflow, and a few suggested improvements for Stack Overflow, I won't rehash those here. What I would like to talk about, however, is how I think new users should approach the Stack Overflow experience:

Search, Search, and Search Again

I cannot stress this point enough. Before you ask a question on the site, search it to see if a similar question has already been asked. Over 95% of the time, at least one person will have already asked a question that should point you in the right direction. Don't use the built-in search, by the way; like many site search boxes, it's pretty lousy. Search with Google using the site:stackoverflow.com operator, and include any relevant keywords that could narrow your search (searching is an art form and non-trivial!).

Ask Detailed Questions

This is probably the biggest mistake new users make: they don't provide enough detail. Asking detailed questions takes some practice to master (I still haven't mastered this). Before you click that "Ask Question" button, ask yourself these questions:

  1. Is my question clear, concise, and easy to read?
  2. Have I mentioned what I've tried in the question I'm about to post?
  3. Have I provided all relevant details about my question (any specific library versions, or specific database flavors, or the operating system in use, etc.)?
  4. Do I have an idea of the direction to head, or am I flying blind? Have I made it known in my question that I know (or don't know) where to go?
  5. Where else have I looked for solutions? Did I mention these in my question?

Being short and to the point, yet detailed, is a difficult balance to achieve, but find that balance and you'll reap the rewards.

Be Patient

It's very difficult to get a lot of rep points in the beginning, so be patient; building trust takes time. Set mini-goals for yourself. I personally set a goal to get to 2000 rep points so I could edit other posts without having to have my edits approved. Once I reached that goal, I stopped worrying about points altogether (it's not worth worrying about)! Also, be courteous to everyone, even the jerks on the site (of which there are a number). Know-it-alls tend to like to flaunt their intelligence, and Stack Overflow is an outlet through which they can scratch that itch.

Join a Sister Site

I'm a big fan of Arqade, a sister site to Stack Overflow focused on video games. The community there is much more friendly and welcoming, and if you earn enough reputation at a site like that (only 200 points), you'll automatically get 100 bonus points on every other Stack Exchange site!

Stack Overflow is a great resource to use, but it's one that I keep at arm's length. These days, I tend to ask more questions than I answer, and I often find answers to questions I have through other people's postings. It's easy to get swept up in the competitiveness of the site at the beginning, but if you avoid doing that, you'll have a much more pleasant experience.

Contact Form Issues?

Mar 26, 2016

I've seen a couple of different reports here that the contact form isn't working properly. That said, the form seems to work for me in the latest versions of Firefox, Chrome, and IE. If you have tried to contact me via the form and gotten an error, please leave a comment with this post. I'd love to know what browser you see the issue in, and what the error is. Thanks.

Securing Born Geek

Feb 7, 2016

This website now enforces the use of https, thanks to the Let's Encrypt initiative and the good folks at DreamHost. I initially had a number of problems in getting WordPress to behave, but I found this helpful article that pointed me in the right direction. I believe the bit of magic that helped me was running the wp CLI tool:

wp search-replace https://borngeek.com https://borngeek.com --precise --recurse-objects

Things now seem to be working, though if you spot a problem anywhere, let me know.

Commenting Fixes

Jan 21, 2016

The commenting system on this site was throwing some nasty errors, as I found out this morning. They were due to an outdated comment spam plugin I was using. I have removed the offending plugin, replacing it with another, so commenting should work once again.

Pasta e Fagioli Recipe

Dec 29, 2015

This delicious recipe was sent to us by my wife's grandmother. It's incredibly tasty!

  • 1 and 1/2 tsp oil
  • 1 lb ground beef (or turkey)
  • 6 oz onion; chopped
  • 7 oz carrots; slivered (a bag of shredded carrots also works)
  • 7 oz celery; diced
  • 24 oz tomatoes; canned, diced
  • 1 can red kidney beans
  • 1 can white kidney beans or cannellini beans
  • 44 oz beef stock
  • 1 and 1/2 tsp dried oregano
  • 1 and 1/4 tsp pepper
  • 2 and 1/2 tsp fresh chopped parsley
  • 3/4 tsp Tabasco sauce
  • 24 oz spaghetti sauce
  • 4 oz dry pasta ditalini (or any other small pasta)

Saute beef in oil in large 10 qt pot until beef starts to brown. Add onions, carrots, celery, tomatoes, and simmer for about 10 minutes. Drain and rinse beans and add to the pot. Next, add beef stock, oregano, pepper, Tabasco, spaghetti sauce, and pasta. Add chopped parsley. Simmer until celery and carrots are tender, about 45 minutes to 1 hour. Makes 4.5 quarts of soup.

Pulled Party Pork

Nov 8, 2015

My wife was sent a recipe by a family member down in Florida that's really good. This recipe comes from the Junior League of Tampa, and I'm transcribing it here just in case their electronic copy ever disappears.

  • 1 (3-lb) pork tenderloin or Boston butt roast
  • 1 cup water
  • 1 (18 oz) bottle prepared BBQ sauce
  • 1/4 cup packed brown sugar
  • 2 tablespoons Worcestershire sauce
  • 1 teaspoon each salt and pepper

Combine the pork and water in a slow cooker. Cook on high for 7 hours. Drain, reserving 1 cup liquid. Shred the roast in the slow cooker with a fork. Add the remaining ingredients. Add the reserved cooking liquid if necessary. Cook on low for 1 hour. Serve on rolls for sandwiches if desired.

Contact Form Fixed

May 4, 2015

Well, that was fast! I've found the problem with the contact form and corrected it, so emails should now actually make it to my inbox. Apologies for the problem!

I discovered this morning that my site contact form is not working properly. I will investigate why and hope to have a fix in place soon. Until then, if you've sent me an email recently, I likely didn't get it. Feel free to leave a comment here or email support at borngeek dot com. It's been fixed!

Lenovo Thinkpads have an on-screen display for various hot-keys. For example, when you change the monitor brightness, or the volume level, an on-screen overlay will display showing the current brightness level or volume level, respectively. Twice, I have received laptops from Lenovo that have this software installed, but the on-screen display never appears. Frustrated by this bug, I used the Dependency Walker to troubleshoot this problem a while back, and subsequently found the solution.

Simply install the Visual Studio 2010 C++ redistributable, available from Microsoft (make sure to install the x86 version, even on a 64-bit system; the on-screen display application is a 32-bit process). Once this package is installed, and the laptop rebooted, the problem should go away.

Brown Sugar Saver

Mar 25, 2015
Brown Sugar Saver

I've been meaning to post about this for a while now, because this product is as close to black magic as I've ever seen, even though I know the theory of how it works. My wife and I picked up a Brown Sugar Saver from Sur La Table while at our local mall a few weeks ago. We had a container of brown sugar that was literally as hard as a rock. Various metal implements were unable to pry the concrete-like material from its container, so we decided we'd give this a try.

The Brown Sugar Saver is simply a piece of terracotta pottery; nothing more. You soak the small medallion in a dish of water for 15 minutes, remove it, blot it dry with a towel, and place it directly in the container with your brown sugar. We did this, and in the morning found that our brown sugar was just as soft and pliable as it would be had you just opened a fresh bag of the stuff! Needless to say, we were really surprised. It only cost $4, and has solved an annoying problem that I've lived with for far too long. I highly recommend this thing (you can buy similar ones in a number of places).

GitLab defaults its time zone to UTC, which may not be what you want. Thankfully, you can update the value directly from your gitlab.rb file. Here's the relevant line:

gitlab_rails['time_zone'] = 'America/New_York'

Once you've added the field, simply reconfigure and restart:

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

A list of all the available timezones is available on Wikipedia.