7 Best productivity hacks (without any BS)

This is my first blog post in 3 years! What have I been doing instead of blogging? Being productive with these productivity ‘hacks’:

  1. Close everything distracting especially skype and outlook
  2. Come in late so you can work later hours so less people are around to distract you
  3. Don’t make eye contact with anyone they’ll just want to have a long boring conversation distracting you from your precious work
  4. Stay in the office or your home office at all times, it is dangerous outside
  5. Do the boring simple tasks when you first get in and your brain hasn’t woken up, they’ll take just as long to do when your brain is awake
  6. Ignore your Health, the amount of self-value from the extra work you get done will replace it
  7. never EVER EVER get married
Posted in Uncategorized | Leave a comment

Idiot’s guide to Entity Framework by an Idiot

I recently used Entity Framework for a project for the first time and my Boss wanted to take a look at Entity Framework so I wrote up a 101 guide for him and he thought it was good. This blog is probably full of inaccuracies as I’m a noob at EF but I think it has a few helpful tips.

So the way I like best is to create your database first then have EF generate your objects for you. You get complete control over your DB tables so you can make them as efficient as possible and when using code first EF has been spotty with making database structure changes.

When creating your database make sure to set up the FK / PK metadata relationships so EF can load it up. For PKs make sure to set Identity specification to YES or EF will assume you are providing your own PKs when creating a new object. If you generate your edmx file before setting identity specification to YES it will bug out if you try to change it yes then update the file, so you then have to manually change it in the properties of the identity column in the ef designer.

Also ALWAYS include a PK for a table, this is generally a really bad idea not to use a PK and with EF it is an even worse idea that will only end in tears(lots of bizarre exceptions).

You can also use EF by creating a model in their edmx file gui editor and generating a DB from that or by coding your objects and having it generate a DB from that.

Steps to add EF to your project:

1. EF should already come with vs2012/vs2013 but use nuget to install if you don’t have it (http://msdn.microsoft.com/en-us/data/ee712906.aspx)

2. Add a new file to the project, choose “ADO.NET Entity Data Model” under Data.

3. Choose generate from database, connect to it and run through the wizard

You now have a .edmx file which is all the auto generated crap EF just made for you. Clicking the .edmx file will bring up the gui editor where it should have loaded all of your tables up. All of the .tt file stuff underneath the edmx file is auto generated files that you should not edit unless debugging.

So EF just generated a bunch of awesome POCOs for you. These POCOS have their pk/fk relationships set up as virtual objects which will only load when referenced when lazy load is enabled(it is by default).

It also generated a DbContext class for your db that will be named whatever you named it in the wizard. The DBContext class is what you use whenever you want to get to your data, it manages all of the database query/persistence/connection and what not. DbContext classes are a combination of unit of work/repository patterns.

Simple use to get 1 object

StoreContext context = new StoreContext(); Account a =
 context.Accounts.FirstOrDefault(a => a.AccountId == 1); 
//woo all our purchases loaded up automatically 


So whenever we get an object  from a context it is going to be associated with that context. When we call context.dispose() and then try to call a.Logins it will throw an exception because it never loaded our logins and our context is gone now.

A context should be used like a unit of work because it is not thread safe and leads to memory/sharing issues. So when we want to do a task we create a new context make our changes and call context.SaveChanges() then get rid of the context. For an asp.net site I would use one context per request so every time a request is made in the global.cs I would create a new context and store it as StoreContext.Current() then when the request is done  dispose of the context.

So add a a current method like this to your context class. This checks if a context has been created for a request yet and if it has it it returns it if not it creates a new context and returns it.

public static MySweetContext Current()
     if (!HttpContext.Current.Items.Contains("context"))
         ("context", new MySweetContext());
      return HttpContext.Current.Items["context"] 
      as MySweetContext 

And to dispose of it after each request add something like this

MySweetContext currentContext = 
HttpContext.Current.Items["context"] as MySweetContext;
if (currentContext != null)

in your Application_EndRequest(object sender, EventArgs e) method in your global.asax file.


For a web api service you should create a new context in your object controller every request, you can actually generate basic controllers from entity framework entities that will have this in there already. Microsoft spent some time making the DbContext class fast to instantiate so I wouldn’t worry about creating one to often.

Moving an object between contexts is a complete PITA of attaching/detaching and setting things to null. I fell into a trap of trying to do this because of storing an object in a session variable with a context associated with it and then making a new request that had a new context. Don’t be like me use your objects then get new ones with a new context. Screw trying to be efficient with this.

For a web service you are pretty guided away from falling into this, but be warned moving between contexts is awful and generally means you shouldn’t be doing what you are doing if you have to.

Rest/JSON ef web api stuff,

1. to generate a basic controller from an EF object right click a folder and add scaffold and follow the wizard from there.

2. Web API with JSON is dumb with object relationships by default, it will get stuck in a loop. To fix this you can add

= Newtonsoft.Json.ReferenceLoopHandling.Ignore;


to your global.asax.cs start method. This will stop the loops and load up every single virtual object down to its termination.

OR you can disable lazy loading in your context. This might be better because with a web service you are trying to limit what your sending down so specifying exactly what you load is going to be needed.

One idea for this is to extend your Context class to a class named something like JSONContext, then disable lazy loading in its constructor and use it in the service controllers. So when you need to load a virtual object you have to do explicitly by using the Include method

context.Accounts.Include(A=> A.logins).FirstOrDefault(A => A.id == id)

Random cool things

1. EF protects against SQL injection and whatnot by itself as long as you use the objects with LINQ like your supposed to, if you manually enter in some SQL code to the connection you are on your own.

2. You can bind values to enums in the .edmx designer or bind an already made enum class to an enum column ( I believe the later requires .net 4.5 though)

3. Some say you should wrap EF with a repository and unit of work pattern so it is abstracted away and allows your unit tests to be pure. However EF already is pretty much a repository/unit of work pattern, I don’t think this is necessary honestly. For a small project don’t bother but for something larger it’s pretty debated and you should google it.

4. EF can handle polymorphism with your POCOs in the ef designer by using a tinyint or byte column to differentiate the classes.

5. I extend my POCOs by creating a partial class in a new file, your base poco files are auto generated so don’t edit them. EF in a normal project(vs an asp site) will create separate class files in the model folder which means if you want to keep the same file names for this partial extension you have to put them in a separate folder and go against namespace standards of using the folders. You can’t have a partial class in a different namespace unfortunately

6. To update your EF file from DB Right click and then hit update in the EF designer and then hit save and it will regenerate.

Thanks for reading my blog! Hopefully it didn’t kill too many brain cells.

Posted in Uncategorized | 1 Comment

The vegans tricked me

Over the weekend I was visiting my usual lunch place, Smash Burger which serves some very delicious burgers, when I decided to branch out and try something new. My friend pointed out the new Native Cafe restaurant that was close by so I decided to give it a shot. I saw Native in their name so I figure they serve exclusively local organic food or some such sort (I was very wrong). I quickly scanned their menu and saw “Oklahoma Bacon Cheeseburger” it had something about delicious native bacon in its description and I was sold.

I order up the aforementioned burger and some fries and she starts rambling about all the different fries she has, I just reply I’ll take the most normal fries you have. So I take my seat and expect that in a few moments I will be served some combination of beef, pork product and cheese.I notice a guy with dreads in the corner, over at the table next to us there are a couple of Indian woman munching on some burgers. That’s funny I think to myself Indians don’t eat beef, eh they probably serve tofu burgers too. This is where the trouble begins. I look to my right and see a blackboard talking about their various “meat” products and see “Native Bacon” and underneath that it describes how it is made out of some sort of tofu. Oh god. I look at a pamphlet on the table and see “100% vegan restaurant ” at the very top. Back at the blackboard I see my expected beef is actually “Seitan”. Panic begins to set in my friend begins laughing so hard he is crying. I have just spent 13.90  at a vegan restaurant. OK I have to deal with this situation, I’m sure this burger can’t be that bad who would become a vegan if all the food tasted awful?

My “Bacon Cheeseburger” with no bacon,cheese or burger arrives. I peer inside of the buns cursorily to inspect what I have gotten myself into. The “bacon” looked pretty real actually, well it had the right color at least. The closest thing I know of that resembled the “cheese” was easy-cheeze and finally the “beef” looks like a slab of calamari… “It can’t kill me right? right??” I ask my friend, he shrugs. I just go for it and take out a huge bite. I will remember that bite for a long time, it was the most disgusting thing I have ever eaten.It did not taste like cheese, it did not taste like bacon and it sure as hell did not taste like burger. God have mercy on your soul if you stumble into this place. This review ends here it pains me too much to say more.

Posted in Uncategorized | 1 Comment

Synergy with OS X mouse disappearing

I have synergy set up with Windows 7 as the server and OS X as the client. Randomley today the mouse pointer would disappear and hide in the background on the OS X side if I did anything on the Windows side.

Not sure why it is doing this but here is what fixed it

-You can’t have more than one workspace open

-The dock can’t be on the side where you are moving your mouse over from your server

-After doing both of these restart the synergy program on both the server and the client.

Posted in Uncategorized | Leave a comment

Stack exchange, moderators with OCD, and why some poor sap won’t be able to find a quick solution now

Over the weekend I brought my mac mini home from work and set it up using synergy with my PC. I did some tinkering with OS X and unbeknownst to me at the time these changes would later screw up my synergy set up at work.

So I come in on Monday after a nice weekend and my previously perfect synergy setup has got a problem. I do a quick Google search to try to solve it and the top results are from stack exchange sites. Nobody has a real work around besides try an older version so I set off to fix it myself and a little later I figure out a workaround.

Now I think gee that sure was annoying, but I know, I will share this useful information on the top Google results(superuser.com questions) so Joe Shmoe doesn’t have to waste some of his time. There was two questions that were similar to mine that could use an answer and I check out a post on the bulletin section which has some vague wording on making duplicate answers. I’m thinking it would be useful to put the answer on two of the posts and if I’m in the wrong a mod will come by and just delete one of them or edit them and post a link in or something actually useful. I have no rep I can’t just add a comment so I have to put a full answer but hey this question was pretty much unsolved who doesn’t like some knowledge?

Apparently some kid with OCD damn well doesn’t like the sharing of knowledge because he deleted not one of my posts but BOTH of them. He didn’t give a reason, the only thing in the rules I could see that would apply to this is that these questions were a little on the old side. BUT THEY HAD NO REAL ANSWER AND STACK EXCHANGE DOMINATES THE TOP GOOGLE RESULTS. This is just completely irresponsible. If you have a site this visible on search engines and deny searchers knowledge because of some archaic rule there is something very wrong with you. This probably explains all the times I’ve gone searching for some bizarre problem and stack overflow floods the results with unanswered or half assed answers.

I sent the moderator an email and am waiting to hear back, I’m sure his response will be entertaining from my past experiences with these kind of people.

To unnamed moderator: I’m sorry for messing up your perfect little power tripping playground by actually giving something useful.

To Joe Shmoe: Sorry but you will have to wait until my blog rises in the search results through some sort of voodoo magic before you find your answer.

Posted in Uncategorized | 2 Comments

Error building app with objective c google gtl library

So I recently started working on building an iPad application. I linked up the google gtl library for objective c and I got a long list of these wonderful compiler errors.

“Undefined symbols for architecture i386:

“_SecItemCopyMatching”, referenced from:

-[GTMOAuth2Keychain passwordForService:account:error:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_SecItemDelete”, referenced from:

-[GTMOAuth2Keychain removePasswordForService:account:error:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_SecItemAdd”, referenced from:

-[GTMOAuth2Keychain setPassword:forService:accessibility:account:error:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_kSecAttrAccessible”, referenced from:

-[GTMOAuth2Keychain setPassword:forService:accessibility:account:error:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly”, referenced from:

+[GTMOAuth2ViewControllerTouch saveParamsToKeychainForName:accessibility:authentication:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_kSecAttrAccount”, referenced from:

+[GTMOAuth2Keychain keychainQueryForService:account:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_kSecAttrGeneric”, referenced from:

+[GTMOAuth2Keychain keychainQueryForService:account:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_kSecAttrService”, referenced from:

+[GTMOAuth2Keychain keychainQueryForService:account:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_kSecClass”, referenced from:

+[GTMOAuth2Keychain keychainQueryForService:account:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_kSecClassGenericPassword”, referenced from:

+[GTMOAuth2Keychain keychainQueryForService:account:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_kSecMatchLimit”, referenced from:

-[GTMOAuth2Keychain passwordForService:account:error:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_kSecMatchLimitOne”, referenced from:

-[GTMOAuth2Keychain passwordForService:account:error:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_kSecReturnData”, referenced from:

-[GTMOAuth2Keychain passwordForService:account:error:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

“_kSecValueData”, referenced from:

-[GTMOAuth2Keychain setPassword:forService:accessibility:account:error:] in libGTLTouchStaticLib.a(GTMOAuth2ViewControllerTouch.o)

ld: symbol(s) not found for architecture i386

clang: error: linker command failed with exit code 1 (use -v to see invocation)”

(Im hoping shoving the whole thing in here will help people find this on google when they make the same stupid mistake I did)

So I thought the gtl library wasn’t building correctly for the iPad simulator and spent a little while changing build options for that. Nope turns out I skipped a step in the setup guide and I just needed to reference SystemConfiguration.framework and Security.framework in my app. It doesn’t really make sense to me that you have to have these referenced in the gtl project and your application project but the Mac users seemed flabbergasted when I wanted a maximize button that actually maximized the damn window so I guess I just don’t understand this Mac world.

Posted in Uncategorized | Leave a comment

Help they’re making me work at Windward!

Recently I was asked to write a little about why I decided to work here at Windward full time come summer.

1) They’re a software company

I am graduating this spring so I have been mulling over where to work. I had already got an offer from Windward but I needed to look around at the competition. I had heard and seen big name companies like Raytheon and such drooling over computer science majors, someone I know was walking by a booth of a large non software company at a career fair when a guy spotted the Computer Science major on his nametag “You can program? We want to talk to you!”. Working at a big company that makes some impressive weapons sounded great but then I got to thinking that software developers are not the company. It’s their “hard” engineers and political and management games that make them. I don’t just want to program I want to create something.

2) Ideas are demanded and the work is challenging

We are encouraged to share all of our ideas related to our products or not. But we are not just encouraged, I have been in meetings where product ideas were straight up demanded from me and the penalty for not doing so was to be locked in the storage room and forced to write blogs until being devoured by a plague of nameless blog commenters (that last part is a slight exaggeration). The point is I’m involved in our products and not just a tool forced to program.

The other part of this is that I am constantly challenged; I get moved from different pieces of code, languages and technologies all the time. My workload is a hodgepodge of things that need to get done. This is the place to work if you want to be pushed to your limits. Then on top of that we are allowed to do specific things that we want to do on Friday afternoons, I remade one of our websites, made a chrome extension and some other stuff I cannot recall at the moment.

3) No hurt feelings over challenging questions

When I interviewed with them I was told to ask a challenging question of them, I asked my future boss why did the video game you create, enemy nations, fail? No hurt feelings over my boss’s baby and it even got me the job!

4) Intelligent talking canines to bounce ideas off of


5) Ramblings

While talking to a few other local software only companies I picked up some rather strange tones. They made it seem like if I wanted to work for them I had to stalk their company for weeks and come to several of their boring presentations followed by scoffing at my .net and friends development background while I am pretending to be constantly intrigued about their strict agile culture and their out doorsey perks. Company hikes all day every day? Yes programmers are known for their love of the outside. I think I’d rather go for Windward’s internal coding competitions.(Ok Windward does go outside sometimes, this is Boulder).

Posted in Uncategorized | Leave a comment

Simple way to mix asp.net with a php page

So your marketing department has just made a new website. They ask you to make some new forms for the webpage, but for some reason they handed you a bunch of php pages. Your old form code was all in asp.net! You have things to do besides this, they are pushing out the site live tomorrow, and you don’t really know why the pages need php but you need to get this done.

So after looking at a few pages on mixing php and asp.net together I said to hell with it and figured the quickest way was to just shove the old aspx pages into iFrames in the php pages.

Trim down your aspx page to fit in whatever sized container you need and it works.

Then marketing tells you they need the entire parent page to redirect after the submit form button is clicked, not just the iFrame. You can’t do this in asp.net so you need to use javascript. Simple way to call this after the form submit code has done whatever it needs to do is write a response back in your page behind code:

Turns out the website wasn’t live almost a week later, I think they lied to be me to make me work faster.

Posted in Uncategorized | Leave a comment

Breakthrough unit testing approach

Recently at a developer lunch someone brought up the recent article about virtual monkeys. A programmer set up a simulation with millions of virtual monkeys that randomly typed in text, and after a while they eventually produced a work of Shakespeare. Now computing power is expensive so we thought how about we just get some real monkeys to type it up.

Shown: preferred typing monkey

Unfortunately the preferred type of monkey is endangered and it would be rather expensive to get a million of them too. But we thought why not a slightly cheaper animal, surely a dog can type just as well as a monkey.

Shown Arthistory Sapiens

After thorough research we found ourselves with the cheapest solution, the art history major. Not just cheap but free. We estimated in Boulder, Colorado there was approximately 10 million art history majors.


Now what does this all have to do with unit testing? Well recently we have had a lack of interns for doing testing for us and needed a solution. But at the lunch meeting we suddenly realized what if our mentioned army of Arthistory Sapiens wrote unit tests instead of Shakespeare.

A couple of calls later and we had 20,000 Arthistory Sapiens willing to work for free as long as we gave them a recommendation. This would be our first initial test run. We purchased a small plot of land in north Boulder and an old Cray mainframe with 20,000 terminals.

We decided to use Perl as our language, as we thought Perl had the most likely combinations of valid unit tests possible. This would prove to be the best decision.

After only 2 hours one of the Arthistory Sapiens produced this code. This one piece of code gave 50% code coverage for our entire product.

This first test run was a huge success. Our only costs were a grand for the land, a six pack for the Cray and the terminals, and a homeless Perl expert we paid in food to verify the unit tests. We now have 500 acres of land in North boulder and over a million Arthistory Sapiens typing at any one time. We consistently have great code coverage and quite possibly the fewest bugs in production code ever. This is the future of testing.

Posted in Uncategorized | Leave a comment

Where Did I Come From, A chrome extension and how I made it

One predicament I often find myself in is having 20+ tabs open in chrome and wondering what site I was on when I clicked a link to open the tab I am on. So I made a chrome extension that stores that site for all newly opened tabs. Just click the “w?” button in the top right and it will create a new tab with that url. You can find the link to the extension here and the source code here.

I have never made a browser extension before, but it was pretty simple to do. The chrome API doesn’t have some magic history functions that could accomplish this so I had to store all tab ids and urls. My explanation of how this works will probably be butchered but hopefully someone will find this helpful still.

The first part is the manifest.json file. This stores the basic information of the extension. The “background_page” line tells the extension where are scripts are going to be run from which is background.html. “browser_action” tells the extension that we want a clickable icon and permissions requests from certain permissions from the browser when installed so that we can manipulate protected things.


The second part,background.html, is the actual code of the extension. It is written in javascript and listens for actions in chrome. One note, a lot of the chrome api calls are asynchronous so you must go through coding your application assuming that code will finish running whenever it wants to. There is no way to have synchronized and asynchronous code to work together as javascript provides no blocking and it is single threaded so you can’t sit around in a while loop waiting for an asynchronous function to finish.


Here’s the first part, whenever our selection changes to a new tab we want to store it in sel.

This listens for whenever a new tab is create in chrome. When a new tab is created we want to grab our last selection from the sel variable. Then we create an object and store the new tabs id and our last selections url and put it in a global array called tabs.

Here’s the actual function that is called when the extensions button is clicked. It finds what tab we are currently on then searches through our global array filled with the tab information. When it finds an object with a matching tabid it creates a new tab with matching url.

And that is all there is too it.free manuals

Posted in Uncategorized | Leave a comment