-
Jim Weirich Ruby talks
I was linked to these two videos by Jim Weirich when I started working with Ruby and Rails again by my friend/colleague/boss (in 2017 at Webbernet) and they really helped get into the mindset of working with Ruby in a good, SOLID OOP way. They also gave me a path to not use Rails magic too often, and to decouple logic and classes from the framework as much as possible.
Advanced Ruby Class Design by Jim Weirich
Decoupling Ruby from Rails by Jim Weirich
-
Simulating the mouse click event in JavaScript
In 2025 there are probably better ways to do this now, especially if you are using https://playwright.dev/ . This article also references many deprecated browser APIs. Leaving this as a historical curiosity.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
read more...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
In 2025 fzf is a critical tool I use daily, I use it for much more than what this article shows, including heavy usage in nvim.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
read more...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 tofzf
, where you can then search for and select the file you want. The selected file is then given to thegit add
command. -
Custom time formats in Rails
In 2025 this still works in Rails, but it is likely better to rely on other methods like defining time formats in the Rails I18n system yaml files and usingI18n.l
rather thanTime.to_fs(:format)
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 callto_s
on yourTime
:Time::DATE_FORMATS[:short_ordinal] = ->(time) { time.strftime("%B #{time.day.ordinalize}") }
This is covered in more detail in the Rails
Time
documentation here:https://api.rubyonrails.org/classes/Time.html#method-i-to_fs
-
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:
- Advanced Ruby Class Design by Jim Weirich
- Jim Weirich on Decoupling from Rails
- Basic Rake by Jim Weirich
- Mastering The Ruby Debugger by Jim Weirich
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!
-
Sharing dynamic objects between assemblies in C#
I had a method in one assembly within my project
namespace
that accepted adynamic
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 { [TestClass()] public class MyDataClassTest { [TestMethod()] 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 theAssemblyInfo.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.
read more... -
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.
← Previous | 3 / 11 | Next → |