Skip to content

Thomas Shipley Posts

Ignoring Folders During Compilation in a ASP.NET Core RC2 Project

ASP.NET Core RC2 – DNX is dead. Introducing the DotNet CLI Until RC2 of ASP.NET Core, the responsibility for building a project was handled by DNX which has now been retired. This has been replaced by the .NET CLI. Part of the motivation for this is to have one tool fulfilling the roles of DNX, DNU and DNVM to try to make things less confusing for developers when they set up their environments. Ignoring a Folder in .NET CLI Compilation One of the quirks during the transition to the .NET CLI from DNX was my project failed to compile. This was due to a node package that didn’t support .NET…

Enabling Cascade Delete in EF Core Code First DB Using the Fluent API

Entity Framework Core Default Behaviour on Delete Cascade delete saves a developer time by not needing to write boilerplate code for related data when the parent data in the relationship has been deleted. However in Entity Framework Core it is not the default behaviour. It takes a more conservative view and sets the on delete behaviour to restrict (StackOverflow Question where EF Core Team Member Confirms) which the documentation defines as: Restrict: The delete operation is not applied to dependent entities. The dependent entities remain unchanged. – EF Core Documentation Compared with the definition of cascade: Cascade: Dependent entities are also deleted. – EF Core Documentation Enabling Cascade Delete Using The Fluent…

Setting Up SQLite and Entity Framework Core in ASP.Net Core

For small applications such as prototypes and small side projects, SQLite is a great choice for a relational database. It is really easy to setup because: Its self-contained Its just one database file in your project. No server Because its just one database file in your project which holds all your data there is no extra server setup. No configuration All you need is to create your schema and the database is ready to store data. Letting Entity Framework Core Manage Your Database Schema For all its ease to setup, you still need a schema to define your tables and the relationships between them. Unless…

Creating a Visual Studio Code Task for Building a .NET Core Project

Visual Studio Code is a great new multi-platform code editor from Microsoft currently in beta. It is a lot more lightweight than Visual Studio. But when writing code I in VS Code I missed the Ctrl-Shift-B shortcut. It makes sense that VS Code doesn’t have it – after all, it doesn’t know what is being written and the build targets, and you can always build without it in .NET Core using dnu build but it can be added back in. Visual Studio Code Tasks Turns out you can integrate your own tasks into VS Code – when combined with Gulp it becomes easy…

Making a GET Request in C# using HttpClient

With my new job at New Orbit I am moving towards full stack web development in ASP.NET and AngularJS. The first issue I encountered was how to make a GET request to an external API. WebClient vs HttpWebRequest vs HttpClient. Which one?! It doesn’t help that are multiple options. Such as the WebClient, HttpWebRequest and HttpClient classes which all can be used to make a GET request – so which one to choose? Diogo Nunes has a nice discussion of the differences. After speaking with one of the Principle developers here it seemed HttpClient was the best option. Compared to WebClient it is closer…

Calculating a Percentage in Ruby Elegantly

In a recent project it would have been handy to write some ruby code which looked like: View the code on Gist. When searching through the ruby libraries there wasn’t any indication it existed. Wanting to avoid a class method – a quick google turned up this StackOverflow post – Calculate percentage in ruby. It presents a nice solution to the problem (one I should have thought of!). Create a class called Numeric and add the method to it: View the code on Gist. Now a number object has a method called percent_of which takes itself and another number as an argument to…

Parsing YAML in GO

Go supports JSON via its standard libraries. However, it does not support YAML – which is interesting when you think about it. YAML is after all just JSON written in a specific way. It is useful to have a high-level understanding of how GO supports JSON before diving into YAML. The first thing you need to do is model your data as a struct: View the code on Gist. Notice how there is a string with some metadata for each field. This tells Go what each field is named in your JSON. After this, you can include the encoding/JSON library you get a…

Using Ruby to Recover JPEGs from a Forensic Image

This is the second post in a series investigating different programming languages applied to a forensics recovery problem. More detail about the problem can be found in Using Go to Recover JPEGs from a Forensic Image. The code is available on GitHub. Continuing from the last post the next language I looked at was Ruby. As a brief recap, the problem was to recover 16 JPEG files from a forensic image which had been zero wiped before they were taken. About Ruby Ruby is a language that was popularised by the web framework Ruby on Rails. It can be best surmised by the quote…

Using Go to Recover JPEGs from a Forensic Image

CS50 is an introductory course offered by Harvard to students at the college and online via EdX and the Harvard Extension School. It teaches mostly through a series of problems sets which mostly focus on using C to solve them. One of the more interesting problem sets is Problem Set 4: Forensics. The Problem The original problem was solved in C as part of the course and here will be solved using Go. But before looking at any code it is important to give a little context (all code is available on GitHub for those that are interested). Key characteristics of the problem have been outlined below: What we…

Finding Lost Commit History using the GitHub API

It is quite easy to lose commit history in Git. A mistaken forced push is enough to rewrite the past and lose valuable work. Assuming the user in question has not done a git fetch in a while reflog won’t help you either. This happened to me while dealing with a branch that had a misconfigured remote pointing to the mainline. In my stupor, I forced the push. Outdated reflog! Perhaps GitHub has the Answer? All is not lost however you can access all the information you need via the GitHub API. Assuming you have stopped the team making anymore commits to the…