• Simulating the Mouse Click Event in JavaScript

    I was trying to write a capybara feature spec for a date input using flatpickr. I wanted to assert that once I selected a date in the picker, it would be successfully entered into the input field in the required format. To do this I wanted to simulate a mouse click event in JavaScript. However, I hit a snag when attempting to fire the click event on a date in the flatpickr calendar instance, which had the CSS class flatpickr-day. When selecting the element and triggering the .click() event, nothing was happening; the date was not selected, the flatpickr instance did not close, and the input remained empty.


  • Git Shortcuts with FZF

    Today I started using FZF, which I’d heard of before but haven’t found useful until now. It is a fuzzy file finder written in Go, which can be used to rapidly locate a file with the arbitrary string provided, starting with the current directory or a provided directory or STDIN.

    Where I have found it most useful so far is alongside git. The first command I’ve set up an alias for is git add. I wanted to be able to add an individual file using git, though I didn’t want to have to type out the full path of the file every time. This command gets all of the added, deleted, and modified files in the current repo and feeds them to fzf, where you can then search for and select the file you want. The selected file is then given to the git add command.


  • Custom Time Formats in Rails

    If you need to set up custom date formats in Rails, for example to show in Views, you can do so by creating a config/initializers/time_formats.rb file and adding as many of the following as you want:

    Time::DATE_FORMATS[:au_datetime] = '%e/%m/%Y %I:%M%P'
    Time::DATE_FORMATS[:au_date] = '%e/%m/%Y'

    You can even use lambdas when defining a format, which will be executed using .call when you call to_s on your Time:

    Time::DATE_FORMATS[:short_ordinal]  = ->(time) { time.strftime("%B #{time.day.ordinalize}") }

    This is covered in more detail in the Rails Time documentation here:


  • Back to Ruby

    After almost two-and-a-half years of the high-paced, glamourous lifestyle of a UI developer (what we definitely need is more frameworks), I’m putting the JavaScript (partially) on the shelf along with the C# and .NET to work once again with Ruby and, for the first time professionally, Rails. I’ve decided to work with an old colleague and friend in a software consulting company, Webbernet, which entails an exciting move from Brisbane to Melbourne. The first half of this year has been and will continue to be an exciting and frantic time, and I am rediscovering what I liked the most about Ruby after my first week on the job, namely its pleasing syntax, great testing story and culture, and frameworks like Ruby on Rails that make it easy to get a functioning application up and running quickly. As a refresher I watched the following videos on Ruby and Rails that I really recommend to anyone wanting to try either or both out:

    From now on expect to see more posts about Ruby and Rails alongside the general programming articles I usually post. I’m even heading to the birthplace of Ruby (Japan) next month, and along with my other huge life changes it’s good to be good to get the fire burning again!

  • Organising C# using Statements in Visual Studio

    If you’ve been working on a C# file for a little while, refactoring as you go, you may notice that some of the using statements are grayed out, which means you are no longer using their assembly code in the current file. Also, they may be out of order alphabetically. Fortunately there is a way to fix both of these issues in Visual Studio. You can do it manually by going to Edit > Intellisense > Organise Usings > Remove and Sort Usings or you can bind this action to a keypress, say Ctrl+U.

    Remove and sort usings

    To do this, go to Tools > Options > Keyboard, and inside the Press shortcut keys textbox press the key combination that you want to use. Then type usings in the Show commands containing: textbox. Then choose EditorContextMenus.CodeWindow.OrganizeUsings.RemoveAndSort, and press Assign. All done! I found out how to do this from this StackOverflow post:

    Shortcut to organize C# usings in Visual Studio at StackOverflow

  • Sharing dynamic Objects Between Assemblies in C#

    I had a method in one assembly within my project namespace that accepted a dynamic as a parameter in the method. Something like this:

    using System;
    namespace MyAssembly.Data {
        public class MyDataClass {
          public IResult Parse(dynamic input) {
              // do stuff…
              var data = (int)input.data;
              return new ClassThatImplementsIResult(data);

    I then attempted to test this method, by passing in a dynamic created by the test:

    using System;
    using MyAssembly.Data;
    namespace MyAssembly.Tests {
        public class MyDataClassTest {
            public void Parse_Should_Parse() {
                var instance = new MyDataClass();
                var result = instance.Parse(new { data: 1 });
                Assert.Equals(result.ID, 1);

    But when I ran the test I got this exception:

    ‘object’ does not contain a definition for ‘data’

    This is because of the way dynamics are generated under the hood. They cannot be shared between assemblies because they obey the normal rules of access control, and the types generated by the compiler for the dynamics are marked as internal. To get this to work, I had to add the following line to the AssemblyInfo.cs file of my Test assembly (basically think of what other assemblies you want the current assembly to share internals with):

    [assembly: InternalsVisibleTo("MyAssembly.Data")]

    And after that everything worked peachy! For other gotchas related to dynamic objects in C#, check out Gotchas in dynamic typing from C# In Depth.

  • Why You Should Not Use Medium for Your Personal Blog

    Clickbait articles, hyperbolic statements, fresh graduates from 4 month code camps that declare that all current programming languages are dead, painfully un-subtle product plugs. Medium articles are everywhere now, and not a day goes by where at least two or three of the damned things show up on the front page of Hacker News or any other site with collections of programming articles. They have become formulaic to the point of parody, and I think you are doing yourself a disservice as a tech/programming blogger by hitching your wagon to the sleek green and white machine. They are often a platform for people who have a lot to say on twitter, but very little substance to write actually useful articles.

    I know, it is hypocritical to slam content-less clickbait articles with a clickbait-y article of my own, but there is a point. I’ll try to stop here with the actual bashing of Medium and go into some real pros and cons of running your own blog vs. hosting on Medium.


  • The Fundamentals of Flow in 10-ish Minutes

    I’m still kind of undecided on the best way to add type checking into JavaScript. On the one hand there is Typescript, which a lot of people seem to be going toward. It’s a superset of JavaScript, and it adds a LOT of new language features, as well as compile-time type checking. It’s backed by Microsoft, and has widespread support in other projects like AngularJS. It’s easy to add to an existing project, and having used it briefly myself the ecosystem behind it, including typing libraries for projects like Lodash and React, and the benefits it brings are outstanding, and I really feel like this will be the future of JavaScript.

    On the other hand there is Flow which was created by Facebook. It’s also a compile-time static type analysis tool, and like Typescript you can add it gradually to your project by adding // @flow to the top of .js files that you want to perform type checking on. Flow doesn’t aim to add a lot of new language features like Typescript does, but rather it attempts to ensure correctness in your JavaScript code using the type analysis. Here’s a good comparison article between the two if you want to do some further research http://michalzalecki.com/typescript-vs-flow/.

    I watched this video a little while back by Alex Booker (@bookercodes), a developer on Pusher, that serves as a great introduction to Flow. Check it out below, and there’s a similar type of video on the Typescript website.

  • My Writing Blog

    Just a little plug for my writing blog, where I am posting quotes, essays, short stories, and personal blog posts not related to tech. Check it out at https://writing.martin-brennan.com.

  • Terminal Shortcuts

    A friend sent me this list of useful terminal shortcuts:

    Ctrl-A: go to the beginning of line
    Ctrl-E: go to the end of line
    Alt-B: skip one word backward
    Alt-F: skip one word forward
    Ctrl-U: delete to the beginning of line
    Ctrl-K: delete to the end of line
    Alt-D: delete to the end of word

    If you are using windows, I can’t recommend cmder enough. It is miles ahead of other terminals, and you can use bash, and Powershell inside it too.

3 // 11



Want to read regular updates? Subscribe via RSS!