You are currently browsing the category archive for the ‘programming’ category.

A tall high-five to the employees at Double Fine.  That cool indie game company out of San Francisco headed up by the legendary Tim Schafer.  Why? do you ask. Well let me tell you.  

 

My eldest son just finished the sixth grade where he was in the gifted program.  This year his teacher decided to try the Genius Hour program in her classroom.   Genius hour is a movement that allows students to explore their own passions and encourages creativity in the classroom.  It provides students a choice in what they learn during a set period of time during school. The teacher planed to have a few Genius Hours throughout the year.  The first two Genius hours the students may pick any subject that they don’t already know about.  The third Genius hour the students needed to pick a future career.  After the students learn about their subject they put together a report and short presentation to explain what they learned, etc. to the rest of the class.

Genius Hour Logo

For his first Genius Hour he chose ink as a subject to learn about.  He never really said why, “just because I was interested in it”, he would say.  Okay, cool.  He sure has brought up some interesting ink facts over the last few months I must admit.  I never did see his presentation, but I believe he received a perfect score.

His second Genius Hour was on building games in Unity3d.  He went through one of their tutorials to build a top-down space shooter game.  This was followed by a presentation of what he did and what he learned. One conclusion of his project he discovered he prefers is creating content and story-lines over hacking on code.

Space shooter imageIt’s his third Genius hour, future career, that I am writing about here.  The teacher had the students research the chosen career and interview someone in that field. My son chose, “Senior Developer at an Indie Game Company.”  As a programmer myself, this sounded interesting.  And who wouldn’t want to create games for a living? I know I would love to! It seems natural that he would pick game development of some type. Since he was very young, at least three, he would make up games all the time to play with people.  His Grandmother Debbie played these games with him the most.  She would say they are really creative, though, of course, skewed for him to win.  ;)  He has continued to create games with parents, friends, neighborhood kids, etc. and they are much more fair now (so we think… j/k).

As time went on an his deadline came closer I kept asking him how things are going.  He usually responded that he was researching about the job but had not found anyone to interview.   I thought he may be able to interview me, though honestly I am, at best, an aspiring game developer.  I thought of a few friends at work, but they didn’t fit well either.  Until one day I thought of Double Fine. Oh that would be perfect!

I first heard of Double Fine through their Kickstarter, “Double Fine Adventure“.  I have always loved Tim DoubleFine logoSchafer’s games and the fact he wanted to raise money to build one without the bureaucracy and bullshit of production companies. I’m all for it, sign me up!  On top of that they planned on filming the making of the game and provide that movie to backers.  When I saw this, I had to have a copy of the movie. Mostly because I hoped it could give an inside view for my son on what goes in to these computer games he loves to play and design.

So my next question was, how to contact them?  I started with the basics, the about/contact page on their website.  I found a general email address and started crafting an email.  It was a horribly written email, I have no idea what I was smoking at the time. My wife still loves to rib me about my appalling use of the English language.  Though this didn’t matter.  I sent the email on Friday, April 25th at 17:32 Central Time.  I didn’t expect to here back from anyone until the following week.  By 18:02 that same day I received a response which started out with:

“I’ve forwarded your e-mail to the whole company and there are already a few that are more than happy to oblige. You should be getting a separate e-mail from one soon.”

What!? Are you kidding me? That is freak’n awesome!  I really didn’t think anyone would really be interested.  I was flat out wrong.  A few seconds later I received an email From Ben Burbank, a senior developer at Double Fine.  Him and another showed interest and agreed to an interview.  After a while there where a few more who were interested as well.  At this point I was kind of hoping to hear form Tim himself, though I knew that was a pretty tall order.  The overall response from the company’s employees was so warm.  They expressed so much interest in helping.  It was refreshing very appreciated.

I had my son plan out the time and interview with Ben and others.  He needs to learn these things, I got him the contact, he can run with it.  Which he did pretty well.

The day of the interview Ben and others spent close to one and one-half hours on Skype with my son.  That was so completely awesome.  I am so happy I reached out to Double Fine, the results turned out better than I had hoped.

My son finished his interview, wrote up his paper and completed his presentation all on time.  He “winged” the presentation, which I wasn’t too happy about.  Though he needs to learn in his own way.  His score reflected his input.

It is now a couple of weeks into Summer break and he has not stopped creating.  He put together a mod pack for Minecraft to design some mini games around. And just today, designed some floor game using dice and army men which he said he really liked the outcome of and plans on writing up rules/instructions.

Needless to say, but I will anyway, I am so proud of my son.

I have real simple advice for him, “Never stop being awesome.” Everything else will fall in to place.

 

To the great people of Double Fine:

Thank you so much for taking time out of your day, your life, to give a little of yourself for the benefit of my son. I really appreciate you. And hey, you never know, maybe one day he may be the Senior Developer in an Indie Game Company at your company.  :)

If you are every in the Chicago area, give me a call, I’ll buy you a drink.

 

I love computer games.  I have been playing them since I was able to use a computer.  I can’t say I am an avid gamer, I really don’t have the time for that, but I sure enjoy playing them.

MC-Brettski111

One game I play often, and usually with my sons, is Minecraft.  A sandbox adventure game which we have found very fun.  We have spent countless hours building different things, going on adventures and PvP fighting.

On a cold night in November I started digging in to MinecraftForge.  A modding system for Minecraft.  In short time my oldest son and I created two ‘Mods’ for Minecraft: Stonecraft and GrackMod.

I really enjoyed manipulating the game play.  I found it very satisfying to interact with items we added to the game.  Play with rules we developed.  It was just cool.

A month or so prior to this a friend of mine introduced me to Unity3d.  A game development environment which allows you to release 2D and 3D games to many different platforms. And you can do all your scripting in C#!  JavaScript I believe is the other scripting language available.

Unity_Pri

Acting on the bug which bit me writing the Minecraft mods I downloaded Unity3d and started playing around.  Quickly I figured out this stuff is pretty complex, there is simply a lot to it.  Off to the tutorials!

The first tutorial I found was a top-down shooter game called, Space Shooter.  You fly a simple spaceship and shoot asteroids flying toward you.  It’s a basic 3d game which covers many of the very basics of building a game in Unity3d. My version can be found here.

Of course I couldn’t leave the tutorial as is.  Once built I added a high score, increasing difficulty with more asteroids and faster asteroids.  The overall experience was good and I want more!

Since I can’t draw for shit, and am not very creative with design tools, I plan to stick to the 2d world of gaming.  Modeling 3d objects just scares me.  So you may ask, where do you plan to get content?  Well, two main sources, first, is my son who is a better artist than he realizes and second I will end up buying available content.  I have found some decent stuff already (links needed) and I assume I can find someone to create some stuff form me.

Next on the list is to build a tower defense game.  I found at least one tutorial to build one.  It’s not 2d but  I am hoping it will provide more depth into maintaining more cloned prefabs, controlling their paths and player’s placing items.  Hey, who doesn’t like tower defense games?

See one of my ultimate goals is to build a SimTower type game.  A game I really enjoyed in the past, which doesn’t work on most new hardware (though I do still run it in an XP VM on my Win8.1 box!).  Can I improve on the game?  I have no idea, but I am going to build my version and see how it goes.  I don’t plan to get caught up in cloning the old game, I just want to take it a step (feature) at a time and see where it goes.  I think it will be a lot of really-frustrating fun to build.  The whole reason I build things in the first place.  What fun would it be if it was simple?  It would be boring and be lame.

Octocat

I’ll update progress as I continue tutorials and build new stuff.  I plan to keep all of it available in GitHub so others may use it for examples or whatever.

All my main development machines are now running Visual Studio 2012.  I have a few new projects in VS2012 and have begun updating my old projects to it as well.  I ran into an annoying issue today that I need to post.

My Blog by Email site was built using VS2010 and ASP.NET MVC 3.  My new machine, which I am working on right now, is running Windows 8 and VS2012.  Recently a new user started using the site and discovered a few bugs I needed to get fixed.  I cloned the repo from Bitbucket and opened the solution in VS2012.

My first tip-off that there was an issue is when the Migration Report displayed 7 errors all on the _bin_deployableAssemblies\ folder.

BlogByEmail\_bin_deployableAssemblies\Microsoft.Web.Infrastructure.dll: Failed to backup file as C:\vsp2k12\BlogByEmail\Backup\BlogByEmail\_bin_deployableAssemblies\Microsoft.Web.Infrastructure.dll 
BlogByEmail\_bin_deployableAssemblies\System.Web.WebPages.Razor.dll: Failed to backup file as C:\vsp2k12\BlogByEmail\Backup\BlogByEmail\_bin_deployableAssemblies\System.Web.WebPages.Razor.dll  (... Plus 5 more files)

My second is when I went to run the project and the build failed for the same 7 files.

If you recall the _bin_deployeableAssemblies folder is used to aid in bin deploying MVC 3 applications to [shared] hosts which don’t have ASP.NET MVC 3 loaded.  You can read more about it here [@haacked.com].

It turns out this isn’t required in VS2012 as I found here :

Starting with MVC 3 Tools Update we are now using Nuget package references, which means that your project is automatically bin-deployable. Since the tooling gesture is no longer necessary it was removed from VS 11.

The fix here is really simple.  Remove the files and _bin_deployableAssemblies folder from your project.  Everything should compile just fine.

Now the one part I have not figured out is where or how we get the files that used to be in _bin_deployableAssemblies.  I don’t see them in the bin folder as I assumed they would be.  I will need to do some test deployments at my host, Arvixe (I think they didn’t have MVC 3 loaded).  Add a comment below if you h ave some knowledge around this.

I ran into a styling issue last night and it is driving me nuts.  I have found a work-around, but I want to see if I can figure out how to do this way.

I have a span tag which I am using for a button.  This button calls a JavaScript function to test blog posting settings.  I am using a span because it was easy enough to style.

CSS:


#VerifyBlogClick {
/*#696969*/
color:#575757;
border:1px solid gray;
background-color:#eee;
padding:2px 5px 2px 5px;
margin:0 0 0 13px;
border-radius: 2px;
}
#VerifyBlogClick:hover {
color:Black;
background-color:#bbb;
cursor:pointer;
}
.verifierRunning {
padding-right:30px;
background-image:url(ajaxloaderBlue.gif);
background-repeat:no-repeat;
background-position:right;
}

HTML:


<span id="VerifyBlogClick" onclick="javascript:verifyBlog_click()" title="Tries to send an unpublished test post to your blog">Verify Blog</span>

JavaScript:


$('#VerifyBlogClick').addClass('verifierRunning');

// ... stuff

$('#VerifyBlogClick').removeClass('verifierRunning');

Basically what I have here is a span styled like a button.  When the button is clicked I add the class .verifierRunning to the span tag using jquery. This class changes border-right to 20px and defines a background image (a loading image).

The problem that I am running into is that any properties defined in the id selector are not overridden by the class.  It seems that id’s always have a higher precedence than a class.  I can’t believe that there isn’t a way around this, though I have not been able to find anything on the web which will work.

My work-around this is to change VerifyBlogClick to a class.  I don’t mind doing this, I would just like to find out a way to do this the other way.

I just took the long silly way around to return a json result to  a page.  I kept trying to send a json string back as just that, a string and it just wouldn’t work.  Whenever JavaScript received the string it didn’t know what to do with it, except treat it as a string of course.  I banged my head against this one for too many hours.  Though my persistence payed off.

As the night got later (I think it’s 03:00 about now) I decided to figure out how others are returning json object from ASP.NET MVC.  It isn’t as simple as it should be, but not too difficult.  The biggest issue, as with much in MVC land is the huge lack of documentation.  So looking up something like JsonResult, yields a pretty useless help page.  So more time had to go into discovering on how to actually use this cool new result type.

It turns out you can set up and action with a return type of JsonResult (it’s usually ActionResult) and have that action return a json object.  I am not even going to pretend I can do this from other objects like json.net (from James Newton-King).  I am using this to return a model as json which populates my form with on-demand instructions.  This library rocks, but I digress.

The basic structure I used is a dictionary object

public JsonResult MyAction()
{
  Dictionary<string, string> dict = new Dictionary<string, string>();
  dict.Add("keya", "valuea");
  dict.Add("keyb", "valueb");
  return Json(dict);
}

That’s pretty much it in a nutshell.  Json() is a new web helper in MVC3.  You can find it at System.Web.Helpers.

I saw one example where you can build an object on the fly, but I couldn’t get it to work.  It basically looks like this:


//....
return Json(new {keya = valuea, keyb = valueb};

The dictionary generic works for now.  If you know of a better way, please let me know.

While working on Blog by Email (http://blogbyemail.com) I came across the necessity to create my own HTML helper class.  For those who don’t know helper classes “…reduce the amount of tedious typing of HTML tags that you must perform to create a standard HTML page.”

The registration request form on the site was getting hit pretty hard by spam bots and I was getting tired of cleaning up the mess, so I decided to add a captcha.

ReCaptcha is what I decided on and started down the rabbit hole.  First of all there was only ASP.NET examples.  Since I was writing this in ASP.NET MVC, I wanted to use a more, “MVC” approach to it.  I came across an post on Devlicio.us named Using ReCaptcha with Asp.Net MVC.  The post covered exactly everything I need, what it was missing is details around its steps, specifically Step 5 – Create a Html Helper to build and render the Captcha control. It shows the current code and nothing else:

public static string GenerateCaptcha( this HtmlHelper helper )
{
  var captchaControl = new Recaptcha.RecaptchaControl
    {
      ID = "recaptcha",
      Theme = "blackglass",
      PublicKey = -- Put Public Key Here --,
      PrivateKey = -- Put Private Key Here --
    };
  var htmlWriter = new HtmlTextWriter( new StringWriter() );
  captchaControl.RenderControl(htmlWriter);
  return htmlWriter.InnerWriter.ToString();
}

My first thought, is cool, I can just add an HTML helper to the view to generate the captcha, this is a good approach.

First stumble, that is a method, that needs to go into a class–what class should it go in to?

No problem, I’ll just look up creating helper methods.  That was an easy search which rendered an ASP.Net site page, Creating Custom HTML Helpers.  Great, now I have my examples.  I matched it to an extension method; okay, I get that, I have used those before.  I learned the syntax and added it to my site.

It doesn’t come up in Inteli-sense.  What can it be.  I changed all kinds of things around, from renaming the class, to changing the method name.  I was wondering if it followed some naming scheme like controllers and models do.  I don’t recall it needing to.

I decided to browse though the comments, see if anyone else ran into this.  And there is was, someone named, ianchadwick mentioned a way to make the namespace global in the web.config.  Well, damn, that is it, the view doesn’t know about my namespace BlogByEmail.Helpers.  I added @using BlogByEmail.Helpers; to the top of the page, and everything fell into place.

To use the helper in the view simply use @Html.Raw(Html.GenerateCaptcha())

Html.Raw is needed to keep MVC from HTML Encoding the output.

Damn I feel dumb sometimes.  …back to my code!

For some time now I have wanted to post to a blog from an email account.  Some blog engines these days have this functionality, like WordPress and TypePad.  Some through plug-ins and some built in.  I have used the WordPress plug-in on a test installation, and it works pretty well.  Though WordPress is probably my most preferred blogging engine, most of the time when I am installing blogs, it’s on a Microsoft stack and I am not big on running PHP on Windows.  On the Windows stack I really like using Blogengine.NET.  I find it to be a very capable blogging engine.  The only problem is, at least to date, I have not found a plug-in for it to post by email.  What it does support though is XML-RPC.

With the Help of the XML-RPC.NET library and a few hours away from the family, I through together a rough blog posting application.

I added in OpenPop.NET, a popmail client library I have used in the past, and now have a way to collect emails.  Now all I needed to do is tie them all together.

The outcome is Blog by Email (http://blogbyemail.com).  An online service for setting up email accounts to post to blogging engines.  Besides looking like crap (I am using the generic MVC layout), it is functioning well. I am hoping my buddy will give me a hand coming up with a real design for the site.

The biggest challenge to setup posting to a blog is finguring out what XML-RPC entry point is, and what the blogging engine uses for the Blog Id.  The blog id is often the name of the blog, but I found in MovableType it uses the actual integer value assigned to that blog.  Bit of a pain to get that value.  A cool aspect of MovableType is that it generates a password to use for posting via XML-RPC.  A nice security feature.

Speaking of security, to protect the users entered credentials I am encrypting both usernames and passwords in the database.  Also, each user is given a unique key pair when the sign up with the service.  Little steps to make it harder to get this information in case someone does hack the application.

 

If you need to post to your blog from a POPMAIL email address, give Blog by Email a try.  The service is free (at least until it grows to the point where it needs a bigger web server).

While the site is getting off the ground and I get the code stable, registration is closed.  There is a form request an account.  I am looking for people to help test the system, so if you are interested please let me know.

Brett

http://blogbyemail.com

It has been /interesting/ working with Entity Framework (EF).  With my first couple of sites I used Linq to SQL, and I really liked it.  It’s pretty simple once you get the gist of it.  Though now Microsoft recommends the use of Entity Framework (EF) and Linq to Entities.  Well using Linq against EF is really no different then Linq to SQL so the transition was pretty simple.  Here is a good beginner walk-through I ran into.

The part I like most about EF is Code First.  I can define my classes, relationships and inheritance and EF creates the database for me.  Need to add some properties, no problem, add them and remap (or recreate) the database.

Sure there are a few short comings like no foreign key constraints on none primary keys.  This is a pretty big deal, but nothing that can’t be handled in code (at least for my small sites).  I wonder how it’s handled with database first models, I’ll have to experiment with that some day.

The other shortcoming I found is with date fields.  It seems EF automatically works with database datetime2 field types but only creates datetime field types in its database create scrips.  This perplexed me for some time until I discovered what was really going on, and the temporary fix is pretty darn simple.

Each time you create a new script by running “Generate database from model…”–the script which is created is opened in Visual Studio (eg. myModel.edmx.sql).  Before you run it or close it, do a find and replace on the file.  Yes you guessed it, find datatime and replace it with datetime2.  Simple straight forward and works like a charm, as long as you remember to do it.

Happy coding!

I just finished a new file hashing tool, BD File Hash, which is hosted on CodePlex under the Microsoft Public License (Ms-PL).

The goal behind this Windows tool is an easier way to verify files you download from the internet.  Many applications, ISO’s, and other files usually list a hash with them.  This hash is used to verify the file you downloaded is the same file the author meant you to download.  It prevents you from using corrupt or exploited downloads by allowing you to verify the file before you use it.

The problem I had with most file hashing tools, is that they needed to be run from a command line, or you had to open the hash value into a text editor and copy/paste it into the hashing application to be compared. So I wanted BD File Hash to be a convenient way to verify files using hashes.

BD File Hash has the following capabilities:

  • Right click any file and select BD File Hash from your Send To menu
  • Use a file picker to select the file with the authors hash value, it will automatically be parsed from the file and entered into the BD File has application
  • Easily hash to files to see if they are the same
  • Supports MD5, SHA-1, and SHA-256
    • Please recommend any other hashing algorithms you may need.
  • Save your default hash type to the one you use most often

BD File Hash requirements:

  • .NET 3.5 SP1
  • Windows Installer 3.1

Give BD File Hash a try today!

Unicode Characters converted to ASCII string

I hacking together a report today and discovered the Unicode text I received was actually in Unicode not ASCII.

Basically I have this:  こんにちは

And I want this:  

By using AscW(Char) you can convert a Unicode character into an integer value.  Add some delimiters to encode the string and you have a Unicode HTML Entity Reference.  It isn’t perfect, as AscW(Char) sometimes returns a negative number, which isn’t allowed, though this is an easy work around explained here.  It is used below.

Public Function UnicodeToAscii(sText As String) As String
  Dim x As Long, sAscii As String, ascval As Long

  If Len(sText) = 0 Then
    Exit Function
  End If

  sAscii = ""
  For x = 1 To Len(sText)
    ascval = AscW(Mid(sText, x, 1))
    If (ascval < 0) Then
      ascval = 65536 + ascval ' http://support.microsoft.com/kb/272138
    End If
    sAscii = sAscii & "&#" & ascval & ";"
  Next
  UnicodeToAscii = sAscii
End Function

Now lets go the other way: ASCII string to Unicode

Now I have this:  

And I want this:  こんにちは

I remembered that ChrW(int) will convert character codes to their associated character.  I really wasn’t in the mood to write parsing logic and test it, but luckily I came across a class which does this.  I ripped out the method I needed and it worked great in all it’s simplicity.  I have included this function below:

Public Function AsciiToUnicode(sText As String) As String
  Dim saText() As String, sChar As String
  Dim sFinal As String, saFinal() As String
  Dim x As Long, lPos As Long

  If Len(sText) = 0 Then
    Exit Function
  End If

  saText = Split(sText, ";") 'Unicode Chars are semicolon separated

  If UBound(saText) = 0 And InStr(1, sText, "&#") = 0 Then
    AsciiToUnicode = sText
    Exit Function
  End If

  ReDim saFinal(UBound(saText))

  For x = 0 To UBound(saText)
    lPos = InStr(1, saText(x), "&#", vbTextCompare)

    If lPos > 0 Then
      sChar = Mid$(saText(x), lPos + 2, Len(saText(x)) - (lPos + 1))

      If IsNumeric(sChar) Then
        If CLng(sChar) > 255 Then
          sChar = ChrW$(sChar)
        Else
          sChar = Chr$(sChar)
        End If
      End If

      saFinal(x) = Left$(saText(x), lPos - 1) & sChar
    ElseIf x < UBound(saText) Then
      saFinal(x) = saText(x) & ";" 'This Semicolon wasn't a Unicode Character
    Else
      saFinal(x) = saText(x)
    End If
  Next

  sFinal = Join(saFinal, "")
  AsciiToUnicode = sFinal

  Erase saText
  Erase saFinal
End Function

I didn’t always understand why you wouldn’t just want to work with the Unicode characters themselves.  Well is seems that not all applications treat Unicode the same way and the characters may be changed.  If you are storing and passing around a text representation of the characters there is no way for them to be misinterpreted.

One of the neatest things I like about this is that I can just put the text represented Unicode in a web page and the browser will automatically convert it to Unicode characters.  This is the reason I needed to use an image above to show what the text represented Unicode looks like.  If I just put the string there, it is converted by the browser when displayed.

If you have been to this post in the past, you have probably noticed that it has changed a bit.  That is because I had it all backwards! Yeah well it happens.  I said I want wanted to change Unicode characters to Ascii string, but the code actually was for the other way around.  Well I finally got around to fixing this and made sure that code worked before displaying it.  I hope this helps someone out there.

Twitter Updates

Follow

Get every new post delivered to your Inbox.

Join 176 other followers

%d bloggers like this: