Tag: syndicated

  • 2020 Advent of Code–Day 4

    This series looks at the Advent of Code challenges.

    As one of my goals, I’m working through challenges. This post looks at day 4. I’m going to do this one in Python here, though I did solve it in other languages in my repo.

    Part 1

    We have another string parsing operation. We get a series of lines that represent a passport. Passports are separated by blank lines. Therefore, we can get 1-x number of lines representing a passport.

    Ugh.

    Python seems like a good place to start here. I loaded the file and then started to concatenate rows of data until I found a blank one.

    file_handle = open('2020\day4\day4_data.txt', 'r')
    passports = file_handle.readlines()
    part1 = 0
    currpassport = ""
    for row in passports:
    if row not in ['\n','\r\n']:
            currpassport += row.replace('\n',' ')
    #print(currpassport.split(" "))

    else:

    At this point, I have a passport I can look at, with all the various sections. I used another split, this time into a dictionary to get each item separate.

    currdict = dict(x.split(":") for x in currpassport.split(" ") if x)

    Now, I can count these. If there are 8, or if there are 7 and CID is one of them, I have a valid passport. Adding these up gets me the answer.

    Part 2

    This is very similar, but each part now needs validation. So, I take the same structure, but once I have passports, I assume they are valid and start to check each section. It’s really a series of IF statements for me.

                valid = 1
    if ((int(currdict["iyr"]) < 2010) or (int(currdict["iyr"]) > 2020)):
                    valid = 0
    if int(currdict["byr"]) < 1920 or int(currdict["byr"]) > 2002 :
                    valid = 0
    if int(currdict["eyr"]) < 2020 or int(currdict["iyr"]) > 2030:
                    valid = 0

    These each could be functions, and I’d refactor that way, but I couldn’t come up with an easier way to do this. After checking if I have enough valid items, I tally another passport (or not).

    Overall, this felt like busy work, not hard, but just a grind through each set of validation.

  • Daily Coping 28 Apr 2021

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag. 

    Today’s tip is to focus on a eating a “rainbow” of vegetables today.

    I like cooking. I find it relaxing, especially when I’m not rushed and can have a glass of wine while I work. Most days now it’s just my wife and I, and she is a good influence in trying to get me to cook a little healthier.

    Recently I found a recipe for Primavera Stuffed Chicken a few weeks ago and decided to try it. My oldest son was coming by for dinner, and I knew he’d enjoy it as well. I spiced it up by adding some yellow squash and asparagus as well, getting some more vegetables in there. With a salad that had some purple leaves and colored tomatoes, I think I got a nice rainbow.

  • Daily Coping 27 Apr 2021

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag. 

    Today’s tip is to pick a new musical artist and listen to a few songs today.

    I love music, and a few of my coping tips have noted that. One thing I used to do when I traveled on planes by myself was download a few albums from one artist and listen on the plane. It might be someone I knew a few songs from, or someone recommended to me.

    For this tip, my wife turned me on to PJ Morton, who reminds me of Stevie Wonder. I downloaded a few albums of his the last time I flew in 2019.

    On Spotify, there’s a “Fans Also Like” section for artists, and I decided to try someone else that was on that page for PJ Morton. I found Jonathan Nelson and gave him a try. It’ s a little more gospel/spiritual than I like, but not bad.

    I also ran through an album from Ledisi, which is softer, quieter, and relaxing. I really enjoyed her.

  • Expanding Inclusion and Diversity – Better Linking

    I’m a native English writer/speaker. Some might debate how well I really know the language, but I am a native. I wasn’t a good student of languages. I struggled with Spanish I, took 4 years of Japanese in college, and wasn’t sure I really learned a lot.

    I tried to learn some Spanish when my wife hired someone who had that as a native language and struggled with English. I didn’t apply myself well and struggled. I also tried some Italian when my boss was learning, but again, continuity was an issue. However, the pandemic changed some of that, as I’ve been working on a streak with Duolingo, back in Japanese and practicing with my son, as well as doing French with my daughter. So far, I’m nearly at a year of some daily practice.

    What does this have to do with diversity and inclusion? It has a little to do with it, and a new habit I’m going to try and build.

    The other day I saw a tweet from @SQLChick: “I learned something cool! You know how Microsoft Docs are localized? We can tell because it’s in the URL. For me, that path includes “en-us/” and if I remove that, the Docs site adds it back when I visit the page. Removing it is better for link sharing with a global audience.”

    That’s a good idea. I’ve known this was the structure for MS Docs, but I hadn’t thought about it.

    I hadn’t thought about inclusion here.

    I often assume most developers know English, at least from the code standpoints. Most languages are implemented in English, and lots of software doesn’t get translated. However, that is changing, and I know companies are thinking about localizing things more and more.

    As they should.

    So, my challenge to myself, and you, is to grab links and make them local where possible. As an example, I was looking up this link the other day:

    https://docs.microsoft.com/en-us/sql/t-sql/queries/select-order-by-clause-transact-sql?view=sql-server-ver15

    If I remove the “/en-us” part, I get this:

    https://docs.microsoft.com/sql/t-sql/queries/select-order-by-clause-transact-sql?view=sql-server-ver15

    If I drop that in a new browser, it reverts to the English version, but if someone has their local system set for French, or Japanese, or Spanish, they get that version. The link works for them, rather then dropping into my language.

    It’s not necessary, but it’s polite. Something worth doing a bit more of all the time.