Skip to content

Instantly share code, notes, and snippets.

WesThorburn /
Last active December 25, 2023 12:05
Use Chart.js with Nuxt v2.11.0

Use Chart.js with Nuxt v2.11.0

Line chart example

  • Run npm i vue-chartjs
  • Run npm i chart.js hchs-vue-charts
  • Create a file called chart.js and save it in the /plugins directory
  • Give chart.js the following contents
import Vue from 'vue'
import { Line } from 'vue-chartjs'
WesThorburn /
Last active March 11, 2024 07:01
Configuring PM2 to daemonize a task

Configuring PM2 to daemonize a task

  • Install pm2: sudo npm install pm2 -g
  • Start the process: sudo pm2 start path/to/process.js
  • Optionally pass command line flags like so: sudo pm2 start path/to/process.js -- --port 8080
  • Optionally provide an alias like so: sudo pm2 start npm --name "your-app-alias" -- start
  • Initialize the launch configuration: sudo pm2 startup
  • Save the configuration: sudo pm2 save
  • Optionally test that it works by restarting the server: sudo shutdown -r now

Without sudo

WesThorburn /
Last active March 21, 2023 18:35
Deploying Git Project Repositories to an Ubuntu server

Deploying Git Project Repositories to an Ubuntu server

  • If you haven't already, install git on the server by running: sudo apt-get install git
  • If you haven't already, create a repo directory inside of /var by running sudo mkdir repo
  • On the live server, go into /var/repo and create a new directory inside eg newsite.git
  • The new directory path should look like /var/repo/newsite.git
  • Ensure a new directory has been created in the www directory. Eg /var/www/newsite
  • cd into /var/repo/newsite.git and run: sudo git init --bare --bare means that our folder will have no source files, just the version control.

A number of new folders will be created, cd into the hooks directory

WesThorburn /
Last active March 14, 2024 22:11
Linux: Compile C++ to WebAssembly and JavaScript using Emscripten and CMake

Linux: Compile C++ to WebAssembly and JavaScript using Emscripten and CMake

Download and Install Emscripten

  • My preferred installation location is /home/user
  • Get the latest sdk: git clone
  • Enter the cloned directory: cd emsdk
  • Checkout main: git checkout main
  • Install the lastest sdk tools: ./emsdk install latest
  • Activate the latest sdk tools: ./emsdk activate latest
  • Activate path variables: source ./
WesThorburn /
Last active July 30, 2023 04:35
Webassembly, wasm files, webservers and MIME types

When compiling client files to webassembly, usually you'll end up with both .js and .wasm files. By default, most webservers don't know about the wasm MIME type. You'll likely see the following error: wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.

Here is how to add the wasm MIME type (on linux systems, apache + nginx):

Open /etc/mime.types You'll see two columns, media type on the left, file type on the right Add the line application/wasm wasm

WesThorburn / client.js
Created May 14, 2018 22:47
Sending binary messages between client and server using uWS
var socket = new WebSocket("ws://localhost:3000");
socket.binaryType = "arraybuffer";
socket.onopen = function(){
var arrayBufferMessage = stringToArrayBuffer("Test message from client");
socket.onmessage = function(e){