Books I’ve Read in 2017

This year, I’ve made it a personal goal to read only new (to me) books. I haven’t been good at finding new things to read and I’ve spent a lot of time (possibly a whole year) re-reading Discworld books, with occasional dips into my comic shelf.

So that was a simple challenge – only read books I’ve never read before. Not even a long time ago.

Successes

  • David Copperfield
    I read Nicholas Nickelby last year and enjoyed it, this was a little bleaker but still very interesting. You learn a lot about everyday Victorian life from Dickens.
  • The View From the Cheap Seats
    A little disappointing, it feels a lot like a reminder to read things and listen to people I wanted to anyway. The other things in there would probably be more interesting to me if I had already read them, kind of like a covers album is better if you already know and love the originals.
  • Singing From the Well
    Trippy as hell. Reminds me of the film Cat Soup, and to a lesser extent My Neighbour Totoro. An easy read, I got through it in a couple of weeks.
  • The Un-discovered Islands
    An interesting book about places that we thought exist, but don’t. I think I might look for the Phantom Atlas for more, it’s an interesting alternative to real history/geography.
  • Star Trek: Destiny
    Recommended to me as the best continuation of Star Trek after Voyager, after I looked out on my own and found The Lives of Dax. I would have preferred a less epic, more DS9 focussed story but this was still good.
  • The Prince
    Very difficult to read, as it contained so many run-on sentences and I like to read just before sleeping. Not my most alert. Slightly interesting, but not nearly as diabolical as Macchiavelli’s reputation has come to be.
  • The Better Angels of our Nature
    Since I heard Penn Jillette talk about this book all the time on his podcast (Penn’s Sunday School), I picked it up. I even got it signed by Penn and Teller when we went to their London show! They said it was a great book, and it’ll change my life.

Failures

  • World’s End
    I was having a slow, tired week and wanted to read something but wanted something easy. I love World’s End as a story about stories (and one of those stories is about stories…) in a strange place – like a lot of good sci-fi, it’s not about what’s going on, it’s about the stories that happen before and after the episode. It fires the imagination.
  • Drive, Act One
    I think this counts mostly as a failure, because I’ve already read the story as a webcomic.

Films I’ve Watched in 2017

Some years, I don’t get to the cinema. A couple of times now I’ve actually trekked out on my own in order to catch a film that I want to watch. In one of the Planet of the Apes reboot series, I was the only person in the whole screen. You can pretend you’re a billionaire! Anyway, here’s what I managed to see.

Lego Batman Movie

It wouldn’t have worked as a Batman film without Lego, but didn’t really need the Lego too much (one key point notwithstanding). I wouldn’t have been tempted to watch this without the kids, but really enjoyed it with them.

Ghost in the Shell

I’ve heard mixed opinions, but I really liked this. It told a different story, in a different way, but is still a valid story for the world. It’s more of a personal story of the overall “who am I” question of the original film. I liked that it didn’t dumb things down, and the camouflage cloaks were not even mentioned – just taken for granted that that’s what people have.

Guardians of the Galaxy Vol. 2

Not as fun as the first film, but still a pretty good show.

Spider-Man: Homecoming

Better than I thought it would be. Some excellent moments of tension, like the car journey, as the characters start to realise what the audience knows. I really liked how it fit into the rest of the Marvel Cinematic Universe, and used Peter Parker as a real teenager. The only complaint I could make about it is the spider suit suffers from the Tony Stark patented ‘magic technology’, while still looking like lycra.

Baby Driver

WOW. This film is absolutely incredible. The music, the acting, the direction… Edgar Wright is a genius, no question. Some of the Easter eggs in it I’m pleased I caught (I got the Halloween stuff near the end), I’m sure there were more that I missed though. Wright is a real cinephile, and would have seen opportunities to put little bonuses in everywhere. It’s a rare film that I want to go out and see again straight away, this is one of them. One thing I noticed that I wasn’t sure about, I’d like someone to confirm… It seemed to me that Buddy’s gunshots were timed so much closer to the music beats than the other characters, and Bats was way off with timing. Since a lot of that could be faked or fixed in editing anyway, it felt like a deliberate choice and it would make sense since Buddy understood Baby more than Bats did. Definitely worth another watch, just to look out for that sort of thing.

Valerian and the City of a Thousand Planets

Very, very disappointing. The effects were good, the world and setting were incredible but the film was a total let-down. The acting was… inconsistent. Some scenes were well done, others not – and I don’t think it was restricted to the CG-heavy scenes, where actors would be expected to have a hard time. The story was passable but the dialogue was atrocious.
Laureline as a character just didn’t make sense. She starts the film professional and focussed, ends it as a loose cannon who ignores the rules, and no-one seems to notice the change. Maybe she was always as much of a maverick as Valerian, but the first half don’t set that up at all. On top of which (spoiler alert), in a station of millions of people and human agents like Laureline and Valerian, Laureline assaults two officers and escapes arrest and yet no-one is sent out looking for her. “Oh dear, she got away. Guess we’ll see her when she comes into work tomorrow.” The worst part of the film was how much potential it had, and wasted. Big Market, the history and structure of Alpha… there was so much there that was explained for a minute and then used for a split-second in an action scene. There felt like so much more that could be done, that there was a good film in there somewhere, but the direction they took just didn’t work.

War for the Planet of the Apes

Fantastic. Amazing. Visually stunning, great story, some great nods to the original series and a far better film than Conquest of the Planet of the Apes. This new trilogy feels like a reboot of the last two films of the original series rather than the first two. Dawn felt like the original Battle for the Planet of the Apes as the Apes are uplifted and escape human society, Rise happens off-screen and War matches up with Conquest of the Planet of the Apes as humankind is shown to be a waning species.
I really enjoyed what the whole series has had to say about leadership, ambition, and xenophobia. In both Rise and War, Caesar doesn’t want to fight. He even manages to avoid going to war and still defends his people for the most part, in both films. Rise was particularly good in that leaders on both sides don’t want war, but are forced into it by radicals in their own camps setting events in motion that can’t be stopped. It actually makes me want to go back and watch Conquest again, as bad as that was, and look out for other little nuggets that were left behind.

Thor Ragnarok

This was so much fun. It was silly, and funny, and colourful, and just fun. One of the best Marvel films, and definitely the best Thor film. The others were fairly dull and serious – this one really played it up a bit, and being away from Earth meant it could be as big and outrageous with the ‘God’ thing as it wanted.

Bright

I’d heard terrible things about this from critics, and great things from friends. I’d say there’s a bit of truth in both. It’s certainly not going to win awards, but it’s a really good film regardless. The dialogue is very natural – people talk over each other and get interrupted properly. I like how the Orc is not dumb, but without spending a lot of time with him people wouldn’t know that. He’s not stupid, but inexperienced. His intelligence is not appreciated – like the two years of Elvish he took in high school that he can remember enough to hold conversations, or the attention to self-care that he has, or the insights that his senses give him. The human character too is a great portrayal of “I’m not a racist but” – he’ll work with the Orc (but try not to), he’ll be talked into killing the Orc (he wouldn’t get as close to that with a human), he hates Elves when they’re not around… and the wonderful display that spending time with people softens ill-feelings towards those people.

Drag and Drop in Unity Part Two

After getting a basic system of moving Items between different Containers, I needed to extend this slightly. First of all, I need some feedback of which container an item is going to, and also of restricting items to only some containers. In most games, only some containers are valid locations to drop an item.

Feedback

What I want is for the containers to highlight when an item is hovering over them and they can be dropped. To detect when an item is hovering, I gave all the Containers a BoxCollider2D component and all of the Items both a RigidBody2D component and a BoxCollider2D. Now apparently, the collider should size its mesh to the shape of the GameObject but since I am only using Panels, not sprites, this doesn’t seem to be the case. It’s not a problem, since the collider mesh can be edited manually.

The RigidBody2D components need to be set to Kinematic for the Body Type, so that the Unity engine doesn’t try to push them with gravity all over the place.

The BoxCollider2D elements on the Containers need to have Is Trigger set to true, so that the trigger methods fire.

Then on the DropHandler script I added the following methods (which are overrides of methods on the MonoBehavior base object so they don’t need any more interfaces):

private Color? _startingColour;
 
private void OnTriggerEnter2D(Collider2D collision)
{     var image = GetComponent<Image>();     _startingColour = _startingColour ?? image.color;     if (collision.transform.parent.gameObject != gameObject)     {         image.color = Color.red;     }
}
 
private void OnTriggerExit2D(Collider2D collision)
{     if (collision.transform.parent.gameObject != gameObject)         GetComponent<Image>().color = _startingColour.Value;
}

This will make the Container red when something is hovering, and white otherwise, but only if the container is not it’s original parent container. The _startingColour field is to be able to return to whatever it was before. The last part of the puzzle is to add the following to the OnDrop method in the DropHandler script:

GetComponent<Image>().color =

_startingColour ?? GetComponent<Image>().color;

So that after an item has been dropped, the container will return to it’s original colour.

Restrictions

Restrictions were surprisingly easy. First of all, everything got renamed either ContainerAA, ContainerBB, ItemAA and ItemBB so I could check conditionals without having to go through added a custom editor pane. Then, I added the CanDrop method to the DropHandler script:

public bool CanDrop()
{     return (DragHandler.ItemBeingDragged.name.Contains("AA") && gameObject.name.Contains("AA"))         || (DragHandler.ItemBeingDragged.name.Contains("BB") && gameObject.name.Contains("BB"));
}

And called it as part of the conditional checks on OnDrop, OnTriggerEnter2D and OnTriggerExit2D.

Et voila! Only some targets highlighted on hover, and those were the only ones that would accept the drop. Different items had different targets.

In further developing this, I can see that CanDrop will really be looking for a specific MonoBehavior type (for example, by calling ItemBeingDragged.GetComponent<Card>()) and then interrogating the properties against specific logic – different for each container. So in Solitaire, the CanDrop method would get the Card component out of the item being dragged and then check it’s suit and value against the current suit and value on it’s own stack to determine if the card can be dropped or not.

Drag and Drop in Unity Part One

I’m starting to experiment with Unity for a hobby project involving a card game.

In almost any card game, there are certain areas of the table for a collection of cards. Whether this is the vertical stack in Solitaire, the lands in Magic: The Gathering or a hidden hand of cards that aren’t ‘on’ the table, there are different areas that contain groups of cards. These cards will usually need to move between the card containers, so I figured the first thing to do would be to implement dragging and dropping. After watching a few video tutorials (the most useful was this one), I was ready to try some things out.

I started with a 2D game in Unity – card games are famously 2-dimensional. To this, I added a Panel and named it “Container”. Then I added a Panel inside the Container and named it “Item”. I made the Containers a little bigger than the Items so it was easier to see them, and duplicated this until there were 4.

I added a Grid Layout component to all of the “Container” objects and set the Child Alignment to ‘Middle Center’, then added a Constraint of ‘Fixed Row Count’ and the Constraint Count to 1 so that each container would only ever have one row of items.

Each “Item” needed a script – named DragHandler – to handle the dragging behaviour. The script describes how the object should behave when being dragged around, including how to begin dragging it in the first place. To do this it needs to reference the UnityEngine.EventSystems namespace, and implement the three interfaces IBeginDragHandler, IDragHandler and IEndDragHandler.

First of all, it needs some properties and fields set up.

public static GameObject ItemBeingDragged;
private Vector2 _startPosition;
private Transform _startParent;

This is almost verbatim from the tutorial video, and I will probably be refactoring that static GameObject field at some point in the future (it ought to be a property if it’s public).

public void OnBeginDrag(PointerEventData eventData)
{     ItemBeingDragged = gameObject;     _startPosition = transform.position;     _startParent = transform.parent;     GetComponent<CanvasGroup>().blocksRaycasts = false;
}

OnBeginDrag starts the process off by setting the ItemBeingDragged to the current GameObject, saving the start position (so it can be returned later if the drop is unsuccessful) and saving the original parent (same reason). Finally it finds the CanvasGroup component and stops blocking raycasts so that events can be fired through the item being dragged (this will be needed to drop it).

public void OnDrag(PointerEventData eventData)
{     transform.position = Input.mousePosition;
}

OnDrag just makes the dragged item follow the mouse cursor until it is dropped.

public void OnEndDrag(PointerEventData eventData)
{     ItemBeingDragged = null;     if (_startParent == transform.parent)     {         transform.position = _startPosition;     }     GetComponent<CanvasGroup>().blocksRaycasts = true; 
}

Finally, when the drag is over, the ItemBeingDragged is forgotten (set to null), and if the parent item at the end is the same as the beginning it is returned to it’s starting position. Finally, raycast blocking is restored so it can pick up further events.

The Container objects need a script too, which will also need to reference UnityEngine.EventSystems and implement an interface. This time, IDropHandler so we can drop items there.

public void OnDrop(PointerEventData eventData)
{     DragHandler.ItemBeingDragged.transform.SetParent(transform);
}

This is a simple script. It references the static ItemBeingDragged property from the DragHandler script, and sets its parent to whatever the drop target is.

With all this set up, I can drag Item panels from one Container to another. Or move a card from one location to another, eventually.

Drive Comic, Act One Book Review

This comic gets a lot better when it’s read all in one go. I started reading it as a fan of Sheldon (I’ve since dropped Sheldon from the comics that I read, it just got a bit… meh… for me), so I was reading each strip as it came online. If I remember rightly, Dave Kellett was working on Stripped! at the time and couldn’t keep to a consistent update schedule. Although, looking back it seems to have been fairly constant at weekly-ish for the first year, unless the dates in the URL are unreliable.

Regardless, reading a page a week is not the best way to read Drive. Especially at the Six Moons of Slaughter, an action sequence that happens in about 2 minutes and 20 pages (I’m not going to go and check these facts). The story in the Act One book started in 2009 and finished… I can’t find when it finished (the website has no archive page and individual strips are loaded by date), but it was sometime after 2011. 2 years for a very sequential story is a really, really long time.

The best way to read Drive is with one of the beautiful, Kickstarter, hardcover Act One books, like I did! There was so much that I’d forgotten about the story, and now I’m aching for Act Two so that I can see how some characters get out of the predicaments at the end of Act One… And I’ve just been going back through the recent pages to see if they even did make it out of Act One! Seriously, long-form storytelling in a weekly webcomic is not easy to follow. I’d forgotten what the Vinn were exactly, since they don’t show up often in the strip and they’re named often but described little (any description would be too much when you have all the pages in front of you, but 6 years after the description of the eyepatch tattoo of a race that’s not been seen for 5 years? I only have so much capacity for minutia!)

Anyway, I highly recommend this comic. You can read it online if you’re into binging archives, but following it on RSS (as I do) will ache to get each new page. It’s a million times better to wait and read it all in one go, it was absolutely designed to be read that way rather than a page a week.

Fantasy Battles – Age of Sigmar

I promised a long, long time ago to try out Age of Sigmar. Jen really wasn’t interested, but my old Warhammer buddy has gotten into it and offered to show me through it.

We played Wood Elves vs Warriors of Chaos (with a few Skaven thrown in) but I suppose in the new jargon that would be ‘Aelf Wanderers and Sylvaneth’ against… something else? We used Warscroll Builder to come up with 2000pt armies, and since I haven’t read more than the four-page rulebook (and dozens of pages of warscrolls for my two elf armies…) I don’t know if it accurately reflects all of the points options available. Compared to old Warhammer, there are far fewer options. I suppose it’s on the same sort of level as Kings of War – pick a unit, choose small/medium/large and off you go. But I’d have to see the Age of Sigmar supplement that describes pointed battles to understand it properly.

Headline response? I think I’ll try it again, but it’s definitely not hooked me yet. It wasn’t that hard to pick up, although I didn’t really get to learn how to use each unit well. The game played out strangely – because I had managed to get near an objective and that unit didn’t die fast enough, I scored a couple of points and technically won. However, I lost almost my entire army and what was left was too far away to do anything if we’d played longer. Compared to our Kings of War game this one took 3 hours to finish 3 turns, and that took under 2 hours to finish 6 or more – with roughly comparable armies.

Comparing to both Kings of War and old Warhammer, this game is more fiddly. Every model moves separately. I wouldn’t be surprised if this is why it took so much time to play, since the other two games both involve pushing around whole trays of models that fight as a tight formation.

It also feels less tactical, although I suppose the tactics have just changed. I used a battalion rule that let me ambush and come on at any table edge to sneak in behind the enemy lines and start shooting. However, in Age of Sigmar turning around is impossibly easy, the combination of moving and charging means everything is a little bit closer and for bonus points, there is no benefit to flanking your opponents units. It looks like the game needs you to be smarter about which match-ups you get into or what support your units have (since combat no longer prevents you from shooting into or out of combat), and not necessarily smarter about how you move around the battlefield. The absence of any tactical movement rules like fleeing from a charge go along with this.

I’m not sure I like the new tactical direction. I liked the feel of drawing a unit somewhere it didn’t want to be and then hitting it in the side for maximum impact. Since I’ve almost always used Elves you need to be able to maximise their effectiveness with ganging up or gaining some sort of advantage, but there’s no major benefit to either of those in Age of Sigmar. It won’t matter where my Elf unit engages the Chaos Knights, they are screwed unless there are absolutely loads of them – and even then Battleshock will take care of the rest even if they win.

I do like Battleshock as a rule. I didn’t dislike fleeing and pursuing, but Battleshock is one area of the game that just goes faster and still does it’s job. It also keeps units in the fight so you’re not looking at all your fleeing units and wondering if you’ll be able to rally them in time to do something useful with them. The downside is when you realise that your units shouldn’t be in that fight in the first place, and you’d really rather they fled somewhere safer (although having ambushed right along the back line, my units had nowhere to run anyway…)

Another thing I liked was the individual melee weapon ranges. It’s a bit fiddly, the sort of thing that would go down well in Mordheim or Necromunda better, but the idea of a Treeman being able to reach over two models to hit a guy further back whereas swords are pretty much ‘base contact’ is really neat. I noticed that the spear wielders could still attack in two ‘ranks’ if they were bunched up together.

Overall, there are things I think I need to try again to see if I can get the hang of it. I almost feel like 2000pts is too big for a game where you’re moving individual models, measuring 1” ranges to see if they hit in combat (2” for spears) but I’ll try it with the Dark Elves (‘Aelf Exiles’) and see if they get on any better.

Kickstarter Roundup, part two

I’m not a mega-prolific backer by any means, but I do keep my eyes out for interesting projects. Here’s what I’ve been up to since my last Kickstarter Roundup

Deadzone: Infestation

I backed this at $1 to see where it was going… but I wasn’t hooked enough by the end to back more. I really wanted the Blaine on jetbike exclusive backer model, but it wouldn’t have been worth the price.

Whizz Pop Bang

This one’s a science magazine for children, and even after the Kickstarter subscription ran out we’ve kept it going. The children enjoy it, and occasionally Fred will mention some fact that he’s picked up from months before so we know they’re enjoying it! Their school has even picked it up to stock in the library, so that’s good.

We just need to get more organised about doing some of the experiments. A shopping list is sent out by email before each issue arrives so we should be able to pick any bits up that we need in time to do it.

Penny Arcade’s Automata

This one looked like fun to back. We’ve been getting into some of the Netflix Original series recently, and really enjoying them, so I’m more open to supporting independent shows. They’ve started teasing some more stuff in updates so hopefully it won’t be too much longer until it’s out.

Mystery Science Theater 3000

I loved this show as a kid, and went in heavy enough to get a t-shirt and mug, and I am absolutely thrilled that it’s going to be out in less that a month. It was so exciting watching it grow into one of the biggest Kickstarter projects ever!

Lumbermancer

The pitch video made me laugh, the game was already finished and it was only $4. So I didn’t think it was a bad bet to try it out. It’s a fun enough game but I’ve not found the time to go back to it since the first couple of days.

DreadBall 2

How could I not back this? An update just arrived to say it’s been delayed (yes, yes…) but should still be here by Christmas. I’m going to try and paint the New Eden Revenants like the Borg, trying some new glaze techniques to make their skin seem appropriately clammy… I’ll let you know how I get on.

Drive Hardcover

I’ve been enjoying the webcomic for a while now, and it’s worth supporting creators who make good things. I get the feeling that reading it in a short space of time (rather than single pages over a course of years) would make it even better (like many long-form comics), and binge-reading comics is more pleasant in paper form.

Goblin Hood

Fantasy goblin Robin Hood models? Awesome! I know the guy behind Macrocosm Games and he’s done several mini-Kickstarters already so I was pretty certain it would deliver fine, and it didn’t take long before the models turned up (in a teeny-tiny box). There were even a couple of sweets in there! The goblins were a little bit smaller than I expected but they weren’t for any particular game or project so they’ll be fun to paint up just on their own.

Brexit – Why I’m Marching

Warning: unedited stream of consciousness.

Next Saturday, I’ll be attending a protest march in London. I know the government won’t listen, I know that nothing will change. Sometimes protests make change happen – not very often though.

So why march?

Well, there’s not much I can do to stop Brexit. My local MP defied Labour’s three-line whip to vote against the bill (which I appreciate, greatly) and any reasoned arguments against Brexit are met with “but we’re going to get the best deal.” A march will show that this is an unconvincing argument.

The 48% who voted to Remain in the EU are not just being ignored, but completely silenced. They’re already being made scapegoats by some Brexit supporters – the pound is weak because we’re ‘talking down Britain’. If Brexit isn’t a success, they say, it won’t be because it was a terrible idea, or even a good idea poorly implemented, the blame is already being laid at the feet of ‘Remoaners’ for not uniting or trying to make the best of it.

That argument has a small ring of truth. I know small business owners, technical professionals, skilled and educated people who are looking at emigrating because of the government’s course before Brexit hits properly. If what I can see in my own bubble is representative, then these ‘Remoaners’ will inflict some small economic harm on the UK by leaving. Then again, it could be argued that they are taking back individual control and leaving an undemocratic union rather than trying to make the best of it. Which 52% of the country also decided was the right course to take.

The government’s attitude towards Scotland is absolutely astonishing too. I wouldn’t believe it if I read it in a book – it has an air of Douglas Adams to it. Telling people that leaving our biggest trade partner to go it alone is guaranteed to be a success, but telling Scotland they can’t afford to go it alone? Trying to explain that it would be irresponsible to have a referendum when the final relationship isn’t clear? The thing that swung the first Scottish referendum was membership of the EU. Now they’re guaranteed to lose membership of the EU, but when independent they have a chance to re-join it. And as a small economy in the union, they will see investment to accelerate their own independent growth and success, like we’ve seen with other new members. I don’t think Scottish Independence will be good for the UK. But I think Scottish Independence with EU membership will be better for Scotland than UK membership without the EU, and even that will be better than Scottish Independence without the EU. So it’s a gamble, but seems quite a safe gamble. I can’t see any reason they wouldn’t get into the EU fairly quickly after independence, other than the border issue. But Northern Ireland will already have set an example there.

I think we will either have Freedom of Movement with the EU (and riots from the 52%), or there will be some sort of a border in Ireland. I can’t see it going any other way. You can’t put up a border between Northern Ireland and the UK (it’ll be like having your passport checked to go to Wales). When I was young, ‘terrorist’ meant ‘IRA’ in any news story I heard. Since then, things have settled down a lot. Borders could start to unwind that process.

I don’t see the benefit in Brexit. We will be throwing away our trade deals (made by a strong economy with 20+ other large states to form a powerful negotiating bloc) to make new ones, as a single state with a weak currency.

The Leave campaign, and the Conservative manifesto, promised that we would stay in the Single Market. Leaving that would be completely nuts. We are going to lose many large businesses as they flee to Ireland, France or Germany. The government’s current course is like (and I steal this from someone else, I can’t remember who though) Remain won 52% and told the country that it was therefore the will of the people and a clear mandate to drop the pound and join the Euro. And then trying to tell 48% of the population to ‘just get over it’. And the leader of the opposition bullying their party to support this plan, then trying to pretend that they really oppose it.

The whole Brexit situation is aggravating, and I’m not even going to go into the whole Parliament-vote final deal stuff. The government is crazy. The country is doomed. And it won’t be my fault, I didn’t vote for it and I’m not trying to sabotage it. If there’s even anything I can do to make it work, I’ll do it because I don’t want everything to collapse more than it already has. But if me saying “I don’t think that’s a good idea…” on my private Facebook or a blog no-one reads is enough to derail the Brexit plans, then maybe Brexit isn’t the guaranteed success it’s being promised as.

So I’m going to go to this march and be counted and show that it’s not just a small minority who lost the vote. The half of the population who lost still feel very strongly, and deserve to have their concerns answered properly. Being told “we’re going to get the best deal” isn’t very convincing. Other countries have no obligation to give us a good deal. We need answers, we need a plan, and we need to be treated fairly – when Brexit fails, it won’t be the fault of the people who voted against it.

SQLite in ASP.NET Core WITHOUT Entity Framework

Try and search for ASP.NET Core and SQLite and you’ll get a dozen guides to using it with Entity Framework.

First of all, we’ll need an ASP.NET Core website and install the Nuget packages Microsoft.Data.Sqlite and System.Data.Sqlite.

I prefer to use Dapper for my database access (hence not wanting to use Entity Framework), so go ahead and install Dapper too.

Opening any connection in SQLite by default automatically creates the database file. Run this code:

var connectionStringBuilder = new SqliteConnectionStringBuilder();
connectionStringBuilder.DataSource = "MyNewDatabase.db";
using (var connection = new SqliteConnection(connectionStringBuilder.ConnectionString))
{     connection.Open();     var result = connection.Query<int>("SELECT @number;", new { number = 789 });
}

And you’ll see in the /bin/debug folder there is a new (empty) file called MyNewDatabase.db. Setting a breakpoint and inspecting the result variable will also reveal that the database is responding nicely to queries. It should have a list of a single item, and that item is the number 789.

Running basic queries for fun isn’t very exciting though. We need to be able to connect to the database, create tables and interrogate them. The way to do this with SQLite is through the command line. Since I’ve been playing with Linux, I loaded up Bash for Windows 10 and gave it a go.

To do it like that, run sudo apt-get install sqlite3 in your Bash shell to get the client application. Then navigate to the database file location (you can get to the main drives with cd /mnt/c, where c is your drive letter). Then hit sqlite3 MyNewDatabase.db, and you’re into command line SQL mode! All commands must be terminated with a semi-colon, but otherwise it’s easy to add tables, set them up, etc. I will be saving all the commands in a separate file so the scripts can be re-run if necessary, or if I choose to create a new database on the live environment and deploy to it separately.

A few hints from this site on using SQLite:

To list all tables, type .tables and to exit the command line type .quit.

New Year, New Host, New Blog

I mentioned at the start of the year, I’m hoping to get back into blogging a bit more this year. I had a pretty good run of posting once a fortnight, but it fell away as my commute got shorter and less convenient for typing.

I’ve moved my blog to Digital Ocean. The reason is partly cost-based, but also because I wanted to play around with SSL certificates for DreadBall Hub. My previous web host was eHosting, a UK based provider of Windows hosting. That was important as a .NET developer, until last year when .NET Core has brought my skills to Linux.

Anyway, I wanted an SSL certificate and could get a free one from Let’s Encrypt. I spoke to eHosting, and they said that I could absolutely install a third-party certificate like Let’s Encrypt, but I’d need a static IP address. That’d be £1 a month (+VAT). Well, that was still cheaper than the £50-100 for another provider’s certificate, so I thought it was worth the cost. Unfortunately, I couldn’t find the option to buy that add-on.

Their support staff were very helpful – the solution was to upgrade my subscription at an additional cost of £5 a month (+VAT), so that I could buy the £1.20 add-on for a static IP address. So that’s a total cost of £72 (+VAT) a year, to get a free SSL certificate.

Rather than spending an extra £80+ every year, I decided that with the Linux portability of .NET Core another option was open to me. Try out a Linux server (and Digital Ocean charge by the hour, so I’m not locked in too tightly) and see if I can do everything I want on there. Even with the collapse of the pound against the dollar, the hosting is cheaper than I was paying at eHosting with the downside of having to be the administrator.

The upside of course is that with free SSL certificates, this blog and DreadBall Hub are now encrypted. My mail is handled by another free domain-mail handler. I’m saving money, and I’m getting to learn new things about Linux and .NET Core – exciting new stuff! Onwards and upwards!