Skip to content

Instantly share code, notes, and snippets.

View holmberd's full-sized avatar

holmberd holmberd

View GitHub Profile
@holmberd
holmberd / minification.md
Created December 11, 2018 23:33 — forked from gaearon/minification.md
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
holmberd / cart-example.js
Last active January 19, 2021 21:43
Cart pub-sub example
/** 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 March 12, 2020 18:26
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
holmberd / asyncRetry.js
Created November 6, 2018 18:39
Javascript Recursive Asynchronous Retry Function
/**
* 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 August 27, 2018 03:42
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

@holmberd
holmberd / move-sql-data.md
Created August 27, 2018 03:42
Move MySQL data to a separate EBS volume

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

  • mysql -u root -p
  • mysql> select @@datadir;
  • sudo service mysql stop
  • sudo service mysql status
  • Move files: sudo rsync -av /var/lib/mysql /mnt/data-01
  • Create backup: sudo mv /var/lib/mysql /var/lib/mysql.bak
  • Change datadir to point to the new volume:
    • sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
  • datadir=/mnt/data-01/mysql
@holmberd
holmberd / nginx-access-debug-log.md
Created August 22, 2018 17:28
Nginx access log debug

Debug Nginx access log

log_format debug_format '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" host:"$host"';
access_log /var/log/nginx/access.log debug_format;

sudo service nginx reload

@holmberd
holmberd / linux-kill-pts.md
Last active April 25, 2024 15:50
Kill tty/pts sessions in Linux

Kill user tty/pts sessions in Linux

Commands

  • w: show who is logged on and what they are doing
  • who: show who is logged on
  • tty: show current users pseudo terminal
  • ps -ft pts/1: get process id for the pseudo terminal
  • pkill: signal process based on name and other attributes
@holmberd
holmberd / api.md
Last active August 18, 2018 04:39
Product REST API CRUD Responses

Responses

POST /api/v1/products

success-status: 201

failure-status: 400 (bad request), 500

{
  id: 1,
@holmberd
holmberd / decorator.js
Created July 27, 2018 18:54
Simple decorator methods
/**
* Binds a component to one or more decorator functions.
* @param {Object} component
* @param {[function]} decorators
* @returns {Object}
* @throws {Error}
*/
function Decorator(component, decorators) {
if (!component || !decorators) {
throw new Error('Failed to create decorator, arguments invalid.');