Skip to main content

Slugify string

· One min read
Filip Tammergård
Software Engineer at Frilans Finans

When you generate URLs from titles, the title typically can't be used directly — spaces, question marks and other special characters don't belong in URL slugs. That's where a slugify function comes in handy.

Filling space with flex-grow

· 2 min read
Filip Tammergård
Software Engineer at Frilans Finans

I recently faced a task to create a contact form, with input rows in one column and a textarea and submit button in the other column. The fun little challenge was to make the textarea fill the available space above the submit button in a responsive way, so that the textarea will continue to fill the available space regardless of the number of input rows in the column to the left.

Here is the design, where you can choose the number of input rows:

Input row
Input row
Input row
Input row
Input row
Textarea
Submit button

Uniquify array

· 2 min read
Filip Tammergård
Software Engineer at Frilans Finans

Consider this array of names:

const names = [
"Filip",
"Anna",
"Jennifer",
"Anna",
"Robert",
"Emma",
"Filip",
"Anna",
]

In this array, Filip occurs two times and Anna three times. What if we want to filter out the duplicates and get an array with the unique names?

Centering with CSS

· 3 min read
Filip Tammergård
Software Engineer at Frilans Finans

I often face the task of centering something. Either horizontally or vertically, and often in both directions at the same time. When flex and grid didn't exist in CSS, it could be quite cumbersome to get vertical and horizontal centering working. Now there are easy solutions!

We start from a span element in a div:

I want to be centered!

Word and character counter

· 3 min read
Filip Tammergård
Software Engineer at Frilans Finans

Use this counter if you want to count words, characters or a sequence of characters in a text!

Number of words: 0

Number of characters: 0

Colors on the web

· 6 min read
Filip Tammergård
Software Engineer at Frilans Finans

Colors on the web can be defined in many different ways. There are 140 color names, such as green, goldenrod and navy. On top of that, there are four standards for color values: HEX, RGB, RGBA and HSL. I'll go through them one by one in this post and also show how to generate random color values for each standard with React.

Pi decimals

· One min read
Filip Tammergård
Software Engineer at Frilans Finans

How many decimals of pi do you know? Here you can test yourself and try to improve. Click the box below and type the first decimal to begin. If you want help, you can click the "Show answer" button, where you'll also see how far you've come — the correctly typed decimals have a green background.

Operations in JavaScript with immutable arrays

· 3 min read
Filip Tammergård
Software Engineer at Frilans Finans

As mentioned many times before, I always try to keep my variables immutable when developing. Let's take a closer look at how we accomplish immutable arrays in JavaScript when adding, replacing or removing elements. We start with an array of birds:

const birds = ["Great tit", "Blue tit", "Pine grosbeak", "Stock dove"]

Format lists with Intl.ListFormat

· 3 min read
Filip Tammergård
Software Engineer at Frilans Finans

Let's say we have this array of cities:

const cities = ["Uppsala", "Stockholm", "Lycksele", "Lund"]

And let's say we want to write the cities from the array in a sentence like this:

Uppsala, Stockholm, Lycksele and Lund are 4 nice cities in Sweden.

How?!