Welcome to the VectorLogic blog. We publish content of a technical nature, across the field of software (mainly web) development. The content is published on a pretty sporadic basis, but if you want a heads up when we drop any new content, please subscribe now.
In the era of hyper-sophisticated machine learning models like ChatGPT, it is surprising how effective the classic decision tree model remains, especially when used in conjunction with other techniques, such as bagging, boosting and random forests. In this blog post we demonstrate how to build an effective decision tree model, and train this model on some sample data.
Read nowSuccessfully recommending relevant content to web users is critical to business success for may web properties. There are a variety of techniques used, with the largest sites and companies employing some highly sophisticated technology to optimize their recommendations. In this blog post we discuss how to build an effective recommendation system from first principles in ruby.
Read nowThe fields of machine learning and artificial intelligence rely, fundamentally, upon the ability to measure the distance between two points. In this article we introduce some of the most common metrics used, discuss their interpretation and demonstrate how these can be implemented in ruby.
Read now
The controller-layer in any MVC architecture performs a pivotal role, leveraging the domain logic captured by your models and using this to build the views returned to the application user. Controllers in a Rails app offer a wealth of functionality and conveniences to help you complete this job. But how well do you know Rails controllers and the ActionController
API. Try the quiz below to find out?
The controller-layer in any MVC architecture performs a pivotal role, leveraging the domain logic captured by your models and using this to build the views returned to the application user. Controllers in a Rails app offer a wealth of functionality and conveniences to help you complete this job. But amongst these conveniences there lie a number of prickly parts which can do more harm than good. In this post we will present three practices which are best avoided.
Read nowRuby arrays offer a rich set of behaviours to help you solve a wide variety of problems. In this post we look two different ways of evaluating available combinations from any array-of-arrays.
Read now
The Ruby Array
class offers some of the most-used methods in the ruby ecosystem. A few months back we published a quiz, testing knowledge of ruby arrays and their associated methods. In this short post we review average performance against this quiz and identify which questions posed the biggest challenge.
The ActiveRecord
module in Rails is one of the core components which have contributed to the success and popularity of the framework. A few months back we published a quiz, testing knowledge of the ActiveRecord
API. In this short post we review average performance against this quiz and identify the question that posed the biggest challenge to our quiz-takers.
When updating a mature Rails project to use v6.1 defaults, we encountered an unexpected stack level too deep
error. Investigation revealed that naming one of our class methods :default_role
was a bad idea.
In ruby, everything is an object, so having a solid understanding of the ruby object model will make you a more effective developer. A few months back we published a quiz, testing knowledge of the ruby object model. In this short post we review average performance against this quiz and identify which question proved the hardest.
Read now
The Ruby Array
class offers some of the most-used methods in the ruby ecosystem. Regardless of your level of experience with the language you have almost certainly used some of these methods in your code. Have a go at the quiz below to see how well you know Ruby arrays.
As part of a recent project we needed to receive and process webhook notifications issued by PayPal. In this article I outline some techniques and code snippets which might prove useful to someone picking up a similar task.
Read now
The ActiveRecord
module in Rails is one of the core components which have contributed to the success and popularity of the framework. True proficiency in Rails requires a sound understanding of the API offered by this ActiveRecord
module. Take a look at the quiz below to see how well you know the Rails ActiveRecord
API.
Owing to the superpowers of the Rails ActiveRecord
module, developers can sometimes forget that, under the hood, our AR models are just regular Ruby objects. This allows us to make use of standard instance variables on the objects to adapt their behaviour, which can be useful in particular cases. In this post we discuss the technique and give an example of where it could be used.
There are several motivations for running your local web application over SSL; making use of service workers being a prime example. In this blog post we consider a number of different approaches for achieving this with a Rails application. We outline the key configuration changes required in each case, and discuss some of the drawbacks and benefits of each approach.
Read nowMastering an understanding of the ruby object model can help navigate many potential confusions about the language, and can make you a more confident and effective developer. Take a look at the quiz below to see how well you know the ruby object model.
Read now
A recent ruby upgrade exposed a flawed attempt to set some dynamically defined methods as private
. In this post I will present a bare-bones example to recreate the problem, and demonstrate how the issue can be resolved.
Matrix Factorization has proven to be a very effective technique for building recommendation systems based on collaborative filtering. In this post we summarise a few classifier evaluation metrics, and see how they can be applied to the recommendation model generated for an implicit feedback dataset.
Read nowFollowing a recent blog post on operator precedence I thought this might be a good topic for a short quiz. Take a look at the quiz below to see how well you know your operator precedence rules.
Read nowGoConqr is an e-learning platform that allows users to create and share learning resources. User-generated content fills a vast public library across a broad variety of topics. User feedback on this dataset is implicit in the views that each piece of content receives. We outline established techniques for collaborative filtering on implicit sparse datasets and apply these techniques to build a recommendation system, demonstrating how this model can be used to suggest similar content.
Read now
The array construct in Ruby is a very versatile tool. In this blog post we introduce the set operations that are supported on ruby arrays. We discuss cases in which these set operations can be exploited to write eloquent and idomatic ruby code. We also introduce the Set
class and consider under what circumstances you might wish to consider an actual Set
over an Array
.
When multiple operators appear in the same expression operator precendence will dictate the order in which these are applied. Despite being a pretty basic and fundamental concept, this often crops up at the root of hard-to-find bugs. In this blog post we take a brief look at one such case, and discuss the role played by operator precendence.
Read nowIn the modern age, building our web apps so that they can be used on mobile devices is critical. As a web developer, being able to debug problems that surface in a mobile experience can present some obstacles. In this post we look at 5 quick tips to help you get started with debugging your Rails applications on mobile web.
Read now
This series of posts will explore how we can use the HTML canvas
element to build a simple browser-based drawing tool. In this final post we look at allowing users to add text annotations to the canvas.
This series of posts will explore how we can use the HTML canvas
element to build a simple browser-based drawing tool. In this post we look at adding images to, and exporting images from our canvas.
This series of posts will explore how we can use the HTML canvas
element to build a simple browser-based drawing tool. In this post we extend our drawing tool to allow us to add resizable and draggable rectangles to the canvas.
This series of posts will explore how we can use the HTML canvas
element to build a simple browser-based drawing tool. In this first part we will look at how to implement free-hand drawing on the canvas.
When debugging we sometimes place a break point in our method of interest just to find that it is called a bazillion times before the actual invocation you are interested in. We realise that we don't want to break into the method on every invocation, we just want to focus on a single call. What can we do? This article looks at a simple trick to help overcome this problem.
Read now
Ruby offers the fetch
method to return values from a Hash
object based on a key argument.
This method can take a second argument, which will be returned when the key doesn't exist within the Hash
. But if you are not careful you may be executing code unintentionally which is not great if that code has side-effects, or is costly to run.
Web browsers expose requestAnimationFrame
to allow developers to register a callback that they wish to be invoked before the next browser repaint. This is frequently used as an efficient way to update an on-screen animation. However, if you have embedded hidden iframes you cannot rely on this method being called. We will investigate the behaviour in this blog post.
A recent point release in Rails led to unexpected Javascript errors in one of our projects. These errors related to Content-Security-Policy
violations, and they arose when the server returned a 304
(Not modified) response. In this article we investigate why these errors have arisen and how we fixed them.
The humble HTML label
element never gets much press, but it makes our form inputs more user-friendly and accessible.
In this brief post we look at using the nested format for the label
element to tighten up HTML formatting.
RSpec block syntax offers an extremely flexible option for validating the arguments passed in method calls. In this post we look at an example of how to use RSpec block syntax to verify arguments.
Read nowRails supports a RESTful interface through its resourceful routing. Sticking to these resourceful defaults can help to avoid bloated controllers and can also help to uncover hidden domain models.
Read nowSecuring controller endpoints is an important aspect of most non-trivial web applications. For Rails applications there are a number of established libraries used for this purpose. In this article we compare two of the most popular options, Pundit and CanCanCan. By means of an example we compare how these different libraries integrate into a Rails project.
Read nowContent Security Policy offers a way to lock down webpages, and prevent loading of external resources from non-trusted sources, thereby mitigating many XSS attack vectors. A nonce or hash approach can be used to handle existing inline scripts. In this post we look at how the hash generation can be achieved from the browser console, and why you may want to do that.
Read nowWe recently received a responsible disclosure from a security researcher, demonstrating an RCE exploit leveraging image uploads which were being processed by ImageMagick. Read on to understand more about the exploit, if you are vulnerable and how to mitigate.
Read nowHaving good test coverage of your code is a noble and worthwhile goal. However, sometimes resolving test failures can be an enormous time-sink. In this post we take a detailed look at one order-dependent test failure which I recently encountered. In the process we uncover an important lesson to bear in mind for your own controller specs.
Read nowSprokets remains an important part of the Rails ecosystem, despite the move to webpacker for Javascript assets. In this blog post I look at a particular case where the interplay of Sprockets require-directives and CSS @import rules can cause confusion.
Read nowRails offers filter methods to execute cross-cutting concerns around controller actions. Multiple filters can be attached to any given action, creating a filter chain. But some care is required to ensure you don't get tangled up with complicated filter chains.
Read nowThe safe-navigation operator is a great way to avoid repeated null checks. However, sometimes it can go a bit wrong. This post outlines a specific case where care is needed to ensure you don't break existing logic.
Read nowOver the last few years I have found myself reaching for CSS Flexbox with increasing frequency. Once you get a handle on a few basic properties it makes it very easy to position elements in a way that is natural and responsive. But how does this magical flex system determine the size of individual flex items? Unsurprisingly, there is some basic logic underpinning this process, and I will attempt to outline this logic here.
Read nowIn the world of software development and engineering there are innumberable books, blogs, theses etc. that are dedicated to the topic of good coding principles, and to the ultimate question of how to code well. My experiences have helped me to formulate my own ideas of what I believe to be important. I want to share these thoughts in the form of two precepts, which I have leaned on quite frequently in recent times.
Read nowRuby setter-methods are a great way to keep code explicit and terse. But beware of making a straight substitution for a regular function, as their return behaviour is different.
Read now
For many years I have equated localhost
and the loopback address 127.0.0.1
. Recently I became aware of some differences, and in particular how MySQL treats these two addresses.
If you run MySQL in a docker container there is a good chance you will bump your head on this also.