Skip to content

Instantly share code, notes, and snippets.

View holmberd's full-sized avatar

holmberd holmberd

View GitHub Profile
@holmberd
holmberd / nginx-ssl.md
Last active November 2, 2017 22:01
Create SSL certificate for Nginx

  • sudo mkdir /etc/nginx/ssl
  • sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
Country Name (2 letter code) [AU]: __
State or Province Name (full name) [Some-State]: __
Locality Name (eg, city) []: __
Organization Name (eg, company) [Internet Widgits Pty Ltd]: __
Organizational Unit Name (eg, section) []: __
@holmberd
holmberd / nginx-ssl-cerbot.md
Last active November 2, 2017 22:10
Run SSL with Nginx and Certbot

Install cerbot

  • sudo add-apt-repository ppa:certbot/certbot
  • sudo apt-get update
  • sudo apt-get install python-certbot-nginx

Obtaining an SSL Certificate

  • sudo certbot --nginx -d example.com -d www.example.com

Auto-renewal

  • Installed with certbot in /etc/cron.d
@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.');
@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 / 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 / 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 / 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 / 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 / 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 / clean-full-boot-partition-with-unmet-dependencies.md
Last active January 3, 2019 22:46
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