Recently I blogged about replacing Moment.js with a lightweight alternative Day.js.

In Laravel, when working with dates I’ve been used to using the Carbon method diffForHumans.

It gives us a date value relative to an optional given date, but it defaults to now. Examples of output from the diffForHumans method looks like:

1
2
3
- 5 minutes ago
- One week ago
- Last Year

Rather than:

1
2
3
2019-05-19 18:08:40
2019-05-12 18:13:40
2018-05-19 18:13:40

We can do the same with Moment.js using the fromNow method. Given that Day.js is supposed to have the same API as Moment.js I assumed that the fromNow method would “Just work”.

Turns out that it didn’t. But with some small changes to our code we can get the same fromNow method working with Day.js.

Continue reading

I’m always looking for easy wins to optimise my development workflow and improve the end user experience, so figured after hearing about Purgecss I’d look into it and see how I could integrate it into my work flow.

“Purgecss is a tool to remove unused CSS”

With frameworks like Bootstrap and Zurb providing so many CSS classes that often don’t get used, this looked like it really would be an easy win situation!

Continue reading

The project im currently working on makes use of Spaties Event Projector package. Recently the team at Spatie upgraded the package to Version 2.

One of the changes that was made was to separate all storable events from regular events by moving them from the App\Events to a new App\StorableEvents folder. In moving the new stored events a new namespace of App\StorableEvents was created.

Whilst this isn’t a mandatory change, all new events classes created get in this new namespace and for the sake of keeping code organised, I wanted to move all of our other storable events to this new folder.
Light work until I wanted to replay my events. What I’d forgotten is that the fully qualified class names are stored on the stored_events table that the package uses.

No big deal I thought - ill just search for App\Events\% and replace with App\StorableEvents\%, how hard could that be in SQL? Turns out harder than I thought but not impossible…

Continue reading

When doing any sort of development work I’ve always preferred working on an Ubuntu machine.
Doing so has helped me understand the servers that our production code has always been run on.

Towards the end of last year I started work on a new project that made heavy use of Spatie’s Event Projector package.
Without getting into the package too much, at its core it stores the payloads of all recorded events in a JSON column within a stored_events table.

I hadn’t needed to use JSON columns before and since they were a part of MySQL 5.7 which was released in 2015 I had assumed there’d be no issues with using them.

For the most part I was right, writing unit tests with Laravel’s build in tools has made me come to love writing tests and made TDD part of my daily workflow.
However when I tried to run the same tests within Gitlabs CI/CD pipelines I saw the following:

1
2
3
4
5
6
7
PHPUnit 7.5.6 by Sebastian Bergmann and contributors.

Runtime: PHP 7.2.15
Configuration: /builds/secret-project/phpunit.xml

==> Tests\Unit\ExampleTest ✓
"{"errors":["SQLSTATE[HY000]: General error: 1 no such function: json_extract (SQL: select * from \"stored_events\" where \"event_class\" in (App\\Events\\ClaimReported, App\\Events\\ClaimUpdatedByApp, App\\Events\\ClaimCreated, App\\Events\\ClaimUpdated, App\\Events\\ClaimUploadCompleted) and \"id\" < 1 and json_extract(\"event_properties\", '$.\"claimUuid\"') = 0dab4335-c5e8-3564-9a0a-d0537cd697f4 order by \"id\" desc limit 1)"]}"
Continue reading

Earlier this year I blogged about reducing the file size of moment.js by stripping out additional locales. Whilst stripping the locales made a good saving in file size, really all I was using it for was to format dates within my user interfaces. So I set out on finding a lightweight alternative to do just that…

Continue reading

Introduction

Recently at work we started using PHP7.2 for all of our new projects. We’d previously been using the TetraWeb docker images for our Gitlab CI needs, however they only (at the time of writing) have a docker images for versions up to PHP7.1.

I tasked one of the junior members of my team with upgrading one of our projects and came back to our repositories commit history looking like this:

Gitlab commit history

Kind of ugly and not so useful when scanning our commit history.

In this article I want to show how we can test our Gitlab CI config locally whilst we’re working out how to set it up properly before we push it to Gitlab as well as keep our commit history cleaner in the process.

Continue reading

The PHP library Carbon is hands down my favourite way to work with dates within PHP.
When using Javascript the closes thing ive found to it is a library called Moment.js.

By default Moment.js is bundled with a plethora of locales which might not all be relavent to you or your users. In this article I want to look at how much of a size reduction we can use by stripping out unwanted locales using webpack via Laravel-Mix.

Continue reading

Introduction

My latest projects at work have evolved from being PHP / Laravel applications with sprinklings of Vue JS on the front end to being almost entirely Vue JS components driving the frontend with Laravel backends.

Whilst laravel ships with Laravel-Mix to make webpack / asset compilation easier it doesn’t ship with anyway to lint your javascript.

Luckily adding eslint and defining rules for your .js and .vue files to follow is pretty straight forward.

Continue reading

jQuery to Vue

Recently I spoke at VueNYC about my journey from the world of jQuery to Vue and some of the problems people may have along the way:

Check it out below:

If you’re in NYC they have monthly meetups that you can sign up for over here : VueNYC.

Continue reading

After moving to NYC this week, I’ve found the need to move sets of data from my local machine to a server I have back at home in the UK.

Whilst I use Resilio sync to keep things that i use regularly in sync between a number of devices this was more of a one off type deal so I decided to use the trusty command line tool rsync.
Continue reading

Author's picture

Talv Bansal

Full Stack Developer, Part Time Photographer


Head of Software Engineering


Remote