markneustadt.com

Pausing to catch your breath in C#

time-371226_640

Sometimes in your code, you find the need to try an operation that’s dependent upon some other system.  That other system might be a little laggy.  As such, you want to try your operation and then pause a moment or two before you try again.  A simple way to do this is with

Thread.Sleep(1000);

That little snippet of code will wait for one second and then continue.  There’s a better way though…

Read more

WebAPI – Accepting both form data and query string parameters

Recently, I had to write a WebAPI method in C# that would be an HTTP POST.  Basically, I wanted to hit

http://localhost:99/api-demo/samplemethod/myIdString

and pass a bunch of data in the body of the request. Simple, no?

In our project, we make heavy use of the Route attribute to decouple the method name from the URL.  My method looked okay.

    [RoutePrefix("api-demo")]
    [SetUser]
    public class DemoController : ApiController
    {
        [HttpPost]
        [Route("samplemethod")]
        public IHttpActionResult Sample([FromBody] string requestBody, string id)
        {
            return Ok(String.Format("Request with ID {0} body has a length of {1}", id, requestBody.Length));
        }
    }

This sample code is clearly very simple.  I have decoupled the controller to api-demo and the method to samplemethod. It appears like everything would work as expected, however when I would test it via POSTMAN, I get the following response:

{
  "$id": "1",
  "Message": "No HTTP resource was found that matches the request URI 'http://localhost:99/api-demo/samplemethod/1134630'.",
  "MessageDetail": "No type was found that matches the controller named 'api-demo'."
}

Read more

My $1,000 Poster

IMG_4973

I got a $1,000 poster in the mail yesterday.  Was it a 20’x20′ gigantic poster of something?  No.  Was it a meticulously reproduced version of one of the masters finest works?  No.  Was it an original that was custom made for me?  No.

What on earth?

Yesterday I received a little bit of a spiff from Tesla.  It was a large bi-fold folder.  When you opened it up, on one side was a very personal thank you from Elon Musk.  On the other side was a set of sketches of the upcoming Model3.

At least I have something to show for my $1,000.

I’ll say this… when people find out I’ve ordered a Tesla, they kind of freak out a little bit.  It seems like there may not be that much awareness of the Model3 outside of automotive circles.  People just assume I’m going to be dropping $90,000 on a car.  I have to be quick to correct them that, no, it’s just the cheap one.

Of course by the time I’m done optioning it up, I might end up with an expensive one.  #cantwaitforautopilot

The opened folder
Very personal, don’t you think?
It really is kind of a good looking car

A new blog

600_433367191

I have decided that the time is now for me to rededicate this blog to what it was originally intended for.  Before I get into that though, let’s put the new blog address here.

https://thebikerwave.wordpress.com/

Check that out and follow my two wheeled adventures.

So back to this blog.  A long time ago I decided that, as a developer, I should have a “portfolio” website or a “resume” website.  A website that would act as a professional presence.  I wanted a URL I would put on my resume.  This was that website.

Over the course of time, I would use this website as a repository for tidbits of technical knowledge I would find as well.  I would run into the same problem over and over again but never remember how to fix it.  I would have to go back to Google and look it up again.  Sometimes that was easier said than done.  So I started putting those scraps of knowledge here as well.  It was in the spirit of a professional website.

Then more time passed and other articles and pages started showing up here.  Nothing really bad or inappropriate, but more personal.  Things that weren’t really in the spirit of a professional site.

So here we are.  I have moved all the motorcycling content over to https://thebikerwave.wordpress.com/ and will continue to refine this site and groom it back to the original intention of being a professional presence on the internet.

God talks to people everyday

I’m not sure what happened at about 3:00 this afternoon, but I got hit with a taste for wine.  I haven’t been drinking much lately thanks to a four day bender a few weeks ago.  That being the case, I decided to indulge.  Also, I t’s rotten weather and I’d rather be riding, but I can’t.  So why not enjoy a tasty glass of vino.

img_0137.jpg

Also, think of this as a “let’s celebrate the new job” and “let’s celebrate leaving the old job” glass of wine.  All-in-all, I want it, I deserve it and doggone it, I’m gonna have it.

Here’s the thing…. I’m not sure God wants me to have a glass of wine right now.  You see, God was talking to me.


I know… I know.  Look… There were no voices in my head.  Plus I’m not entirely convinced of the whole “God” thing anyhow.  But I do believe that someone or something was talking to me.   Call it fate or whatever… for the purposes of this post, I’ll call it God.

So I left work with a hankering for a big fat glass of red wine.  Malbec if I’m going to be specific.  There’s a wine place just down the street from my building.  I walk past it every day.  I thought “this will be great!  I can get my wine on the way to my car!”  I walk in and notice an abundance of bottles and a distinct lack of seating.  Nuts… The place was a wine shop… Not a wine bar.


Fortunately, I have THE INTERNET.  I fired up Yelp and looked up “wine bars”.  I kid you not.  There was a wine bar directly behind where I was standing!  God spoke to me again.


C’MON MAN!  They had wine in the bible!  What’s your deal?  Fine… I work on the capital square in Madison, WI.  There’s nothing if not places to drink.  Back to Yelp and I choose the next closest place that lists themselves as a wine bar.  I know the place as more of a fancy beer joint, but now I’m on a mission.

I start making my way there and….


The level of road (and sidewalk) construction is downright hilarious.  Someone thought it would be a great idea to destroy one entire quarter of the capital square.  There was a big sign saying “businesses still open” but getting there was a huge pain.

At this point, it’s clear that God didn’t want me to have a glass of wine.  God was talking to me.  I could have had an Old Fashioned.


I could have had any number of other beers and/or cocktails with no problem at all.  It was just that I wanted wine and God put up obstacle after obstacle.

But I didn’t listen.
And now I think I’ll have another one.

Joining into the hype

Tesla Reservation

I know myself.  I’m a sucker.  I always have been a sucker for the newest hotness.  The newest flashiness.  Sometimes I wish I weren’t but that’s like an elephant wishing it didn’t have such a long trunk.  It just is what it is.  At least I know myself.

I have driven a Chevrolet Volt for many years now.  My first Volt was a 2012.  That was one of the first generation cars.  It was really awesome.  It seemed to me that General Motors was showing off with that one.  The engineering in it was top notch.  The fit and finish was fantastic.  General Motors wanted to show the world “Hey… look at us.  Look at engineering excellence!  We can still do it!  We’re relevant!”

IMG 0320
My “diamond white tri-coat” Volt next to a coworkers monster truck. The roofline of my car didn’t even hit his door handles

Read more

Poetry and Song Lyrics

poetry2

Many years ago I knew a man named Horace.  He was the first person I knew that was really a poet.  He worked with me in customer support, but would write poetry as a form of meditation or therapy.  He was kind enough to share some with me.  Sadly, I don’t recall the poem itself, but I do recall being very moved.

Lately, I’ve been trying to get into country music.  I have been a big fan of progressive rock and classic rock for many years but I’m getting bored with it.  At the local dive bars where I like to hang out, they’re all country, all the time.  I figured I’d start to expand my horizons and see if I could get some of it to stick.

There are many country songs I really, really like.  They tend to be the more “poppy, mainstream” country songs.  I’ve already brought up Brothers Osborne as one of my favorites.  I also enjoy Chris Stapleton and Eric Paslay.

I’ve noticed (unshockingly) a few themes.  First of all, in my estimation, more than 60% of the songs I hear sound the same.  The same beat, the same key, the same tonal intonations of the singers (male or female).  I mean they’re all just interchangeable.  It’s pretty maddening.

There’s also the eye-rollingly predictable stereotypes of:

  • Friday night
  • Drinking beer
  • Freedom
  • Fishing
  • My favorite bar

Gimme a break.  Whatever… people love it.  The thing that I’ve noticed that I wonder about though is the focus on the pickup truck.

Naturally, because of course.  But why?  I expect that it has a lot to do with the fact that pickup trucks are cheap.  Tons and tons of people in little towns all over America can buy pickup trucks.  They’re the common denominator.

But that got me thinking… how come there are no country songs about motorcycles?  Bikes are cheap and plentiful.  Maybe it’s Harley bias or maybe it’s because trucks are more utilitarian than bikes.

I bought a few books recently that are all motorcycle poetry or motorcycle haikus. Haikus don’t really lend themselves to song lyrics, but I expect that some of the poems in that book could be turned into songs.

A lot of the poems in there seem like they were written by first graders.  Very elementary structure and scheme.  Others are more unpredictable.  Many are actually very moving.

Maybe this is my chance!  Maybe I’ll start writing songs about the open road and my two wheeled steed.  Living a life unconstrained by rules and policies, dependent on myself.  Painting those mental pictures that transport people to another place only using words.

More likely, I’ll just sleep, eat, ride, eat, ride, sleep until I can’t ride anymore.

 

 

BBBC #26, 27, 28 and 29 – Wrapping up

wrap-up

This has been super fun.  I have really enjoyed playing along with Kathy’s Brave, Bold Blogger Challenge.  I’ve been pretty slack on it as we’ve been winding down so today, I’ll just whip out the final four installments.

They are:

  • How you make a living
  • Selfie, captured specifically for your post
  • Childhood photo
  • The first song that comes into your head and why

Here we go…

Read more

Performance – Using Try/Catch

I just wrote the stupidest program ever.  It is inefficient by design.  If anyone did this thinking “hey… this is great code” they should be fired.

Anyway… generally speaking, using try/catch blocks is not a great idea.  There are a myriad of reasons but it’s usually something along the lines of:

If you truly have an unexpected error it’s better to let the program crash and then fix the bug.

If you do have to use the try/catch exception handling block, you should only catch explicit exceptions.  For example catch a file access exception or a database invalid primary key exception.  Just catching the generic exception is poor practice.

There’s another reason to avoid try/catch though… it is a performance hog.

Read more

Scroll To Top