CODING


  • Time String Helper

    Time String Helper

    Formatting Time in Flutter/Dart: A Simple Helper Class When working on Flutter projects, you might need to format durations into readable time strings. This could be for timers, media players, or activity trackers. To make this task a bit easier, here’s a lightweight helper class, TimeStringHelper, that handles common formatting needs. What TimeStringHelper Does Converts…

  • Use search terms in eloquent queries for Laravel

    Use search terms in eloquent queries for Laravel

    I needed to make an Eloquent query that could take search terms. The search terms are optional – no search term and the whole dataset is returned. In our particular data model the Users have one or many Associations. So the search term should check for user name, phone, email and association name. In the…

  • Impersonate users with Sanctum in Laravel

    Impersonate users with Sanctum in Laravel

    I needed to write a somewhat clean solution to let an admin impersonate other users. Which basically means that one user can appear as another user – without having to get access that users credentials to log in. The most obvious use case for this would be when an admin needs access to a user’s…

  • (Dart) Round integer to 10,100, 1000 etc.

    (Dart) Round integer to 10,100, 1000 etc.

    If you need to shave off the last few digits of a big int, you can use this simple solution. Came in handy for me when working with milliseconds in timers. Basically you cast the integer to a double and divide it by the number of 0’s you want at the end. Then round, ceil…

  • (JS) Calculate price excluding VAT

    Sometimes you need to calculate the price of a product excluding VAT, and the only details you have is the amount including vat and the vat percent. This might be a bit tricky in some applications when there are mixed VAT percentages. For example, you payed 1000 space credits and in that sum there is…

  • (JS) Convert short color hex to pair

    If you have a three digit hex for a color. For example #FFF and want to convert it to a 6 digit number here’s a simple way:

  • (JS) Validate date in format YYYY-MM-DD

    A simple JS function to validate that a date string in the format YYYY-MM-DD is a valid date. Will validate that the day is correct for the given month, including leap years

  • (JS) Validate Swedish personnummer and organisationsnummer

    JavaScript functions for validating Swedish personal identity numbers (personnummer), and organisation numbers (organisationsnummer). The functions for personal identity number will also validate co-ordination number (samordningsnummer).

  • Laravel with SSL through Cloudflare on Heroku.

    Laravel with SSL through Cloudflare on Heroku.

    I deployed a Laravel app on Heroku, using Cloudflare for SSL. As a quick note, here’s how I did it. NOTE: if you’re using Laravel 5.4 or higher it’s forceScheme instead of forceSchema Also, you need to set your Laravel environment variable APP_ENV to production (or at least something else than local). Do this in…

  • (JS) Use include method in IE

    Here’s a hack for using the includes method also in the horrible Internet Explorer. [js] if (!String.prototype.includes) { String.prototype.includes = function () { ‘use strict’; return String.prototype.indexOf.apply(this, arguments) !== -1; }; } [/js]