Skip to content

Instantly share code, notes, and snippets.

Dag Holmberg holmberd

View GitHub Profile
@holmberd
holmberd / js-range.md
Last active Mar 24, 2019
Simple Javascript Range functions
View js-range.md

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
holmberd / js-nestGroupsBy.md
Last active Mar 19, 2019
Dynamically create nested level groups by properties in Javascript
View js-nestGroupsBy.md

Dynamically create nested level groups by properties in Javascript

Code

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

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
holmberd / clean-full-boot-partition-with-unmet-dependencies.md
Last active Jan 3, 2019
Clean full boot partition with unmet dependencies - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64
View clean-full-boot-partition-with-unmet-dependencies.md

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
holmberd / minification.md
Created Dec 11, 2018 — forked from gaearon/minification.md
How to Set Up Minification
View minification.md

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
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
holmberd / ubuntu-automatic-security-updates.md
Last active Nov 6, 2018
Setup Automatic Security Updates On Ubuntu
View ubuntu-automatic-security-updates.md

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
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
holmberd / move-redis.md
Created Aug 27, 2018
Move Redis data to a separate EBS volume
View move-redis.md

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.