Category: Random Coding

  • Server upgrade!

    Server upgrade!

    I upgraded my server after 5 of so years and it is still as fun as ever to see the performance gains! I’ve seen this site load as fast as 300ms now and everything seems so silky!

    I’ve been on a weird productivity funk ever since my vacation two months ago and I can’t seem to find the energy to go as big on my game development projects as I did. Instead, I’ve been spending my time in the gold mine of HOTS, migrating sites to my new server and playing with Docker.

    I will get back to adding some of those extra features for the BlackJack game then I’m going to take a learning break to try to figure out how to plug in proper unit testing in Unity and then get back to TanksVsJellyfish.

    Regardless, I hope that all of you are doing well and feeling fulfilled!

    Read the rest

  • Blackjack – Card Counting trainer

    Blackjack – Card Counting trainer

    The first release is finally complete! Download for Android on Google Play now!

    If you have an Android device, please feel free to download, learn and win at Blackjack! If you want offer me any feedback to make it better, I also super welcome the feedback.

    There is a bug that causes the game to go into a locked state that I cannot seem to recreate and if anyone could give me reliable recreation steps, I would greatly appreciate it.

    Additionally, I am going to add a help section to explain all of the abbreviations and interface icons. I hope that some of it is self explanatory, but understand if my UXing skills are terribad.

    The gist of playing before I can formally create a tutorial and help:

    The yellow icon is the visual guidance to playing basic blackjack strategy with the illustrious 18 variants and counting with hi/lo.

    RC = running count
    TC = true count
    CR = … Read the rest

  • Does Card Counting work in Black Jack?

    I’ve heard a few times in passing that you can count cards and beat the casino in Black Jack. Over the years I spent a little time understanding the basic premise, but only got a shallow idea and never knew if it actually worked. I don’t often go to the casino and I have a crazy low risk tolerance when I do go. Usually I pull out $200 bucks for gambling and then come home empty handed. So do I actually know how it works? Each time I go, I always think I should really test this out and find out.

    So I wrote an implementation of the BlackJack game. The rules of BlackJack card counting that I found here and also a simulator. Most YouTube or web content shows the basic ideas of how to count and bet. However, it misses some important details that I was able to uncover with my simulator.

    I’m prepping a video for it … Read the rest

  • EntityFramework – Migrations Gotchas

    Wanting to be a little more thrifty on a side project, I decided to roll with MySQL and EntityFramework. There were a few gotchas, outside of the normal tutorial and I’m just putting this out here to save time for anyone else who may have had to deal with the issues I ran across.

    Data Model defined in a separate library

    Most of the 101 examples have the data model included in the MVC, WebAPI or Console/UI project that is typically the startup project. However, if you have your data model defined in a separate project don’t forget to add the “-StartupProjectName” argument when invoking any of the migration commands.

    ex:

    enable-migrations -StartupProjectName [DataModelLibName] -ProjectName [DataModelLibName]
    add-migration -StartupProjectName [DataModelLibName] -ProjectName [DataModelLibName]
    update-database -StartupProjectName [DataModelLibName] -ProjectName [DataModelLibName]
    

    This argument is actually telling the migration command where to look for the configuration of the providers and the target database to migrate. If you have everything configured in the shell startup project, then … Read the rest

  • XamarinForms – Overriding a ContentPage with a custom PageRenderer on Android

    The short version:

    If you want to have default behavior on all platforms except for Android. Do the following

    • Create your content page with all of it’s goodies
    • Create a custom PageRenderer
    • In the OnElementChanged function
      • Cast the Context property of the renderer to the Activity type associated
      • Take that value and execute the SetContentView method while passing in your new view!

    The awesome story version:

    I’m building a Xamarin Forms application which has a default implementation in most platforms and a special snowflake behavior on Android. While working through the Xamarin documentation I realized that custom renderers were the way to go.

    The default behavior for all platforms is performed through a WebView, which has some custom logic when pages are navigated. While the functionality still works, it doesn’t feel seamless. However, in Android there is already native functionality that really improves the user experience, so I wanted to make sure that if I was on the Android platform, … Read the rest

  • ** Update ** EntityFramework detecting complex type with database first

    Originally, I posted a question on StackOverflow

    http://stackoverflow.com/questions/21630431/entityframework-detecting-complex-type-with-database-first

    While we’re still not using complex types, we’ve worked out a mechanism to preventing our developers from breaking the autogenerated models when re-generating from the DB.

    We’ve altered the T4 template generated by EF.

    First we’ve created a method in the CodeStringGenerator class

    public string BaseClassAndInterfaces(EntityType entity)
    {
        var properties = new List(_typeMapper.GetSimpleProperties(entity));
        bool hasAuditFields = false;
        if (properties.Exists(property =_code.Escape(property) == "CreatedBy") &&
            properties.Exists(property =_code.Escape(property) == "CreatedDate") &&
            properties.Exists(property =_code.Escape(property) == "UpdatedBy") &&
            properties.Exists(property =_code.Escape(property) == "UpdatedDate"))
        {
            hasAuditFields = true;
        }
    
        return string.Format(" : {0}", hasAuditFields ? "Auditable" : "NotificationObject");
    }
    

    If it detects that a table contains those auditing fields, then it prepares to generate the class with a base class “Auditable”, which has those four properties. You’ll notice that if we don’t see the auditing properties, we then set the base class to NotificaitonObject. That’s because we’re still using our own variant of the … Read the rest

  • Gitmongous Distributed Repositories

    So it’s been a little while as I’ve been busy assisting my beautiful wife on some projects she’s had, I’ve been at the tail end of a working marathon and finally I was on vacation last week. However, I’ve got a bit of free time now and I wanted to share an interesting downside of distributed version control systems.

    Sometimes, you’ll have team members who will carelessly deposit massive multi-megabyte files, they’ll alter it to store more multi-megabyte files. These files then duplicate everywhere and make merging insanely painful from the sheer size.

    There are solutions to this problem, but it’s a multi-step process that involves a priest, a rabbi, a shaman, 6 shots of vodka and a jump rope.

    With that said, this isn’t entirely the same problem in a remote version controlled repository like Subversion. If some unrelated branch has all of the megafiles, you’re not sitting there staring at the progress indicator, scrolling in a pattern that … Read the rest

  • 100 YouTube Subscribers!

    Yay!

    So I’ve reach a small milestone of 100 YouTube subscribers! Besides the one or two friends that I have, most of them have discovered me either via the TopCoding video 1 or the RandomCoding Visual Studio snippets video.

    After creating another 4 TopCoding videos, neither seemed to have the reigning success of the first video.

    The Random Coding video 2 had a decent number of views because it was a difficult solution to find and I posted it on StackOverflow. However, all others are relatively unpopular.

    I’d like to increase the reach of my videos, but I don’t want to radically change the intent. I want my videos to all be related to programming, yet have some entertaining spin.

    I’ll start thinking of some ideas for May, but want to spend most of my energy on Conflicademia.

    If any of you do have suggestions, I’m all ears!… Read the rest

  • Facebook Unity – Keystore missing

    So I just recently noticed that the Facebook team wrote a unity plugin to make your games easily integrate with Facebook! I’m super excited to get Conflicademia connected so off I went.

    Apparently, a while ago, I attempted this before and found an old Facebook assembly that I couldn’t get working. It also conflicted with the new library and so step one was to remove that booger. This is not likely something anyone else will have to do.

    The next thing was to correct an issue with the imported module. In the Assets/Facebook/Editor/android/FacebookAndroidUtil.cs class, there is a method to return the debug key store path. When imported it looked like the following

    private static string DebugKeyStorePath
    {
        get
        {
             return (Application.platform == RuntimePlatform.WindowsEditor) ?
                System.Environment.GetEnvironmentVariable("HOMEPATH") + @"\.android\debug.keystore" : 
                System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + @"/.android/debug.keystore";
        }
    }

    Problem is that the HOMEPATH variable doesn’t include the root drive on my machine. I assume it must include the root drive on the devs @ Facebook … Read the rest

  • It’s soooooo obvious!

    While using the Newtonsoft Json.Net library I received the error

    "Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property."

    When attempting to generate a schema for some types that were created that have circular references. My types were created in EntityFramework database first strategy, so I didn’t want to figure out how to hack the T4 generator to add the Json attribute, and I didn’t quite understand what it mean by using the “UndefinedSchemaIdHandling property”. I suppose it might seem obvious to the author as when I searched the interwebs for an example, this was one of the first results

    http://json.codeplex.com/workitem/22569

    His response was pretty much recursive error output.

    if (user.hasError)
    {
      print(error);
      while (user.doesNotUnderstandsError) 
      {
        print(error);
      }
    }

    Now, unfortunately, I was in that loop for a little bit, looking at the method overloads, thinking about maybe a partial class to add the attribute, staring at the … Read the rest