Category Archives: Technology

My blog posts related to technology, technical things and, in particular, computers and computer software.

Natural sort in Javascript

Sorting strings naturally/numerically in Javascript is very simple. You just need to remember the existence of the Intl.Collator… which I keep forgetting…

You simply create one and use its compare function:

const collator = new Intl.Collator(undefined, {
    usage: 'sort',
    numeric: true

const simple = ['a1', 'a12', 'a2']
// => ['a1', 'a2', 'a12']

const objects = [{"id": "a1"}, {"id": "a12"}, {"id": "a2"}]
const by = (key) => (a, b) =>[key], b[key])
// => [{id: 'a1'}, {id: 'a2'}, {id: 'a12'}]

Git: Undo last commit

Sometimes I forget to create a new feature branch, and accidentally commit to master. Keep having to look up how to fix it…

# From master, create new branch, which will include the accidental commits
git branch feature/foobar

# Move master HEAD back, which will remove the commits from there
git reset --hard HEAD~1

# Checkout feature branch, where the commits should still exist
git checkout feature/foobar

How to rename bluetooth device in Windows 10

When my wireless QC30 headset connects to a device, it reads out “connected to [device-name]”. This is handy, but when for example connecting to my work laptop, which has a rather long cryptic alphanumeric name, it gets annoying instead. And since it’s a work laptop, I can’t just change the name of the device either, and frankly, I don’t want to have to do that either. I just want my device to have a different name specific to bluetooth. Turns out, you can actually do that:

  1. Run devmgmt.msc
  2. Find your bluetooth adapter under Device Manager / Bluetooth
    E.g. mine is called Intel(R) Wireless Bluetooth(R)
  3. Right-click and choose Properties
  4. Go to the Advanced tab
  5. Change Name
  6. Hit OK

And it’s done. 👍

Source: comment @

Excel time calculation and formatting

It’s actually really simple, but for some reason I just keep having to look up some of these… so… finally… note to self…

Calculations =X+Y
12:45 - 9:55 = 2:50
Time to decimal =X*24 2:50 * 24 = 2.83
Decimal to time =X/24 2,83 / 24 = 2:50
Days, hours, minutes d h:mm 11 19:20
Total hours and minutes [h]:mm 283:20
Total minutes [m] 17000

Regarding the formatting, without the brackets, it formats as regular time (total hours % 24). So, for example, 2 hours and 50 minutes multiplied by 100; with a regular time format (h:mm) it displays as 19:20; using brackets ([h]:mm) you get the correct 283:20, which is 11 days 19 hours and 20 minutes (hence the 19:20 from h:mm).

Excel screenshot