Stephen Guerra – The uShip Blog https://ushipblogsubd.wpengine.com Wed, 12 Oct 2022 21:22:02 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.2 Father’s Day for coders: Daddy Developer Tech Tips https://ushipblogsubd.wpengine.com/shipping-code/fathers-day-for-coders-daddy-developer-tech-tips/ https://ushipblogsubd.wpengine.com/shipping-code/fathers-day-for-coders-daddy-developer-tech-tips/#comments Sun, 19 Jun 2016 08:04:24 +0000 https://ushipblogsubd.wpengine.com/?p=4511 Recently, my time has been a little pre-occupied. Not so much because of all the awesome new technical innovations I have been able to work on lately like microservices in .NET, nor because of the awesome new features happening in .NET that is causing a revolution in the linux space, but instead, it is because... Read More

The post Father’s Day for coders: Daddy Developer Tech Tips appeared first on The uShip Blog.

]]>
Recently, my time has been a little pre-occupied. Not so much because of all the awesome new technical innovations I have been able to work on lately like microservices in .NET, nor because of the awesome new features happening in .NET that is causing a revolution in the linux space, but instead, it is because of this guy:

Sleeping Baby

I wonder if he is dreaming about code too…

In the past few months, I have had the great honor of becoming a father. And fun and exciting as that may be, I have to admit, it is a bit of work that takes away from a lot of time and energy.

In case you find yourself in a similar world, I am here to help by sharing a few of the awesome tidbits I have come across that make having a baby manageable in the demanding world of the tech industry.

Let’s get started…

Tablets EVERYWHERE

Daddy reading tablet

OMG, how did we exist as a species without these things!? Initially they were a blessing as I ended up being stuck in the hospital with nothing to do while my wife suffered and cursed me I went through the magic and miracle of birth. Only later, after our baby was born did I realize a tablet’s true magic!

Harry Potter on Tablet

Real Magic!

I can lookup an immediately needed baby treatment. Or when I find myself bored as I walk around a room consoling my son, I can read tech news/books! Useful tip: read enthusiastically to your child, even if it is not “The Happiest Little Elf”, just the fact that it is interesting to you (like this blog hopefully) will pique your child’s interest by your enthusiam.

Microservices Book

The daddy monolith then posted to the baby service…

My favorite thing about tablets: with inventions such as swype, you can still do basic work/email/chat and once again feel productive!

Luckily I was able to buy a few different brands of cheap tablets before the baby was born. Keep in mind, you have 9 months to buy tablets, so keep an eye out for sales, especially on deal sites such as woot.com or during Christmas (the kindle fire is almost a dead ringer for a sale for less than $35 at least twice a year).

Start reading “dad” books on your tablet!!!

 

Book Be Prepared

A life saver for me was the book “Be Prepared”. A friend recommended it when we announced, and being a former boyscout, I must admit I was nowhere near as prepared as I thought I could be, but this book has had my back when I have needed it. I must admit, in this day and age, there really is no excuse for dads not to read something about parenthood with the availability of so much information.

The best part about this book: it tells you the things you really care about, like how to stop a baby’s crying, how to change diapers without getting poop everywhere, or how to sleep (spoiler: you don’t… just kidding, but it does have some good tricks for the worst of nights).

Broken up by age in months, and being a short read, it feels like I am reading cheat codes for parenthood.

Mortal Kombat babality

Even nurses at the hospital asked where I had gotten my “experience”, whether it was from other children or having lots of siblings. Luckily my wife was there to inform them I cheated.

Use a standing desk AND a baby carrier at the same time

As developers, I think most of us are pretty used to the fact that we live a sedentary lifestyle almost to the point of sloth. As such, we have learned that standing desks are the “supposed” cure for our lethargic lifestyles.

Despite my unwillingness to conform to the new norm of standing desks, I must admit, it is not that bad when you are forced down that path.

StandingDesk

Luckily I was able to find a few tidbits from Jimmy Bogard’s blog on how to setup a standing desk. I also was able to find some cheap chromebooks online, so this turned out to be a lot simpler than I imagined with my kitchen bar meeting my needs without having to go and get a lot of equipment from ikea (so far).

Also, if you find it too hard to concentrate and work with a baby on you, I have come to find that Star Wars Battlefront has the advantage of having perfect star wars lullabies and rocking movements that work for those middle of the night wakings as well.

Daddy baby gaming

Assume there’s a Technology for that

Magic Merlin Sleep Suite

Conclusion

The above are just a few of the awesome little tricks I have come across with the help of technology, but I will be needing more in the upcoming months. As such, if you do find you have any tips, please share them in the comments!

And most importantly, Happy Father’s Day to all the dads out there!

Smiling BabyDad and son

The post Father’s Day for coders: Daddy Developer Tech Tips appeared first on The uShip Blog.

]]>
https://ushipblogsubd.wpengine.com/shipping-code/fathers-day-for-coders-daddy-developer-tech-tips/feed/ 1
April Fools – Developer Style https://ushipblogsubd.wpengine.com/shipping-code/april-fools-developer-style/ https://ushipblogsubd.wpengine.com/shipping-code/april-fools-developer-style/#respond Fri, 01 Apr 2016 10:50:05 +0000 https://ushipblogsubd.wpengine.com/?p=4301 Here at uShip we are pretty big fans of open sourcing code. At the same time, we are also fans of a good ol’ prank. Hence, we have decided to open source a few of our favorite code pranks to share with the world (and just in time for April Fool’s Day). But first, a... Read More

The post April Fools – Developer Style appeared first on The uShip Blog.

]]>
Here at uShip we are pretty big fans of open sourcing code. At the same time, we are also fans of a good ol’ prank. Hence, we have decided to open source a few of our favorite code pranks to share with the world (and just in time for April Fool’s Day).

But first, a few ground rules:

We believe in following Isaac Asimov’s first two rules of robotics, roughly, you can’t harm anyone with your prank, and you can’t harm their computer
Make sure others are okay with what you are about to do. Generally if you have a great culture like here at uShip, you will find that innocuous pranks are just an inevitable, natural remnant of some age-old perpetual developer-magic duel

Expeliarmus – taskkill /f /im explorer.exe
Additionally, added bonuses for pranks whereby:

The developer learns something in the end (other than to hate you)
The prank is either horribly complex or involves a lot of patience

Also note, for brevity’s sake, we kept most of the below examples in Windows and .NET, but feel free to rant about that in the comments.
Let’s get started…

Change Compile Time Constants

aka
π = 3
In 1897, Indiana for some reason thought it was a good idea to redefine ? as 3. We feel that you should express this idea to your fellow developers as well.

How it works:

 

In some languages like C#, you can override almost any code in the Assembly Info class. Although normally this can be done for any sane reason (of which there are few), we just decided why not have a little fun with the static Math functions instead?

Show me the code already!!!
using System;
namespace IndianaPi
{
class Program
{
static void Main()
{
Console.WriteLine(“PI is {0}”, Math.PI);
Console.WriteLine(“Press any key to continue…”);
Console.ReadKey();
}
}
}

The Trick:
// In AssemblyInfo.cs, located under the Properties folder for any project
internal class Math
{
public static double PI =3.0;
}

Note: One can also use this for enforcing good coding practices as well, although there are likely better means to do so, such as lint or ReSharper code formatting instead.

 
Startup Scripts
aka
What the heck is that sound!!!??

Recently, one of our favorite developers – Jordan Patapoff – left uShip to go and start his own startup Clyp.  Lucky for us, he knows enough about API’s that he left us a perfect entry-point for our next prank.

How it works::

Using Clyp’s API, and a quick script to open a media file, one can have a random media clip played on demand. Then by adding this new script to a user’s startup folder, we are able to give them a nice little surprise whenever they log in.

Show me the code already!!!

Registry Key Rebinding

aka
How-the-hell-do-I-fix-this?
One of the most awesome things windows allows is replacing one key with another. This can have a few purposes, from when a key just randomly falls off your laptop keyboard when riding your bike, to when you just hate a key and want to annihilate it from existence.

I’m looking at you Caps Lock!
However, we find the best usage of this feature is probably to have someone’s spacebar output dashes instead. This way you can wreak havoc, yet likely not get them locked out since rarely do people who fall for this prank use spaces in their passwords anyway.

How it works:

The below script is probably the easiest way to use the exploit (since anyone who wants to go through and manually modify the windows registry in the short amount of time it takes for someone to get a cup of coffee is either insane or the flash). Once run, restart their computer, and sit back and enjoy as they slack you “messages-such-as-this”.

Show me the code already!!!

Copy & Paste from the web
aka
These are not the scripts you are looking for

Some developers (especially those who are new to development) suffer from “just copy it from the internet” syndrome. Generally in order teach that not all code on the internet is “good code”, you can introduce them to your “found” code they should try out. Then once they copy the code blindly without even giving it a second look, they will find that you secretly had some invisible injected code hidden in the middle.

How it works:

When providing a code sample on a web page for someone to copy paste, you can insert code through the use of an invisible span. Even though the span is invisible, its contents will still be copied to the clipboard. After a little html magic, as well as an unsuspecting developer who doesn’t pay attention to what they copy and paste, the rest is history. And the end result is phenomical. The best part is that this works in ANY language!

Show me the code already!!!

 
Aliasing
aka
A rose command by any other name

I think I’m going to name you su
I think all of us as developers have become accustomed to blindly typing certain command line messages. Whether it be git commit or hg push, some developers only have production on the mind and will never give your inserted command a second thought.

How it works:

Using doskey, one is able to alias any command they want to another command. Often this is for the lazy who want to not have to type things like git push, but instead type gp. However, this also leaves the door open for those who want to add a little something extra, such as git commit -ma “<insert message>” $T git push. That is, so long as no one does anything silly like doskey doskey=echo “uh oh… now what?”

Show me the code already!!!

doskey git=git add -A $T git commit -am “I’m a little teapot” $T git pull $T git push

 

URL Redirecting

aka
The Host with the most!

No, not those guys
This one is pretty old school, but I am surprised how many developers still fall for a changed host file. As such, they will never understand when they go to their favorite sites (e.g. stackoverflow.com), then suddenly appear on some of their least favorite (although not uShip.com of course).

How it works:

Whenever a website tries to go to any url, it will always check to see if there is an override in the hosts file. However, if you happen to know of a url that can be accessed using their IP address, you can easily override any site (that is, assuming it does not redirect over https).

Show me the code already!!!

What else?

Obviously this list can easily grow, but hopefully what we have shared is enough to get you started. If you find that one of the above just isn’t good enough in its entirety, feel free to mix them up. For instance, redirect a user from stackoverflow to a place with javascript that changes their keyboard bindings!

Additionally, if you are not used to windows, be sure to try to run as administrator if you can (which is true for most developers) and running Set-ExecutionPolicy RemoteSigned if using any of the powershell commands.

And whatever you do, just be sure to be safe, have fun, and try not to let this wonderful gift of the First of April go to waste.

Feel like we are missing your favorite idea? Then leave us a comment and let us know. Or… just make a pull request!

The post April Fools – Developer Style appeared first on The uShip Blog.

]]>
https://ushipblogsubd.wpengine.com/shipping-code/april-fools-developer-style/feed/ 0
An NHibernateMARE on Elm Street https://ushipblogsubd.wpengine.com/shipping-code/nhibernatemare-elm-street/ https://ushipblogsubd.wpengine.com/shipping-code/nhibernatemare-elm-street/#respond Thu, 29 Oct 2015 10:24:36 +0000 https://ushipblogsubd.wpengine.com/?p=4213 We use (and generally like) the ORM NHibernate for MS SQL Server data access, but we understand why you might not. Ohhhh, the things we have seen! We’d like to share some of our favorite horrors, so that you can avoid them. Originally, our Repository<TEntity> base class implemented IEnumerable<TEntity>. This allowed us to do clever things... Read More

The post An NHibernateMARE on Elm Street appeared first on The uShip Blog.

]]>
We use (and generally like) the ORM NHibernate for MS SQL Server data access, but we understand why you might not. Ohhhh, the things we have seen! We’d like to share some of our favorite horrors, so that you can avoid them.


It Came From IEnumerable
Originally, our Repository<TEntity> base class implemented IEnumerable<TEntity>. This allowed us to do clever things like

    foreach (var c in CountryRepository) { /* … */ }

This simple iteration was handy, especially for reference tables (e.g., Countries, States/Provinces, categories of shippable things). This “feature” turned out to be a giant, carnivorous bug. Why you ask? Because LINQ is powerful magic.

It first started when instead of IUserRepository.Get(userId) someone wrote IUserRepository.First(x => x.UserId == userId). Let’s take a look at the SQL that is generated by these statements.

    -- IUserRepository.Get(userId)

    SELECT
        users0_.Id as Id2_0_,
        users0_.Username as Username2_0_,
        -- ...
    FROM
        [Users] users0_ 
    WHERE
        users0_.Id=@p0;

But notice the missing WHERE clause in this next case:

    -- IUserRepository.First(x => x.UserId == userId)

    SELECT
        users0_.Id as Id2_0_,
        users0_.Username as Username2_0_,
        -- ...
    FROM
        [Users] users0_

What’s really happening in the latter case is that the code we accidentally wrote is

    Enumerable.First(session.Query(), u => u.Id == usersId)

instead of what the developer thought they were writing:

    Queryable.First(session.Query(), u => u.Id == userId)

Unless you don’t mind loading your entire User’s table into memory every time you look someone up (for us this only took 12 GB of RAM), don’t allow your Repositories to implement IEnumerable.


L?t Den R?tte Komma In
We can’t tell you whether you should use nvarchar or varchar in your application, but we can say that the mappings for varchar suck (hint: start by using .Map(...).CustomType("AnsiString") to map your varchar mappings). Regardless of what you choose, you must know exactly what values you’re putting into your database, and equally important, what you’re getting back out.

The problem: this guy ಠ_ಠ

Or rather, the guy who chose that as his username.

First we mapped an Entity’s string property to a varchar column (non-Unicode string data) instead of nvarchar (Unicode string data). However, what we actually store in the database as his username is “?_?” since every high Unicode character is stored as a single question mark.

Second, we included a non-slug-ified, user-defined value (username) in the canonical URI of an API resource. In other words, the username “JohnDoe” would be included in the API URI as the path

    /users/johndoe

But that guy… his URI is

    /users/?_?

Got that? We made this transformation by mistake:

disapprovingface

we turned his disapproving face into tears

For anyone who knows RFC-3986, you will understand why this doesn’t work. ‘?‘ separates the path from the query in a URI. Sadly it took us a few users who were unable to retrieve their profiles before we figured this one out.

Here’s the lesson: Know what you’re storing in your database. If you choose to store non-Unicode string data, prohibit arbitrary Unicode characters in data entry and user input validation. Otherwise, this is how we feel about you: ಠ_ಠ


Night Of The Living Connections

You can’t have a Halloween blog without zombies, right?

Suppose you’re programming along, minding your own business, using your oh-so-convenient Session-per-Request pattern, when you come upon a stack trace containing CheckNotZombied(). In our case, this is another issue that arose from the intersection of a couple different problems.

At first we came across a blog stating this can be caused by one of two problems:

  • The database was throwing exceptions with a severity of 20 or
    higher
  • A transaction is shared by multiple threads

We initially hoped the problem was caused by the former since it would involve just following the stack trace. Naturally, it ended up being the latter.

It turns out that years ago, we wrote some slow code in a non-critical, uncommon code path (mobile push notifications). But the database query it ran really was too slow, so after receiving numerous timeout exceptions, we rewrote it to be more performant swallowed all exceptions and ran it on another thread.

It took about 3 years for the problem to arise, but then, every once in awhile, a random zombie exception would creep up in random places. When we finally traced the calls, we found that they were coming from inside this code!

    ISession session = mySessionFactory.OpenSession();
    new Thread(() => {
        try {
            // Intensive queries with session here...
        } catch (Exception) {
            if (session.Transaction != null
                && session.Transaction.IsOpen()) {
                try {
                    session.Transaction.Rollback();
                } catch (Exception) {
                    // Q: What's the worst that could happen?
                    // A: It’s pretty bad.
                }
            }
        }
    }).Start();

The non-critical, uncommon code path had became more popular over three years. Turns out the whole “smart phone” ended up being more than a fad. Luckily we were able to fix the problem fairly easily since uShip’s native mobile app necessiated a rewrite of push notifications using Amazon SNS.

Here are a couple of guidelines to help you avoid such a terrible fate:

  1. Trace, profile, and log ’til it hurts
  2. Don’t share NHibernate Sessions between threads
  3. When you want to accomplish work concurrently, and the work is IO-bound, prefer async methods to threads
  4. And don’t forget, just like zombies, sometimes all your ORM needs is a little love

Conclusion

NHibernate’s pluses have definitely outweighed the minuses for us, but it’s not without it’s hidden horrors. Are you able to relate? Share your NHibernate scary stories in the comments! And Happy NHalloween!

The post An NHibernateMARE on Elm Street appeared first on The uShip Blog.

]]>
https://ushipblogsubd.wpengine.com/shipping-code/nhibernatemare-elm-street/feed/ 0