Posts

Showing posts from 2013

Cloning form elements in Internet Explorer

So, I ran into an issue when cloning form elements. The scenario was as follows: For an insurance company, a customer was reporting that a damage had occurred to one or more insured items. After adding general information about the event (it happened at such and such a date, while riding a bicycle), the customer added multiple items of goods that was damaged during the event. As a part of the damage goods part of the form, was a dropdown: Report a damage Date: What happened? What was damaged? A brand new Apple computer ... + Add item The idea was, that clicking the button would duplicate a part of the form, which would effectively increase the collection of block items in the associated view model: public class ReportViewModel { public List<BlockViewModel> Blocks { get; set; } } public class BlockViewModel { public string Title { get; set; } public List<QuestionViewModel> Questions { get; set; } } The solution worked pretty flawlessly too! For completeness

Multiple date formats in jQuery UI's datepicker

jQuery UI's datepicker supports one public format and, optionally, one internal one . However, if you're wanting to support multiple public formats, you're out of luck. In my scenario, I wanted to support yy-mm-dd (yyyy-MM-dd in .NET Date Formatting lingo ) yymmdd (yyyyMMdd) Having the top-most rule in effect, entering a date like 20130901 (September 1st, 2013) would make the datepicker change my value to today's date in the specified formatting, which was not what I wanted. To fix the issue, I set the least-restrictive format (yy-mm-dd) as the dateFormat: ... and added a keydown event listener to the DOM element I attached my datepicker to, so that it would hide the datepicker as the user started to enter input: With these two modifications in place, my datepicker now supported my two date formats for manual entry, while maintaining its click functionality, formatting any clicked date as configured in dateFormat. I hope this'll save you some time,

Ease your web development - compile your Razor views!

Image
Don't you just love when - as you add or modify the service layer and models of your web code - everything just works? That is, until you hit that (partial) view that you were not expecting to be affected by your change and ... BOOM! It is extra amounts of fun, when this page is at the end of a page flow, having required that you enter a lot of data before hitting the brick wall. I found it tremendously helpful to enable Build Views  in my solutions for this reason. By enabling this single feature, whenever you build your web project, your views get built too, ensuring that silly things like typos doesn't cramp your style: To enable the feature, simply right-click your web project and unload it. Then, right-click it again and choose to edit it. Locate the tag MvcBuildViews and change it to serenity: <mvcbuildviews> true </mvcbuildviews> After this single change, save your project file, right click on it in Solution Explorer and choose to reload

Content aplenty! Recordings from recent conferences

There's been a lot of very interesting conferences of late! Starting off with Xamarin's first-ever word wide conference, followed by TechEd and then the Norwegian Developers Conference, there are videos aplenty for the curious developer! What is that? You're hoping for a few rainy days this summer? Don't be silly ;-) Xamarin Evolve Keynote How C# Saved my Marriage, Enhanced my Career and Made Me an Inch Taller Multiplatformism: Lessons learned bringing Bastion to Six New Platforms Buttons are a Hack Cross Platform Getting the Most from Xamarin Studio , your Visual Studio-replacement for Mac! Intro to Calabash , the amazing UI automation toolkit that drives Xamarin's Test Cloud ! Writing native Mac apps in C# with Xamarin.Mac . Yes, you can! Mapping on iOS and Android . Sharing up to 80% code for iOS, Android and Windows platforms, a retail app case study . Cross-platform Barcode Scanning with ZXing . Create a uniform login experience with

Reusable test base classes

(This applies to ASP.NET MVC and MSTest and Moq) When writing tests for MVC controllers that inherit from the same base, you can save yourself some time by creating a test base class that is responsible for setup and teardown of your test cases: 1) Create an abstract class that takes your base controller class as a templated argument 2) Create a public method that initializes your tests. Adorn this with TestInitialize. 3) Create a public method that cleans up after your tests. Adorn this with TestCleanup. 4) Create an abstract method that initializes your controller. Having done this, you can focus the test cases, rather than the boilerplate in your tests, simply having to override the CreateController method (step 4 above) to initialize your particular controller, given the initialized argument passed. Example Base Class Imports SecretCompany.Web.Controllers Imports Moq Namespace ControllerTests   Public MustInherit Class ControllerTestBase(Of TController As BaseC

AngleBrackets, Curly braces and the cloud by @shanselman #devsum13

Image
Speaker deck:  http://devsum.se/wp-content/uploads/2011/05/AngleBrackets-and-Curly-Braces-2013-05.pdf What would you teach someone about web programming, if you were to start today? Sc ott  tells us a story about how he wound up talking to a distinguished older engineer at Intel who was curious about web technologies. The gentleman told Scott that, in order to fire up a virtual machine at Intel, he would have to fax someone. To get a hold of a SQL server instance, he'd have to fill out forms and call people, slowing every effort down. There's now a community depot -  V M DEPOT  - access from Windows Azure, letting you fire up a Ruby Stack Ubuntu machine on Azure right away! If you're not comfortable with managing a virtual machine (managing updates etc) though, Azure supports hosted services, such as  Azure Web Sites , which themselves sit on top of virtual machines that you never have to think about. Scott demonstrates the ease at creating a web s

LightSwitch with @melaniadanciu #devsum13

Melania starts off her presentation, setting the mood by playing  The Script's Hall of Fame  ("You can be the greatest, you can be the best … The world's gonna know your name …").  Lightswitch has had its up and down and recently got a bashing with Microsoft stopping to push Silverlight. What few knows, however, is that - first off - their Visual Studio installation comes with Lightswitch pre-installed (look in your project templates (Applies to Visual Studio 2012)), and - second off - Lightswitch now produces HTML5 output alongside its Silverlight support. Jay Schmelzer, the creator of Lightswitch, describes the product as "The easiest way to create modern line of business applications for the enterprise." It can be used for rapid prototyping too, as it quickly helps you create a three-tier solution with little-to-no custom coding, leaving your more time to discuss the final product with your client, rather than spending your time writing demos

Successful Architecture for Windows Store Apps by @johanlindfors #devsum13

Goal: Simplify development and maintenance Mission: Share code and UI Tactic: Separate UI from application logic Obstacle: Abstract platform specifics Johan started off by telling us that the hints and tips he was going to focus on for his session, were not valid for single use/campaign apps. Instead, he was going to drop some valuable tips for how to write apps apps that are intended to live for a long while. I'm very fond of Portable Class Libraries, says Johan. I try to put as much logic as possible in a shared Portable Class Library, so that I can share that across my Windows Phone and Windows 8 apps. By abstractive native implementations behind generic interfaces in my PCL, I can easily inject the specific behavior in runtime, while maintaining nice code reuse. Git works very well against TFS in the cloud, by the way. If you're using shared code via file links and there are type incompatibilities (Visibility is different between Windows Phone and Win

Step-by-step instructions of how to save form information when your user hits the browser's back button

Scenario You have a form that you use to collect information from the user. The normal use case, is for the user to fill in the form and click next for some processing. The next button posts to the Post method in your Controller. Requirement If the user starts to fill out your form but then changes its mind and hits the browser back button to change some setting on the previous screen, save the collected data. Solution - Download history.js ( jQuery-compatible direct-link (save as)) - Put it in your Scripts folder and reference it from your _Layout. - On the page that requires the save functionality, in the document-ready block, add History.pushState({ state: 1 }, "Loaded", "?loaded"); History.Adapter.bind(window, "statechange", function () {   $("form").append(' ').submit(); }); - In your controller action, add the  backCase  optional property. - If the backCase is set, save your view model and redirect your ta

Building the best high tech company to work for by Kent Alstad @kentalstad #devsum13

Speaker deck:  http://devsum.se/wp-content/uploads/2013/06/Kent-Alstad-The-Best-Company-to-Work-For.pdf Happy people tend to be more productive people. In the 100 best companies to work for, we find highly profitable companies, such as Google. Why is it, that happy companies produce better results? Happy people get more engaged . Employees who feel engaged, tend to do better jobs and are more willing to put in the extra hours. Another thing about engagement, is retention. People are less likely to leave a company that they are engaged in. For consultant companies, this is important, since you don't want your consultant to leave you for your customer. In a product company, engagement can be the difference between a successful product, or no product at all. The thing is, that engagement also renders more profitability. The companies at the top of the best workplaces to work for, actually make more money than the average company. It's okay to be happy at wor

Guerrilla Framework Design by @TheCodeJunkie #devsum13

If your framework doesn't have a user friendly API and offers functionality that others do too, users will naturally prefer the other framework. Thus, the API is important from a developer usage point of view. By using dynamics and implicit casts, Nancy is very approachable. public class Module : NancyModule {     public Module()     {         Get["/greet/{name}"] = x => {             return string.Concat("Hello ", x.name );         };     } } Nancy uses a AppDomain scanner to find types of pluggable interfaces in the app domain, which means that all the user needs to do, is to implement an interface to add a feature. No registration required. This also enabled the Nancy team to break out non essential functionalities into separate nugget packages, distributing a very slim core package by default. Using a Bootstrapper, users of Nancy are able to replace core functionalities in the framework by simply inheriting from the Defaul

Beautiful Builds and Build Patterns by Roy Osherove @RoyOsherove #devsum13

Automate All The Things Beautiful Builds My book -  Beautiful Builds  - contains common patterns that we use in automated builds. What if I told you, that you could only compile code every three weeks? It'd feel weird, right? Three weeks of compilation issues to be solved in one day. Quite dramatic day, full of havoc. Obviously, this is not a good idea. Luckilly, this is not the case - we have tools that basically recompiles our code all the time. We find issues as we write, we fix them and everything is fine. What if i told you, that you could only test every three weeks? You write code for three weeks, and then you test and find that stuff you wrote a week ago doesn't work. TDD and testing approaches in general work well for these scenarios. We have realised for some time now, that we need to test more often. So it works on your machine. Great! What about your customers' machines? What about on the server where it is supposed to run? This is what contin

Notes on RealTime RTC by @ulfbjo #devsum13

Ulf starts off by showing all the platforms the  XSockets framework  executes - .NET, Mono, hosted in Azure. He then recommends us all to  check out Chocolatey  (in general), and as way to  install an XSockets server . Ajax is great, but continually polling a data source is a real waste of resources, says Ulf. For sparse updates, however, Ajax is still great.  For realtime data scenarios, Ulf promotes the use of Web Sockets. However, many implementations of Web Sockets are chatty in the fact that they send notifications to clients whether or not the clients want the messages or not, forcing the clients to filter out messages themselves and using more bandwidth than necessary. Ulf then starts a new plain MVC4 Web Solution, runs Install-Package XSockets and writes some simple JavaScript that binds to the XSockets GenericController, which manages the subscriptions. To create a new controller, Ulf invokes the package manager console again -  Scaffold XSocketController Zoo -pro

My notes on Real World Windows 8 by @john_k_waters #devsum13

By binding your view's DataContext to the Application's View Model, you can bind subsequent elements to more specific view models (members of the AVM). Background tasks Windows 8 RT only executes your app when it's in the foreground. However, you are able to do background processing through  Background Tasks . To create one, you create a new Windows Runtime Component project. Pick your name carefully, as it'll turn into the namespace you latter will need to reference in your app. In your UI app, you add a reference to your Runtime Component, in which you simply implement IBackgroundTask. Your background task can get invoked on a Timer, be configured to Play Audio and much more. Finally, your background task needs to be registered through your UI app. You can set timer intervals and system dependencies - such as only execute the task if we have internet connection. Digging deeper, we see that it supports the following triggers with the addition of condit

Notes on Natural Interfaces with @sarahkjork #devsum13

Sarah starts off her presentation, asking if anyone in the audience had seen  Minority Report . Just as Tom Cruise controlled his system, not using mouse and keyboard, but by "owning it" by motioning and gesturing, it's now possible to design systems, that utilises available sensor technology to do that very same thing. She then proceeds to show off the Kinect camera, pointing out its hardware capabilities and showing off the  Kinect toolkit that  is supplied by the Kinect SDK . The Kinect SDK supports up to 4 connected Kinects. On the  SkeletonFrameReady -event (called 30 times per seconds), we get skeleton data. Using the Kinect Sensor's  CoordinateMapper.MapSkeletonPointToDepthPoint , we can get a canvas position from the normalised values that is returned from the sensor. Sarah continues on to show a  Speech control system , featuring controlling a turtle with basic voice commands (walk forward, backward, left, right). For speech recogniti

TypeScript - bringing order to JavaScript with @herkommer #devsum13

Speaker deck:  http://www.slideshare.net/herkommer/ts-devsum2013 Michael has a background as a back-end developer. He's previously been against the idea of JavaScript because of its appeared lack of structure. What caught his interest with TypeScript, was that it introduces structure and order to JavaScript, making it look appealing to a C# developer. More and more well structured frameworks such as jQuery and Knockout also lowered the barrier to entry to the JavaScript world. The fact that all of these frameworks also is maintained as open source projects, makes it easier to absorb and to contribute to. Node.js contributed to my interest in JavaScript. It's a very impressive project where you run JavaScript on the server side in a well structured and highly scalable manner. Michael is heavily pushing Knockout, a prominent MVVM library for JavaScript. CommonJS, RequireJS and AMD are three modules we use heavily in TypeScript to manage type dependencies. All brows

Notes from #DevSum13's #PreConf, featuring @shanselman & @TessFerrandez

As the session starts, Scott shows off his 1337 skills by showing us hackertyper.com . There is one  ASP.NET. Therefore, fights over whether to use WebForms or MVC is contra-productive - use what makes sense for your project! The web team is working on simplifying the File/New Project screen, by reducing the number of choices you have to make up-front. If you want to build a web project, you should be able to just pick that option, and then add features as you go - a Web Forms section for for your admin UI, a MVC section for your client-facing views and a WebAPI section for your API, for example. Putting new project templates into Visual Studio should be as easy as creating NuGet packages . Furthermore, the team is juggling the idea of putting in favourites, so that your company can create custom templates (just like you can set up custom word templates), making in-house development even more straight-forward and streamlined. The 2012. N releases are quarterly releases o