An Interesting List of Development Stuff (October 2014)

october

 

In this October edition of the ILODS, we delve into a variety of topics as usual. There are several articles as always related to developer productivity and life in general as a developer, a few discussions of upcoming changes to popular Javascript-based frameworks like jQuery and Angular and much more.

The House Always Wins

This entertaining piece in Wired introduces John Kane, a video poker junkie that discovered a software exploit in a machine that provided him with a loophole to beat the system. But instead of grabbing a few thousand here and there, he decided to test his exploits out in Vegas. Needless to say, his luck quickly ran out.

I Hate Puzzles. Am I Still a Programmer?

In this article, Zef Hemel discusses a topic that just about every developer has heard of, Puzzles. He covers the often puzzle-filled recruitment processes of many of the world’s top development companies and their reliance on this style of questioning.

Do Not Disturb

Developer productivity is something that every company will always strive to improve upon. Uri Bram recommends the best approach to handling this, is to simply leave the developers alone and let them work. Uri discusses all of the daily occurrences that can interrupt the productivity of a software developer and how these same events affect the amount of work that gets done.

jQuery 3.0 : The Next Generations

It seems like only yesterday that jQuery finally hit that 2.0 milestone and here they are yet again announcing the big three-o. In this blog post, Dave Methvin details some of the plans for the jQuery 3.0 API and many of the goals that this new release will aim to reach including performance, compatibility and being future-oriented.

Angular 2.0

This summary by Coman Hamilton briefly introduces many of the new planned features for the latest release of the ever-popular Angular JS framework. In the latest iteration, there are an abundance of “drastically different” changes from the existing versions and many developers will likely need to do quite a bit of “re-learning” when the new version hits the public. But don’t worry, you’ll have plenty of time as the release isn’t slated until “before the end of 2015″.

It’s a Bird! It’s a Plane! Or is it a Park?

Machine learning can generally produce some really cool stuff and this post from the folks at Flickr is no exception. The team came across a popular xkcd comic and decided “Hey, Let’s do that!”. The team leveraged the extensive computer vision areas of the site to create a fun application that can tell you if any picture you provide is either of a national park, or a bird, or in some cases, a bird in a national park. If this kind of thing is your kind of thing, you can read a bit more about it in this white-paper.

This is Why People Leave Your Company.

This month’s final piece is another work-slash-life one aimed at company management and leaders and why they can sometimes fail to hold onto valuable assets (i.e. you). The article goes into depth regarding many of the most common reasons at why employees jump ship (and why they stick around). It’s a great article for managers to read over to get an idea of how to retain their employees and what those same employees (i.e. you if you aren’t in management) can do as well.

99 Problems and a Bit Ain’t One

99Problems

If you have ever worked on a project that involves interactions between 32-bit and 64-bit applications and referencing their DLLs, you may have encountered this guy before :

BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

This nasty BadImageFormatException generally stems from referencing legacy libraries (or any libraries containing unmanaged code) that were not really designed to run on 64-bit machines. If your all of the code within your 32-bit libraries is managed, then you should be just fine and you shouldn’t see much of this guy at all. This post will cover two methods for hopefully resolving this issue using configuration features available in both Visual Studio and within IIS.

Troubleshooting this Issue

When running into this, I’m sure that your first instinct will be to toggle through the various settings within your Project / Solution regarding it’s Build target. You’ll probably switch back and forth from x86 (32-bit) to x64 (64-bit) and attempt to re-build and run your application countless times :

When encountering this issue, you'll undoubtedly toggle between x64, x86 and the Any CPU options. Success may vary by user.

When encountering this issue, you’ll undoubtedly toggle between x64, x86 and the Any CPU options. Success may vary by user.

Then you’ll likely say “well the Any CPU setting should work” and you’ll try that, only to again be met with the same error that you encountered previously. This isn’t always the case, as I have found that one of these settings may occasionally work, but success may vary by user and application.

Resorting to IIS

If tinkering with the available settings and targets within the Build tab of your Solutions properties didn’t help, you might need to pull out the bigger guns and try to handle this at the Application Pool level in IIS. Try opening up the IIS Manager that your application is targeting and go through the following steps :

1.) Open up your Available Applications pools within IIS :
AppPool

2.) Right-click on the Application Pool that houses your troubled Application and choose the “Advanced Properties” option :

ApplicationPoolAdvanced

3.) Set the “Enable 32-Bit Applications” option to “True”

Enable32BitApplications

4.) Finally, restart / recycle your Application Pool for these changes to go into effect :
Recycle

I’ve found that this should fix the issue a majority of the time, however there are performance considerations that you might want to review over prior to making this change. The primary one being memory availability / access to a much larger possible memory space. If you are using this approach, you might want to consider reading through this related Stack Overflow discussion on using this setting within IIS to get an idea of a few other possible side-effects.

More Information

If you want to learn a bit more about how 32-bit and 64-bit processes interact with one another within the CLR, I would encourage you to give Scott Hanselman’s post on this same issue a read. Scott describes the article as “obscure”, but again, if it is something that you are interested in, it’s certainly worth a read and goes into quite a bit of depth.

 

ASP.NET vNext Community Stand-up Series

I just thought I would post a quick recommendation to any readers out there with an interest in the upcoming vNext release for ASP.NET. Scott Hanselman recently began a weekly web series with various members of the ASP.NET Development team detailing the progression of vNext and reviewing over many of the available features in place and those yet to come.

I strongly encourage anyone out there even remotely interested in vNext to check it out. It’s extremely informative and provides a bit of a behind-the-scenes look at how the technology is being developed and might answer many questions that you have about how vNext will change .NET in the future.

Integrating TinyMCE into an MVC 5 Project

TinyMCEHeader

I thought I would take some time to address a question that has frequently appeared in a few forum questions over the past month or so and that is “How do I use the TinyMCE Editor within ASP.NET MVC?”. Since I’ve answered this quite a few times, I thought I would take a few minutes to share the process with the rest of the net so prevent this from popping up in the future.

Let’s address a few of the extremely common questions.

Can I use TinyMCE with ASP.NET MVC? Or Web Forms?

Of course you can. TinyMCE is simply a pure Javascript rich text editor that has no reliance on MVC, Web Forms or any other server-side related technology. All you need to use it is some simple HTML markup and the appropriate TinyMCE Javascript and content files (which are included within the download).

How or where can I download TinyMCE?

The easiest approach would be to download the latest TinyMCE package via NuGet through the following steps :

  • Right-click on your Project.
  • Choose Manage NuGet Packages from the Context menu.
  • Select the Online tab on the left within the dialog box.
  • Search for “TinyMCE” in the upper right-hand corner.
  • Install the TinyMCE package to your project.

If you aren’t using ASP.NET or simply do not have access to NuGet, you can always visit the TinyMCE site and download the latest version of the editor from there.

A Simple Walkthough for Getting Started with TinyMCE

Let’s create a simple new MVC 5 Application through Visual Studio. For simplicity’s sake, I’ll just be using an Empty Project with the appropriate MVC references added :

Create a new Empty Project with the appropriate MVC references.

Create a new Empty Project with the appropriate MVC references.

Next, you’ll need some way to access the TinyMCE files. Two of the most common approaches (downloading the NuGet package or directly downloading from TinyMCE) are detailed above, this example will use the NuGet approach, but both of them should be similar.

Use the NuGet Package Manager to easily install the TinyMCE Package

Use the NuGet Package Manager to easily install the TinyMCE Package

You should now see several new files within a newly created “~/scripts/tinymce” folder. This folder contains everything that you need to use and configure the TinyMCE editor.

In order to actually use the editor, you’ll need to create a Controller with a single action that points to a View. For all intents and purposes, we will call this one “TinyMCEController” and it will have a an action called “Index” and another Index action that is decorated with an [HttpPost] attribute (and will accept a class that we will define below) :

public class TinyMCEController : Controller
{
        // An action to display your TinyMCE editor
        public ActionResult Index()
        {
            return View();
        }

        // An action that will accept your Html Content
        [HttpPost]
        public ActionResult Index(ExampleClass model)
        {
            return View();
        }
}

Next, let’s actually flesh out this very simple class that will just have a single, but very important property and an even more important attribute decorating it :

// An example class to store your values
public class ExampleClass
{
        // This attributes allows your HTML Content to be sent up
        [AllowHtml]
        public string HtmlContent { get; set; } 

        public ExampleClass()
        {

        }
}

The [AllowHtml] attribute is going to by-pass ASP.NET serialization protection (which can aid in preventing nasty XSS or any other types of garbage input that might fly on it). Without this attribute, you would need to disable RequestValidation for the specified action which is a bit overkill in this scenario as you just need to check for HTML.

The next step will be to add a View that targets your Index action. Right-click on your Index Controller Action and choose the available Add View… option that appears in the context menu. In this example, we won’t be using a Layout page or a Template, so you can leave those options :

You'll just need to create a very basic View without any templating or Layouts. Usage may vary.

You’ll just need to create a very basic View without any templating or Layouts. Usage may vary.

After generating your View, you’ll need to add a few references in to target and configure your TinyMCE scripts. You’ll also need a very simple <form> element to post your content from the TinyMCE editor as detailed below :

<!-- This View uses your Model -->
@model TinyMCE.Controllers.ExampleClass
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>TinyMCE Example</title>
    <!-- TinyMCE Script Reference -->
    <script src="~/scripts/tinymce/tinymce.min.js"></script>
    <!-- Script to wire up your TinyMCE editor -->
    <script type="text/javascript">
        // Initialize your tinyMCE Editor with your preferred options
        tinyMCE.init({
            // General options
            mode: "textareas",
            theme: "modern",
            // Theme options
            theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
            theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
            theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
            theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_statusbar_location: "bottom",
            theme_advanced_resizing: true,

            // Example content CSS (should be your site CSS)
            content_css: "css/example.css",
        });
    </script>
</head>
<body>
    <!-- This will automatically post to your Index method (that is decorated with a HttpPost attribute) -->
    @using (Html.BeginForm()) 
    {
        @Html.AntiForgeryToken()
        <div>
            <!-- This will contain your HtmlContent and use the TinyMCE editor-->
            @Html.TextAreaFor(model => model.HtmlContent)
           
            <input type="submit" value="Create" />
        </div>
    }
</body>
</html>

Obviously, the configuration code that is used above within the <script> tag might look a bit overwhelming. You can visit the TinyMCE Examples page which demonstrates a few varying levels and features depending on your needs.

After adding your View in, you should be able to run your application and see the following :

Editor

Once you hit the Create button within the View, your content will be posted with its associated markup to your Controller and you should be able to see it without any issues :

Posted

Alternatives and Other Editors

Although this walk-through explicitly targeted the TinyMCE editor, it is my no means limited to just it. The same basic steps should work with any of the popular client-side Rich Text Editors such as Redactor, CKEditor, HTML Editor and more. You’ll just need to include the proper references and content files and ensure that you are targeting the proper element when using the configuration code.

It should be noted that there are a variety of other NuGet packages out there for using TinyMCE as well if this felt like too much of a hassle. The TinyMCE.MVC relies on an HTML Helper to build and wire up your editors for specific areas and can be useful if you don’t like messing with Javascript at all. It’s just a matter of preference.

An Interesting List of Development Stuff (September 2014)

sept

Pardon the brevity of this month’s ILODS release, it’s been a month of deadlines, crazy news and all sorts of other things. Anyways, I hope that you find some of these links entertaining, useful or some balance of both and I’ll try to make October’s list a bit more complete than this one.

Lessons from a Lifetime of Being a Programmer

In this article, Andrew Wulf reflects on many of the things that he has learned throughout his career, most of which you would never be taught without experiencing first-hand. Depending on how long you have been writing software, some of these may be familiar and others you might not encounter for a while. Hopefully this can serve as a reasonable “beware the ides of March” so you can keep a look out.

Algorithms, Get Ya’ Algorithms Here!

Learneroo has managed to pack a huge amount of algorithmic-based knowledge into an easy to follow series of snippets and challenges to make learning them easier. The challenges gradually get progressively more complex as do the topics (from basic data structures to matrices, weighted graphs and pathing algorithms).

10 Articles Every Programmer Must Read

This excellent compilation of articles from the folks at JavaRevisited provides an overview of various topics and basically explains “What you need to know about _____ if you are a programmer”. Topics include Memory, Time, Unicode, URLs, SEO, Web Development, Networking, Strings, Security and more!

Getting Schooled by the Developers of the Future

In this Information Week article, it discusses the recent rise in some European nations of adopting and teaching coding practices throughout primary and secondary schooling and actually even creating entire “Coding Schools” to help mold the minds of the world’s future developers.

Debugging courses should be mandatory

This this article, Stanislav Nedelchev provides an overview of the importance of debugging and why it should be taught properly as a course. As developers, we use various approaches to debugging in our daily lives and if developers were introduced to these things early in their careers (or even in school / college), they might find it easier to resolve problems on their own without aimlessly “googling” around the net.

An Interesting List of Development Stuff (August 2014)

August

In my continual effort to catch up on this seemingly endless back-log of blog posts, this monthly installment of the ILODS is quite a bit late. This month covers a few different topics primarily focusing with a few database-oriented topics as well as the usual sprinkling of personal / professional related articles.

3 Highly Effective Habits of Remote Developers

“Work from Home” and  “100% Remote” are often found in the titles of job descriptions that many software developers dream about, but it isn’t easy. You might think that waking up and spending hours coding sans pants might be as easy as it sounds, but it’s difficult to do well. This article by Walter Chen discusses a few key changes that you might consider making if you are going to be working remotely and you want to do it effectively!

The Future is Now : Hyperlapse is Here!

Are you a film-maker? Do you have tons of unnecessary footage that might be cool if usefully compiled into a shorter compilation? Do you like practical Computer Science related research? Well, if you answers “Yes” or “No” to any of the previous questions, then I would recommend checking out this recent article on Microsoft Research’s Hyperlapse algorithm and watching it in action.

Document Databases Meet Azure

If document databases like NoSQL are your thing and you are big into the cloud, you might enjoy the announcement of Microsoft’s DocumentDB. A A fully-managed, scalable, NoSQL document database service.

Don’t Call Yourself a Programmer

In this much needed article by Patrick McKenzie, he discusses the importance of what you call yourself in your career and how it might affect you in the long run. “Programmer”, “Coder”, “Software Developer” are generally all clumped together as the same thing, but Patrick demonstrates that what you call yourself can matter. This is just one of the many insights this article provides and I encourage any one that writes code to read.

What ORMs Have Taught Me : Just Learn SQL.

This article by Geoff Wozniak discusses his thoughts on the recent rise in ORM (Object Relational Mapper) usage in the past few years and some of the detriments that come along with it. While writing pure SQL may go against these trends, he argues that it is still better than letting an ORM do all of the work (incorrectly) for you.

Compute Magazine and Appreciating the Internet

This Ars Technica piece turns back the clock to 1985 and what you might have to do to find a code snippet. Before the days of Stack Overflow, github and all of the other sites with code that we know and love, there was paper. That’s right, if you wanted to know how to code “Balloon Crazy” for the Atari, you needed to swing by your local newstand and pick up a copy of Compute Magazine, which ever so kindly included the game in BASIC, which was a heck of a lot better than when it included the machine code implementations.

Appreciate the internet.

 

 

 

A Quick Fix for Responsive Bootstrap Menus on Windows Phone

bootstrap-in-windows-phone

During a bit of site testing, I encountered a rather strange bug when viewing a site that was developed using the incredible Twitter Bootstrap. The Responsive collapsing navigation menu didn’t appear to work at all and all of the menu items that were present were all jumbled around. It not only looked bad, but it severely hindered the usability of the site at all.

After some research, I came across the following snippet that appeared to resolve the issue. Simply paste this into the <head> section of your application and it should hopefully resolve your Bootstrap issues on Windows Phone devices :

<!-- Bootstrap Fix for Windows Phone -->
<script type='text/javascript'>
        (function() {
            if ("-ms-user-select" in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/)){
                var msViewportStyle = document.createElement("style");
                msViewportStyle.appendChild(document.createTextNode("@-ms-viewport{width:auto!important}"));
                document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
            }
        })();
</script>