Skip to content

Instantly share code, notes, and snippets.

Dag Holmberg holmberd

View GitHub Profile
holmberd /
Last active Mar 24, 2019
Simple Javascript Range functions

Examples of Javascript simple Range functions.

// range(n)
`const range = n => [...Array(n).keys()];

// range(start, end)
const range = (start, end) => [...Array(end + 1).keys()].slice(start);
holmberd /
Last active Mar 19, 2019
Dynamically create nested level groups by properties in Javascript

Dynamically create nested level groups by properties in Javascript


 * Creates nested groups by object properties.
 * `properties` array nest from highest(index = 0) to lowest level.
 * @param {String[]} properties
 * @returns {Object}
display: grid;
grid-template-columns: repeat( auto-fit, minmax(500px, 1fr) );
grid-gap: 20px;
holmberd /
Created Feb 27, 2019
Mount remote directory with SSH

Mount remote directory with SSH

  1. Install sshfs
  • $ sudo apt-get install sshfs
  1. Create local mount point
  • $ mkdir /home/test/sshfs-path
  1. Mount remote folder /remote/path to /home/test/sshfs-path/
  • $ sshfs user@remote-host:/remote/path /home/test/sshfs-path/
holmberd /
Last active Jan 3, 2019
Clean full boot partition with unmet dependencies - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64

Remove old kernels and fix unmet dependency issue

  • See currently loaded kernel: uname -r
  • List all old kernels: dpkg --list 'linux-image*'
  • List old kernels except currently loaded: sudo dpkg --list 'linux-image*'|awk '{ if ($1=="ii") print $2}'|grep -v `uname -r`
  • Remove with force and purge: sudo dpkg --force-all -P linux-image-3.13.0-32-generic
  • Fix dependency problems: sudo apt-get install -f
  • Remove all expect the loaded kernel: sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")

Future proof yourself

  • Setup unattended upgrades: sudo dpkg-reconfigure unattended-upgrades
holmberd /
Created Dec 11, 2018 — forked from gaearon/
How to Set Up Minification

In production, it is recommended to minify any JavaScript code that is included with your application. Minification can help your website load several times faster, especially as the size of your JavaScript source code grows.

Here's one way to set it up:

  1. Install Node.js
  2. Run npm init -y in your project folder (don't skip this step!)
  3. Run npm install terser

Now, to minify a file called like_button.js, run in the terminal:

holmberd / cart-example.js
Last active Dec 12, 2018
Cart pub-sub example
View cart-example.js
/** Quick and dirty Cart pub/sub example */
class CartStore {
add(item) {}
remove(index) {}
update(index, item) {}
get(index) {}
getAll() {}
holmberd /
Last active Nov 6, 2018
Setup Automatic Security Updates On Ubuntu

Setup Automatic Security Updates On Ubuntu

Install unattended-upgrade pkg

  • (Might already be installed depending on your Ubuntu release)
sudo apt update
sudo apt install unattended-upgrades

Configure unattended-upgrade for security updates only

holmberd / asyncRetry.js
Created Nov 6, 2018
Javascript Recursive Asynchronous Retry Function
View asyncRetry.js
* Retries a async function recursively n times.
* @param {function} fn
* @param {Number} [retries=3]
* @returns {Promise}
function retry(fn, retries=3, err=null) {
if (retries === 0) {
return Promise.reject(err);
holmberd /
Created Aug 27, 2018
Move Redis data to a separate EBS volume

Move Redis data to new EBS volume (/mnt/data-01)

  • sudo vim /etc/systemd/system/redis.service

  • Set ReadWriteDirectories=-/mnt/data-01

  • sudo mkdir /mnt/data-01/redis

  • Set chown and chmod
    The permissons on /var/lib/redis are 755 and it's owned by redis:redis.
    The permissons on /var/lib/redis/dump.rdb are 644 and it's owned by redis:redis.

  • Switch configurations while redis is running

You can’t perform that action at this time.