Programming By A Tool Whelps! Left Side! Left Side! Minus 50 DKP!



27Jan/100

Apple’s Latest Innovation Is Astounding, A Real Game Changer

I don't know how they did it, but they made the world's first shrink ray. Amazing.

Bookmark and Share
Filed under: Pointless No Comments
6Dec/091

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...

Bookmark and Share
Tagged as: 1 Comment
1Dec/090

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.

Bookmark and Share
Tagged as: , No Comments
25Nov/095

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.

Bookmark and Share
Filed under: Pointless 5 Comments
16Oct/090

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.

Bookmark and Share
Tagged as: , No Comments
29Apr/090

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.

Bookmark and Share
Tagged as: No Comments
21Apr/090

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?

Bookmark and Share
Filed under: Pointless No Comments
9Jan/090

OT: Winning the MAA Award, Thanks for your votes!

I just wanted to thank everyone that voted for me in the prestigious Most Awesome Award Award. This actually did come as a bit of surprise to me honestly since this year was a really stacked list of nominees between myself, a pack of Mentos, and the last minute write in of George Washington. Let me tell you, Mentos is one hard act to beat. I mean who the hell can compete with The Fresh Maker? And Washington? Wow. I can't explain how much my heart sank when I heard about him.

Now I just want to tell you that it was no easy task. It took a lot of campaigning, travel, self promoting, and paying people off but it still looked like both competitors had a sharp lead over me. I really put a lot of time and effort into convincing people I was the person to vote for. Unfortunately even up to a week before I was behind by too many votes. It wasn't until luck decided to turn in my favor. Apparently an anonymous call alerted the Most Awesome Award Award panel to the fact that Washington had been dead for over 200 years. It's what people "in the know" call a deal breaker. On top of that, I ate the pack of Mentos.

So in closing I'd just like to thank everyone that voted for me, your support has been the backbone of my reinforced structure. And for those who didn't vote for me? AY YAAAAY! Where's you Mentos now, fools? I'm out.

Bookmark and Share
   
NetDevInc.com