NB

Husband, Father, and Solver of Problems.

    Dangerous "As" – Typescript

    Thu Dec 17 2020

    TL;DR

    Do This:

    const car: Car = someObj
    

    Not This:

    const car: Car = someObj as Car
    

    Or This:

    const car: Car = <Car>someObj
    

    I'm still pretty new to Typescript,

    and until today I thought that I should type my objects this way:

    const car = {
      color: "RED",
      drivetrain: "AWD",
    } as Car
    
    interface Car {
      color: string
      drivetrain: "AWD" | "2WD" | "4WD"
    }
    

    It wasn't until I was seeing undefined property errors that I decided to take a look at what the "as" keyword is actually doing here. Up until this point, I thought that what I was doing was typing const car to the interface Car. What the as keyword actually does, is forces whatever object I'm defining into that type.

    What makes this dangerous, is that when you typecast an object like this, the compiler will not warn you of missing properties and will give you a false sense of security because you're not seeing compilation errors. For example, this will still compile even though we didn't include a color property:

    const car = {
      drivetrain: "AWD",
    } as Car
    
    interface Car {
      color: string
      drivetrain: "AWD" | "2WD" | "4WD"
    }
    

    With this in mind here's the code above written in a type-safe way:

    const car: Car = {
      color: "RED",
      drivetrain: "AWD",
    }
    
    interface Car {
      color: string
      drivetrain: "AWD" | "2WD" | "4WD"
    }
    
    How to find available IP addresses when DHCP isn't working (Guide for Macs)

    Wed Dec 16 2020

    I needed to set my laptop to a static ip because the router's DHCP service wasn't issuing me one regardless of how many times I renewed it. I found this Stack Exchange Article that featured a really handy terminal command:

    ifconfig | grep broadcast && arp -a
    

    This produces a list of all devices (and their IPs) that respond to the broadcast. My network was pretty small, and the IPs are in order so you can find a gap that doesn't seem to have a device and try it out.

    ThreeSixty

    Sat Sep 12 2020

    Today I did a weird and silly thing.

    Vegan Szechuan Celery Squash

    Sat Sep 12 2020

    A delicious alternative to the Szechuan Eggplant I love to order that answers the question: "What do I do with all of this celery?"

    Ingredients:

    • 1 Tbsp Sesame Oil
    • 1 Tbsp Walnut Oil
    • 1 Tbsp Coconut Oil
    • 1/2 Tsp Red Pepper Flakes
    • 2 Tbsp Fresh Grated Ginger (Divided)
    • 4 Cloves Garlic (Divided)
    • 2 Tbsp Corn Starch
    • 6 Stalks of Celery 4 stalks diced, 2 stalks sliced diagonally
    • 2 Large Carrots
    • 1/8 cup Dark Soy Sauce
    • 1/8 cup Light Soy Sauce
    • 2 TBSP Maple Syrup
    • 1/2 cup frozen peas

    Phase 1 Preparation

    • Heat sesame oil over high heat until shimmering.
    • Add two peeled and crushed cloves of garlic, 1 Tbsp grated ginger and stir and cook until garlic is blackened.
    • Add walnut oil and diced celery, sliced squash, and sliced carrots to pan to stir fry.

    Prepare Sauce

    • With a whisk or immersion blender add red pepper flakes, 2 cloves of minced garlic, light and dark soy sauce, maple syrup, coconut oil, and corn starch. Mix thoroughly.

    Combine

    • When the squash is soft from stir frying for approx. 8-10 minutes, add the sauce mixture and sliced celery to the pan. Stir until all veggies are thoroughly coated with sauce.
    Seasons

    Thu Sep 10 2020

    For several years now, I have observed a tendency in myself. I go through seasons of incredible motivation and seasons of an incredible lack of motivation. It sounds like it could be Bipolar disorder, though I don't think I can really diagnose this in myself. Besides, I'm not convinced that it's something worth knowing for sure. I did think it would be interesting to use the blog as a little bit of an experiment. Blogging daily no matter how big or small is something I believe I should be able to do as long as I stay motivated. I believe that the amount of content I put fourth on my blog may serve as an indicator of the kinds of mood cycles I got through, and may also be useful for for someone diagnosing me in the future.

    View more posts