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']
simple.sort(collator.compare)
// => ['a1', 'a2', 'a12']

const objects = [{"id": "a1"}, {"id": "a12"}, {"id": "a2"}]
const by = (key) => (a, b) => collator.compare(a[key], b[key])
objects.sort(by('id'))
// => [{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 @ intowindows.com

With a hint of Social Ineptitude