Wednesday, 17 June 2015

6/17/2015

"Against a 13.8 billion year backdrop humanity is a vanishingly small speck in a vast cosmic ocean. We are bits of talking meat spinning on a tiny wet globe adrift in incomprehensible vastness. But this polarity between insignificance and complete connectedness is precisely what makes our existence precious. We can stare into the void with awe, gratitude and wonder, or we can gaze at it with fear - make no mistake that the choice is ours. In a universe so infinitely vast there is no objective meaning, but this frees us to create meaning in any way of our choosing, and it allows us to let go of a childish need for absolute certainty, the type of which authority and religion often promise." We must all find our own meaning in this meaningless space - this is both paralyzing and freeing. What kind of meaning do you wish to fulfill? I don't find meaning in knowing the storyline (or title/premise) of every Netfilx show... but somehow I find meaning in a good Crossfit workout.

What makes you tick?

Thursday, 22 January 2015

MSSQL, LocalDB, and upgrading to SQL 2014

This is a fairly rudimentary post about inner workings of SQL, but since I found it so damn hard to find earlier, I thought I'd share my learnings.

I started a new Web Forms project with user control in Visual Studio 2013, and had SQL 2008 installed on my local machine. The db procedure tries first to create an .SQLEXPRESS database, and if SQL Express is not installed (though I'm not totally clear on this point as I later had it installed but this next statement didn't happen), it will create a LocalDB type database instead. Here's the important bit; in SQL 2008, the version of LocalDB installed is 11.0. Here comes the trouble...

I had most of the project ready to go and wanted to upload it to our test server at work here; it's our own machine, perfectly capable, but it needed SQL Server installed. Not wanting to lean on others, I went to Microsoft and downloaded the latest version of SQL Express 2014 with tools and installed it on the server through Remote Desktop. I uploaded my project and tried to use the registration but ran into "error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details."
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
Let me tell you now, Application event log didn't help me, so I figured it was the difference in SQL versions (spoiler alert: yes).

I tried reading through the SQL Server documentation, and an SQL In Depth book for some glimmer of what might have been happening; at the time I didn't understand much of the inner workings, and thought that SQL couldn't find my .mdf database file.
(I will note here too, that originally the .mdf file in my App_Data folder didn't copy to the server properly, because it was locked to Visual Studio. After closing Vis, I recopied the whole site to ensure everything was in its place, but the same error persisted.)
 I asked Pete for some help and outlined everything that I had tried up to this point (an important trait of a software dev!). He tested out the issue, looked at the Web.config Entityframework connection string and various other application pool settings; everything seemed to be in order. So he opened up the server's SQL database manager to try to recreate the database there. I had previously found a StackOverflow (Dear Joel Spolski, Thank you. Sincerely, everyone) thread that said the localdb database name had changed in 2014 to (LocalDB)/MSSQLLocalDB, the mssqllocaldb abomination part being the brain child of some bored Microsoft employee. Felt like we were getting close!

Pete used the GUI to "Attach..." the .mdf file to the server's database. Everything looked promising, until it didn't. We received an error that said something along the lines of "... unable to upgrade the database because the file is locked." Got a locked file I feel bad for you son... Yeah it wasn't locked. It wasn't even opened. It didn't even throw an error when copy/paste-ing it around the server. The permissions didn't cause an issue either!


After fighting with the "locked" part of that message, we looked to the "upgrade" part instead, and found something to go on. SQL Server 2014's localdb is now version 12.0, and was the source of the issue!

After searching for others who had this issue, I found a StackOverflow thread that illuminated many workings of SQL Server. LocalDB is a simple, blank instance of a database. At run-time, your App_Data .mdf file is loaded into this database for interaction. Localdb lives in your SQL installation folder, whereas the data that populates it lives in your site's App_Data folder: News to me!

So I followed the (at this time) one answer provided, and used command prompt to create a new database:
sqllocaldb create "v12.0" 12.0
This created a new database named v12.0 (following the v11.0 convention), and it is version 12.0

After much fighting, this continues to be an issue. Will update when the solution comes around. Until then, I will reiterate Luigi's middle finger.




Wednesday, 20 August 2014

Synopsis of Articles Read Throughout Time

I often find myself drawn to reading articles of varied topics, but sometimes at a loss to recall the content of most. Here is a living collection of links, ideas, and thoughts of the articles and interests of my life. I hope to bring some organization to the chaos that is my reading habit.

Aug 20, 2014:
  1. $2.5 billion dollar shoe box of LSD, and the value of various objects: http://what-if.xkcd.com/108/
  2. Metabolites are injected to see their effect of pain/fatigue on muscles - turns out 'going lactic' during intense workouts is more complicated than just lactic acid: http://www.runnersworld.com/general-interest/what-causes-muscle-pain-during-hard-exercise
  3. SalesForce is a highly innovative company with a kickass CEO named Mark Benioff. He's a visionary leader who doesn't refer to their product as a CRM, but as a Utility, like water or electricity. This article outlines Salesforce's innovation techniques: http://www.forbes.com/sites/alexkonrad/2014/08/20/marc-benioffs-innovation-secret/
  4. The fastest man-hole cover ever was the result of an underground nuclear explosion. It was ejected from earth at 66km/s, which is awesome and hilarious at the same time. http://qr.ae/5HeEY
  5. Elon Musk is my hero, and a huge inspiration to me. This outlines his dark times and bright future in a 13 minute chunk of a 60 minute interview: https://www.youtube.com/watch?v=dvz1kWLMGm4

Aug 21, 2014:

  1. Was the iPhone 5C the biggest flop in Apple history? I found this title intriguing given that I didn't know the 5C was even considered a flop. Here's the Quora answer to this question: http://www.quora.com/Was-making-the-iPhone-5C-one-of-Apples-biggest-flop-product-ideas
    Here's a statistics blog highlighting the number of units sold of each type: http://www.statisticbrain.com/iphone-5-sales-statistics/ It's not a flop (I'd be proud of selling 2.6million anything), but it's not the raging success it was hoped to be.
  2. Alan Watts can be heard quoted in many Youtube videos (even the occasional electronic song), but to hear his stream of thoughts in his Conversations with Myself series is quite something: https://www.youtube.com/watch?v=8aufuwMiKmE This came up after telling a coworker about Richard Feynman.

September 5, 2014
  1. http://www.huffingtonpost.ca/diane-francis/chinese-money-laundering_b_5664319.html?utm_hp_ref=canada-business - billions of dollars leave China undetected though corrupt officials and shady businessmen, happening since 2002. 

Thursday, 19 June 2014

Handler Service for dynamic Javascript

We're creating a great app for photographers to easily sell their works online, with orders fulfilled by the PNI network - how awesome would it be to 'purchase' a print from my dad, and pick it up from Costco? Pretty rad. Especially if all he has to do is drop one line of javascript on his page.

To accomplish it this succinctly I had to build a dynamic javascript page which would allow the intake of an api-key from the users site. Now, I am aware that the big guys at Stack Overflow accomplish this with a JSON object and using StackOverflow.init({JSON_MADNESS}) kind of tag - but I need this to be fool proof and "pretty" so that someone like my dad wouldn't be afraid of it's length. I think this would go a long way to improving uptake. Also, Shane told me I couldn't do it that way. Lousy EA's. So I needed to build a script that would output the required javascript to the users page, why the heck not? Here's the (naive) flow of how I tried to accomplish this:

  1. Append a '?' string of variables to the javascript tag. Immediately dismissed as silly after trying to think of how to get the variables from the js file (uh... location? script name? parsing?). If it could be done, I didn't want to waste time coding it into submission.
  2. Pretty please can I use a JSON object? No? Fine. 
  3. A C# Handler whose call would look like "ourapi.url.com/JavascriptHandler/MrHudsonsAPIKEY" Beautiful; I'd even used an implemented code with our Google Glass app so I'd have a reference application
Here we go. There is, however, a fair bit of trickery involved with C# Handlers (from my perspective, anyway), and getting them to ignore the file extensions. More on that later. First up, lets build the Handler:
  1. Make sure your project solution has the App_Code folder. If not, simply right-click your project name and find the Add > Add New ASP.Net Folder > App_Code
  2. Right-click the App_Code folder and select Add > Generic ASP.NET Handler to create a new file. Call it what you feel appropriate; for my project I called it JavascriptHandler
  3. In the created method stubs, know that ProcessRequest(HttpContext context) is the called method when the user hits the appropriate URL, so this is where your Handler 'starts.'
Modifying the web.config file proved to be a bit of a pain though; all examples that I could find were about modifying incoming files according to their extensions instead of filenames. Essentially, foo.js was easy to redirect to a handler, however, /foo/ was not happening. Here is the web.config content for fixing up foo.js
If you have IIS6.0 (I did not, but that took a bit of fiddling to find out):
<system.web>
  <httpHandlers> 
    <add verb="*" path="foo.js" type="JavascriptHandler"/>
  </httpHandlers>
</system.web>


If you have IIS7.0 You'll notice that the parent node is system.webServer this time:
<system.webServer>
  <handlers>
    <add verb="*" path="foo.js"
        name="JavascriptHandler"
        type="JavascriptHandler"
        allowPathInfo="true"/>
  </handlers>
</system.webServer>

If you want to know more about what verb, path, type all mean, read the Microsoft documentation (sorry, can't find the exact link at the moment).

I found that if I removed the '.js' file extension, I would get an error page saying "JavascriptHandler not found in this assembly" but it -had- to happen that way... So I queued the music, and got to work.

I eventually found a blog post on exactly what I needed: "Extension-less Routing" This resource and explanation is so well put and apparent (after the fact) that I will leave it up to you to read and enjoy. Spoiler alert: It's a bug in IIS of the mappings of "*." Kind of takes the edge of spending the morning on this.

tl;dr - To get a url like www.example.com/FooHandler/ to run a Handler, go here and apply the hotfix.

Till next time - Find me on Twitter to say hello and ask a question about my ongoing developments

Thursday, 5 June 2014

Entity Framework EF6 and Debugging Errors

I'm building a geo-location Google Glass app today. I want to compare the Glass's location to a set of lat/lon coordinates from an Entity Framework (EF) database - I'm using C# on MSVisStud2013.
Sidebar, the more acronyms and shortened names someone uses, the cooler they are (eg: Banana Republic -> B-Rep. Thanks Paul Thompkins)
Entity Framework First things first, I'm using Code-first approach as opposed to Design-First, and most of the config stuff applies to EF6 onwards so make sure you check your version. Here's some musings/learnings/thoughts from this app: Web.config: If you use EF6 you have the option to do Code-Based Configuration, but what I'm wanting to focus on here is the Web.config or app.config file that specifies the DB. Also of note is that your .config file will override any settings you provide in code. With EF6 (and simple LocalDB or SQL Express setups) your configuration is auto-generated, so when you look online to find help, don't pay attention to the suggestions to add <connectionStrings> tags to connect your db! This is taken care of in the generated <entityFramework> settings.

Debugging Errors
A good programmer must have a process to debug errors that do not (at first) make any sense. A skeleton concept I created today after watching a co-worker debug an error is as follows:
Check errors in
Permissions
Files Existence
Structure (and link/reference errors - especially when moving from local to staging environments)
Packages that need to be included (for eg Know where EntityFramework.dll should exist)