Embrace the Unknown

As programmers its no secret that we like comfort. Well at least most of us. I mean every so often you’ll run into the uncanny ADD-man. You know the guy that is so in need of finding the next thing to jump to you’re pretty convinced he has a deep rooted issue involving being moved around from city to city because of a parent’s career… or paint chips.

For the most part though, we do like a certain comfort zone, and fuck if someone will convince us to get out of the comfort. And why would we? I mean it’s something we know. Something we understand. And isn’t life easier when there’s understanding?

I ran into this a couple jobs ago (I’m a job whore) when I asked for two monitors. Now this idea was something completely foreign and oddly scary to the people there. I mean, alt-tab is just fine, amirite? Wasn’t soon after getting the second one I was being looked at like some kind of child molester.

All I can say is: Don’t knock it until you try it. I meant two monitors, not child molestation. Well at some point the old light bulb went up on someone (Which makes me wonder what turned on before there were lights).

That person dared to start using two monitors. Next thing you know, there was a rash wave of double monitor usage. The world had changed forever. There were whispers of possibly having three monitors.

Side thought: I wonder if this is how the double razor to triple razor to n razor thing started. One guy was all like, “Hey guys, what if we had two razors on a shaver.” and then promptly speared for such thoughts that most likely were from satan. That was until some boss guy who was too high up to spear uttered the same words. Then everyone just went bat f–king crazy and started just throwing on arbitrary numbers out like some kind of reverse auction. And thus the razor wars began.

Anyways, back to the monitor thing. The moral of the story is that you can’t know what you can dare to dream if you have no concept of what’s out there.

Ok I lied sort of. Usually people use the line “The moral of the story” to end a thing like this, but I actually am being all sneaky and I tricked you into something bigger: Programming languages.

I have a confession. Well I have two, but one has to do with a having a song by Miley Cyrus… ok multiple songs… OK EVERY F–KING ALBUM… but that’s not important. The important part is that I’ve been a hardcore Microsoft guy for all 10 or so years of programming. I did not stray at all really. At least not much…

And why not? Microsoft has done a good job keeping the carrot in front of my face.

So why would I want to go anywhere else? I mean, I’m diverse. I use javascript. Besides, I have everything I need just given to me. Read that again. Actually I’ll type it again then just read it: I have everything I need just given to me. There are so many things that .net technologies do for me I really don’t have to do a whole lot. Or know a whole lot. Most lower level language ideas are just completely paved over with easy to use classes and controls. And that’s the problem.

I’ve been on a quest in the last year or two to really push myself to have a much better understanding of important programming concepts… that Microsoft has been so kind to hide from me as to not worry my pretty little face.

And maybe you are ok with that. Maybe you like to just take a pay check or just produce mass quantities of semi working code. Nothing supremely wrong with that. Just realize your career at some point will flat line.

But I say screw that. I need more and damnit I’m going to get out of my comfort level. I will brave the unknown (actually I already have with java and python) and in the long run I’ll be much better off. Why? Because not only do I diversify my languages, I also am privy to new and weird concepts that I would never see if it weren’t for venturing into new languages. Not only that, but I’ve found that some of the concepts and features just being added to C# have been around for a long time in other languages. So why wait for them to mature when you can use them now?

No really, I’m asking that. Give me a good answer…

Off Topic: My Love For Star Trek The Motion Picture

There are few things that I accept about myself: I’m ruggishly handsome, I have a superior intellect, and I’m the only person on the planet that thinks Star Trek the Motion Picture is the best Star Trek movie out there. And no I’m not talking about the 2009 movie, though I really enjoy that one, but the 1979 one. People usually just stare at me when I confess this after way too many drinks, but its true. Its my go to movie. If I don’t feel like watching anything else, I can always watch it. Actually I just had to adjust the TV as I am watching it right now.

Most people think it’s boring or something, but in my mind it’s by far the most true to the original series and by far the most intriguing. If nothing else, it keeps the original series’s flair for the unknown. You really aren’t given a lot of information off the bat except that what ever is out there just made the feared Klingons look like little bitches. I’m sorry, but any one who was brought up on the original knows there’s only one force in the universe that can go toe to toe with them and still survive… James T f—ing Kirk. This thing makes him look like a complete tool. Right off the bat you’re just thinking “Oh s—, what can stop this?” This thing makes the doomsday machine look like a ice cream vendor.

And I think that’s part of where my love comes in. The other movies, except maybe that disaster IV, you knew it was just the normal foe. Even Khan was assumed he would in some way get his a– handed to him James T Kirk style. But this thing (Why is every object we don’t understand called a thing?) is so far beyond powerful that you just can’t possibly accept that Kirk would kill or bang it. There is a feeling of complete and utter danger that none of the other movies really have. That feeling of powerlessness.

The next thing is the total seventies feeling too it. Yeah I know there are a lot of bad movies from that era, but the ones that we remember have something in common, a magically weaving of music and sight. There is something just… eh visceral about this movie that you can’t replicate in a movie. Something about the visual feel and the way the music just seems to draw out everything the eyes can’t see is something I think is the only part of the seventies worth noting. It was a time of experimenting with just about everything and as the saying goes sometimes the blind squirrel finds a nut. That is how I feel about this movie. The deliberate nature of it’s filming being paced by its music brings a certain overload of the senses at times. Some people call it slow or dull, but I call it purposeful and enveloping. It draws you in and tries to tell you a story that words could never do.

Beyond all of that, the twist at the end is so out there but makes so much sense that you can’t deny its possibility. I’m sorry but every times I hear the “V…g..e..r….voy…g…er…. Voyager” it just makes me think, “Now that’s an idea.” Well actually I end up repeating the line in only the way Shatner could deliver, but after that I think about the idea thing.

I understand that most people won’t watch this movie and get what I’m talking about. I get that I might be insane. I’m ok with that. Because as I sit here watching this movie for what is probably well beyond the 100th time, I know that I will enjoy every stupid second of it. You can go watch the stupid one with the whales if you want. This motion picture is mine.

What happened to Lan Parties?

As I was making my third attempt to reassemble a horribly aged futon (that had been passed around to so many people there’s no doubt its seen more action than Tom Selleck in his Magnum PI days), wondering if it was some kind of early attempt of Ikea’s to blend furniture with some kind of social experiment to see how much a person can take before starting a three figure body count, and swearing enough to make Bog Saget blush, I decided that the best course of action to keep me from going hulk on it was to think of better place.

Lan Parties - Panel One

That didn’t feed into my almost Gibson-esque epic instability.

Lan Parties - Panel Two

I then started thinking of my friend (no not that way) and how he (still not that way) was having a lan party this weekend and how he had invited me to it. Now I probably would have gone if it weren’t for the fact he lives 10 hours away, I’ve never actually met him in person, and I’m pretty sure he’s actually just inviting me over because he needs a new host body as his is falling apart.

You remember those days. 10 high school (maybe college) dudes all smashed into a basement with 10 computers going full blast, cases and cases of mountain dew, all completely focused on one and one thing only: gaming. Those 48 hour gaming benders fueled by so much caffeine that by the morning of the second days everyone had that weird anxious/excited/electrified feeling that somehow mixes the feeling you get right before you start opening birthday presents and the feeling you get right before vomiting:

Lan Parties - Panel Three

You know, the same feeling we would feel again 10 years later right before having sex for the first time:

Lan Parties - Panel Four

Well this led to me asking my self, “Self, why don’t I go to lan parties anymore?” For the most part, I think part of getting older is realizing that the copious amounts of caffeine taken in at 16 would no doubt kill me or more than likely be replaced with alcohol and no doubt would end with some kind of machine being forced down my throat in a last ditch effort to keep me alive so that I could enjoy the week long hangover to follow.

I think also in my oldness, I’ve lost the ability to play games for any extended period of time. Seems as if that part of my brain has been removed or possibly atrophied due to suffering from depression brought on by lack of use. Either way, I now have a greater capacity to code for extended periods of time instead… Wait. I’m feeling something… I think it’s an idea which would explain why its a feeling I don’t recognize.

What if the gaming lan party were to evolve? What if all that caffeine drinking, sardine can sized room of guys, (I’d say gals too since I realize there are women coders but really, what woman wants to take the chance of being locked in a small room chock full of essentially coked up geeks?), table to table, computer to computer, energy filled mayhem could be used to code? Think about it:

What if you were to take some idea like say a program that compares the hotness factor of supermodels (YEAH SUPERMODELS MAN, CAUSE THAT’S WHAT MANLY MEN DO, YEAH!) or the best picks for fantasy football (more in line with reality) and just go at it for 48 hours straight? I think this could actually work. After all, you have the combination of a ton of minds and no external interruptions to really just hammer something out. I realize there could be some issues inherent with super-fast coding:

Lan Parties - Panel Five

But couldn’t this work? You get lots of up-side on this one. Comradery, energy, excitement, a semi-working program, and quite possibly good, old-fashioned physical nerd fights (hey, that’s what Youtube was invented for) caused by late nights, caffeine psychosis, and uncomfortably close proximity to other people for more than 10 minutes. How could this be a bad idea? So I say, have at it. Prove me wrong about this one. And make sure you take video proof of how wrong I was. You know, some kind of video diary of you attempting to flee the country after they find the 9 bodies you somehow managed rage into the trunk of your car. (Again, that’s what Youtube was invented for).

Lan Parties - Panel Six

Off Topic Sunday: Does Not Liking Quentin Tarantino Make Me A Mutant?

COMPLETELY NOT PROGRAMMING RELATED

Any time I declare this I always get the same look people had when that one dude in Total Recall took off his glove and had that weird chicken wing arm thing. I can’t think of many directors that get the same free pass as he does for making, in my crazy mutant opinion, two good movies: Pulp Fiction and that one part of Four Rooms with the Zippo lighter bet. Ok so one movie and a section of another. Maybe Kill Bill 2 could be in there. Maybe.

Now I have to admit that I’ve been accused of having less than main stream opinions on movies. I’m not one of those people that only like a movie if it’s made on a 10k dollar budget and ends up just as depressing as it started. (IE Every independent movie ever.) I enjoy movies that are thought provoking and relevant as questions like “What would green smell like?” or “Why do I have 10 ten toes?” However, I liked Star Trek: The Motion Picture the most out of the six because I felt it was very Star Trek like and the most intense of the bunch. I liked Alien 3 more than Aliens (Only after watching the Director’s cut version though) because it had more thought out undertones. I think that Kill Bill 2 is far more interesting than 1 because it had story minus a bunch of tools running around like they’re athletic (See The Matrix). I also still find Godzilla versus Mechagodzilla to be the best, even though Godzilla 2000 is far superior in ever aspect, because that one part where Gozilla and King Caesar are standing in front of and behind, respectively, Mechagodzilla and they think they have it flanked when it turns it’s head around to look at King (With it’s laser eyes) and swings out it’s missle hands at Godzilla almost as if it was sayin, “You thought you got me, but I got missles b–ch. You ain’t got s–t. ”

Three things you can take from that: I probably don’t line up with your tastes, I do have thought out excuses for my “condition”, and I am a massive geek. I honestly feel that at this point I need to boost a car, take some E, and bench press 800 pounds at the same time to offset the horrendous black hole of geek I just created that threatens to pull us all in to an alternate, more geeky version of the world. No one wants that. No one but Adam Savage wants that.

At this point, you might see where I’m coming from. I’m clinically insane. However, that doesn’t mean I’m not entitled to an opinion on Tarentino. The guy is like a 12 year old with a budget.

Remember when you were 12, watching Power Rangers, sitting in a rocking chair, while lathering yourself in a mixture of peanut butter and motor oil? Probably not (But if you do, call me) but you might remember watching a movie like Aliens and thinking “What if the aliens could talk?” or “What if the Aliens could use guns, that would be sweet cause they would be all like ‘What up!’ BLAM BLAM ‘Screw you Marines!'” And let’s be honest, there’s a reason why you weren’t making films at 12… or probably even now. (Honestly? Aliens using guns? What the hell were you on at 12?) Every time I see one of his movies now, that’s all I can see: Tarantino lathered up in pean… Wait… I see Tarantino sitting around writing some movie, probably a masterpiece about a child who is taken from his family, forced into slavery, and then finds a way to unite the slaves against the slavers and bring peace to the his people. Followed by weeks of “What if aliens some how helped him free his people?” and then “What if the aliens give him awesome laser weapons and then there’s a scene where he’s all like ‘I’m gonna make them pay’ while standing on a mound of dead slavers and then he points the gun at one that’s still sort of alive and shoots him and his head explodes and the aliens start dancing in joy! Oh man that’d be cool.” (You might also call this the “Lucas effect”) Somewhere, at some point, the good ideas he may have go from a smooth riding train to a train that just lost a wheel, jumped the track, and is plowing through some childrens’ hospital.

And guess maybe that’s the problem I have with him. It’s clear that the guy is good with conversations and characters. It’s clear that he could be a premier writer. It just seems like the 12 year old side of him takes over at some point. Oh well, that 12 year old has done him well financially so who am I to say what’s good?

In the end, it just comes down to preference. Maybe I don’t have the part of the mind that gets satisfaction from way over the top insanity in movie form (I think it’s seated somewhere in between the part that enjoys chili cheese fries and the part that makes people stop and stare at highway accidents.), and if you do well more power to you. Just don’t judge me based on my thinking he’s straight up overrated or that he isn’t a god of filming. Then again I’m not the kind of person who looks for religious overtones in the Star Wars series, so maybe I’m just too dumb to see the brilliance.

Oh and side note: HE HAD NOTHING TO DO WITH HERO EXCEPT WITH HELPING WITH PUSHING UP THE TIME LINE OF THE US RELEASE. Don’t f–king even think he had any real hand in what’s probably the best epic movie in existence.

Other Note: Apparently resident “computer wiz” Andre refused to read more than the title of this post. He’s one of them…

State List in Dictionary Form

Tired of having to look this up from time to time, so I’m putting this here for my own use. If you get something out of it, good for you. In the end, I really don’t care.

    public Dictionary GetAllStates()
    {
      if(_stateList == null)
      {
        _stateList = new Dictionary();

        _stateList.Add("Alabama","AL");
        _stateList.Add("Alaska","AK");
        _stateList.Add("American Samoa","AS");
        _stateList.Add("Arizona","AZ");
        _stateList.Add("Arkanas","AR");
        _stateList.Add("California","CA");
        _stateList.Add("Colorado","CO");
        _stateList.Add("Connecticut","CT");
        _stateList.Add("Delaware","DE");
        _stateList.Add("District Of Colombia","DC");
        _stateList.Add("Federated States Of Micronesia","FM");
        _stateList.Add("Florida","FL");
        _stateList.Add("Georgia","GA");
        _stateList.Add("Guam","GU");
        _stateList.Add("Hawaii","HI");
        _stateList.Add("Idaho","ID");
        _stateList.Add("Illinois","IL");
        _stateList.Add("Indiana","IN");
        _stateList.Add("Iowa","IA");
        _stateList.Add("Kansas","KS");
        _stateList.Add("Kentucky","KY");
        _stateList.Add("Lousiana","LA");
        _stateList.Add("Maine","ME");
        _stateList.Add("Marshall Islands","MH");
        _stateList.Add("Maryland","MD");
        _stateList.Add("Massachusetts","MA");
        _stateList.Add("Michigan","MI");
        _stateList.Add("Minnesota","MN");
        _stateList.Add("Mississippi","MS");
        _stateList.Add("Missouri","MO");
        _stateList.Add("Montana","MT");
        _stateList.Add("Nebraska","NE");
        _stateList.Add("Nevada","NV");
        _stateList.Add("New Hampshire","NH");
        _stateList.Add("New Jersey","NJ");
        _stateList.Add("New Mexico","NM");
        _stateList.Add("New York","NY");
        _stateList.Add("North Carolina","NC");
        _stateList.Add("North Dakota","ND");
        _stateList.Add("Northern Mariana Islands","MP");
        _stateList.Add("Ohio","OH");
        _stateList.Add("Oklahoma","OK");
        _stateList.Add("Oregon","OR");
        _stateList.Add("Palau","PW");
        _stateList.Add("Pennsylvania","PA");
        _stateList.Add("Puerto Rico","PR");
        _stateList.Add("Rhode Island","RI");
        _stateList.Add("South Carolina","SC");
        _stateList.Add("South  Dakota","SD");
        _stateList.Add("Tennessee","TN");
        _stateList.Add("Texas","TX");
        _stateList.Add("Utah","UT");
        _stateList.Add("Varmont","VT");
        _stateList.Add("Virgin Islands","VI");
        _stateList.Add("Virginia","VA");
        _stateList.Add("Washington","WA");
        _stateList.Add("West Virginia","WV");
        _stateList.Add("Wisconsin","WI");
        _stateList.Add("Wyoming","WY");
      }

      return _stateList;
    }

So there. Hope you’re happy.

Back, Back from the Dead… Again

So Andre, the only person I know to argue with a toaster and lose, has mostly completed moving the site over to the new hosting. Issues? Well there are some lost comments. It’s sad, I know. Your 15 minutes of fame just got washed away like sand on a body of land that is within sufficient proximity of a body of water so that it is carried away if said body of water has the needed tide to carry it away. I’d cry for you but I have no tear ducts.

Going forward, you can feel confident that if you leave a comment it will exist until we change hosts and Andre has control of moving it again.

ASP.Net MVC: Attibute to Check if Route Value Exists and… and Means Something!

Get ready for a roller coaster ride around the insanity that is me. You might actually find it amusing but most likely you’ll just leave sick or underwhelmed. Don’t feel bad if you do, you wouldn’t be the first and, thanks to somehow being impervious to Natural Selection, you won’t be the last. Be proud.

Here’s what this post is about: Say you have a url like eh:

/User/View/1

Where 1 represents a UserId to a user that exists in some matter of context. (Does that makes sense?) Well there are a couple of things that could go wrong here. For one, if you don’t want to have a nullable id in your signature:

  public ActionResult View(Int32? userId)

This could cause ouch:

/User/View/

But this problem is deeper. Much deeper. In fact so deep it deeper than even Piper Perabo has ever deeped before. Yrraaaahh!

What if the id doesn’t even refer to anything? Say the id is 101 but there’s no user with the id of 101? Beyond that, what if the id could be Id in some routes but UserId in others? WHAT WOULD YOU DO???

The idea here is to have something neato like this:

  [UserExistsById]
  public ActionResult View(Int32 userId)

And if that id is junk, then you redirect to an error page. Well if this sounds interesting, I’d be surprised, but read on in the event that it does.

Now this isn’t accomplished in the most simple manor, but for good reason: The more time in means the less time repeating. First method we need is something to simply check the route data to see if something exists:

  public static Boolean RouteDataValueExists(ActionExecutingContext filterContext, String idToCheck)
  {
    return filterContext.RouteData.Values.ContainsKey(idToCheck);
  }

Real easy. It either has been digested by MVC and regurgitated into some kind of route value or it hasn’t. Basically this is the first check. After all, if it doesn’t exist why bother going further?

Next is the method that will be calling this one. Mainly one that uses the RouteDataValueExists and if returns true, then it actually checks the value against where ever the user is persisted.

  public static Boolean ValueFoundAndItemExists
  (
    ActionExecutingContext filterContext,
    Enum idToUse,
    Func<ActionExecutingContext, Enum, Func<Int32, Boolean>, Boolean> check,
    Func<Int32, Boolean> exists
  )
  {
    Boolean checksOut = false;
    String convertedId = idToUse.ToString();

    if (RouteDataValueExists(filterContext, convertedId))
    {
      checksOut = check(filterContext, idToUse, exists);
    }

    return checksOut;
  }

Ok so kind of a lot at first and it’s hard to decide how to present this system, so just go with it.

  Enum idToUse,

This is a design choice. In reality this will be turned into a string anyhow, but the idea is it will be what to check the route values for. So if you are checking for UserId, you will pass in UserRequestTypes.UserId. Again this was a choice on my part as I hate passing text around.

  Func<ActionExecutingContext, Enum, Func<Int32, Boolean>, Boolean> check,

This is the method that will be used by ValueFoundAndItemExists to delegate out the actual checking if the id is an integer and is a real user.

Func<Int32, Boolean> exists

This will be the method that you will use to delegate the whole checking if it exists in the database. Something like:

  class User
  {
    public Exists(Int32 id)
    {
       return EntityContext.Context.User.Any(user => user.Id == id);
    }
  }

Still with me? No? Greeeeat. Next up is the base class that contains the

  Func<ActionExecutingContext, Enum, Func<Int32, Boolean>, Boolean> check,

parameter from above.

public abstract class BaseExistsAttribute : ActionFilterAttribute
{
  protected Boolean Exists
  (
    ActionExecutingContext filterContext,
    Enum idToUse,
    Func<Int32, Boolean> exists
  )
  {
    Int32? id = Convert.ToString(filterContext.RouteData.Values[idToUse.ToString()]).ConvertTo<Int32>();
    return id.HasValue && exists(id.Value);
  }
}

Ok so something might look familiar like well basically all the parameters. The reason for this is that there is a little bit of delegate passing going on with this whole system. One method passes on methods to other method in some kind of crazy method hoe down without the flanel shirts.

You will notice the use of the enum in this part:

  idToUse.ToString()

Again, you can easily just pass in a string instead of an enum, I just did this to stay away from strings.

Only thing that might be of interest is the ToConvert method that you can find here. You don’t have to use it, you can simply just do a try parse on the

  filterContext.RouteData.Values[idToUse.ToString()])

To get an integer. That’s up to you. I could have just put that in the code for you to see but then I couldn’t randomly plug another post of mine.

Finally you have the actual attribute class:

  [AttributeUsage(AttributeTargets.Method)]
  public class QuoteExistsByQuoteId : BaseExistsAttribute
  {
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
      base.OnActionExecuting(filterContext);

      if
      (
        !MvcMethods.ValueFoundAndItemExists
        (
          filterContext,
          UserRequestTypes.UserId,
          Exists,
          UserEntity.Exists
        )
      )
      {
        filterContext.Result = SiteMethods.ErrorOut(ErrorNames.General_PageError);
      }
    }
  }

And now it all comes together.

  UserRequestTypes.UserId

This is the enum I’ve been talking about this entire post! Now that I think of it, not really exciting.

  Exists

That’s the method on the base class that checks for everything.

  UserEntity.Exists

And that’s the method I need to check the persistence if the user is real. Remember? Takes in an integer and returns a boolean? Yes? Yes? No?

What’s ErrorOut? Again this is just a method I made to create an ActionResult that is an redirect to an error page. Not hugely important. It’s just what handles the situation when the value is bogus…. dude.

  [UserExistsById]
  public ActionResult View(Int32 userId)

And there you have it. Hopefully it was useful in some way but I’m not of touch with reality.

SPAM OR COMMENT??!?! 2

Hello Man!. Just one more question. Realy, need your help.
Question about Alcohol posioning?

100 times thenks. I am Waiting for answer!!!

Now I might have been fooled at first, but I’m leaning toward spam on this one. I have to think that if you did indeed have a question about alcohol poisoning you might try a medium faster than say comments on a blog. Course by now if he was looking for an answer it probably doesn’t matter anymore.

Or maybe it’s the fact THIS IS A BLOG ABOUT PROGRAMMING. Then again, maybe it was a comment for this post.

SPAM OR COMMENT?!?!?

So here’s the first round of a new game. Really simple, I post the “comment” and you tell me if it’s real or spam.

Hi Man!, please, need your help.
Wat is an alternative to glass pipe screens?

Thenks, bro. I am vaiting for answer!!!

So what’s your take on it?