Skip to content

Instantly share code, notes, and snippets.

@WesThorburn
WesThorburn / instructions.md
Last active Feb 22, 2020
Use Chart.js with Nuxt v2.11.0
View instructions.md

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
WesThorburn / instructions.md
Last active Feb 25, 2020
Configuring PM2 to daemonize a task
View instructions.md

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

If it's not working and you need to re-install pm2

@WesThorburn
WesThorburn / instructions.md
Last active Feb 15, 2020
Deploying Git Project Repositories to an Ubuntu server
View instructions.md

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
WesThorburn / 1.Instructions.md
Last active Nov 24, 2020
Linux: Compile C++ to WebAssembly and JavaScript using Emscripten and CMake
View 1.Instructions.md

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 https://github.com/emscripten-core/emsdk.git
  • Enter the cloned directory: cd emsdk
  • Install the lastest sdk tools: ./emsdk install latest
  • Activate the latest sdk tools: ./emsdk activate latest
  • Activate path variables: source ./emsdk_env.sh
  • Configure emsdk in your bash profile by running: echo 'source "/home/user/emsdk/emsdk_env.sh"' >> $HOME/.bash_profile
@WesThorburn
WesThorburn / adding_wasm_MIME.md
Last active Aug 20, 2020
Webassembly, wasm files, webservers and MIME types
View adding_wasm_MIME.md

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
WesThorburn / client.js
Created May 14, 2018
Sending binary messages between client and server using uWS
View client.js
var socket = new WebSocket("ws://localhost:3000");
socket.binaryType = "arraybuffer";
socket.onopen = function(){
var arrayBufferMessage = stringToArrayBuffer("Test message from client");
socket.send(arrayBufferMessage);
};
socket.onmessage = function(e){
console.log(arrayBufferToString(e.data));
You can’t perform that action at this time.