Skip to content

Instantly share code, notes, and snippets.

Avatar
✔️
found a nice job ! 😌

William McMurray wmcmurray

✔️
found a nice job ! 😌
View GitHub Profile
@wmcmurray
wmcmurray / basic-linode-server-security
Last active Nov 8, 2021
Basic linode web server security configuration.
View basic-linode-server-security
# A default linode web server does not have a lot of configuration done,
# those are important basic steps to perform in order to secure the server
# and also configure it properly !
# update dependencies
apt update
apt upgrade
# define hostname and timezone
hostnamectl set-hostname example-hostname
@wmcmurray
wmcmurray / backup-database.bash
Created Oct 9, 2021
A simple bash script to create Daily, Monthly and Yearly MySQL database backups
View backup-database.bash
#!/usr/bin/env bash
# This script creates daily + monthly + yearly mysql database backups locally (on the same server)
# It DOESN'T notify you by email if an error happens, and DOESN'T store backups on a cloud service !
# It DOES save a log file with the history of errors/success tho :)
# --- Edit those settings !
mysqlDbUser='root'
mysqlDbName='database_name_here'
backupDirectory='/path/to/backups/directory'
@wmcmurray
wmcmurray / main.css
Created Oct 19, 2020
Chrome newtab extension exemple
View main.css
body {
margin: 0px;
font-size: 40px;
font-family: system-ui, sans-serif;
}
.my-newtab {
display: flex;
align-items: center;
justify-content: center;
@wmcmurray
wmcmurray / FpsCap.js
Last active Oct 28, 2020
Ensure consistent frame-rate in a javascript game/app (threejs or anything else).
View FpsCap.js
/**
* Wraps an animation loop function so it can be executed at a specific frame-rate
* loop {Function} = The function you want to execute each frames
* fps {Number} = The desired frame rate
*/
function createFpsCap(loop, fps = 60) {
let targetFps = 0, fpsInterval = 0;
let lastTime = 0, lastOverTime = 0, prevOverTime = 0, deltaTime = 0;
function updateFps(value) {
@wmcmurray
wmcmurray / BasicCustomShader.js
Last active Nov 18, 2022
A basic example of a ThreeJS (r108) ShaderMaterial with shadows, fog and dithering support.
View BasicCustomShader.js
import { mergeUniforms } from 'three/src/renderers/shaders/UniformsUtils.js'
import { UniformsLib } from 'three/src/renderers/shaders/UniformsLib.js'
export default {
uniforms: mergeUniforms([
UniformsLib.lights,
UniformsLib.fog,
]),
@wmcmurray
wmcmurray / Observable.js
Last active Feb 20, 2019
Watch changes on objects using Proxy and Reflect (with an API very similar to VueJS watch mechanism)
View Observable.js
import _get from 'lodash/get'
import _set from 'lodash/set'
import _cloneDeep from 'lodash/cloneDeep'
import _isArray from 'lodash/isArray'
/**
* A system to watch for changes on an object (with an API very simillar to VueJS watch mechanism)
* @param {Object} obj The object to watch changes on
* @return {Object} Return the proxied object, which you can modify like a normal object
@wmcmurray
wmcmurray / Mediator.js
Created Sep 23, 2018
A simple events bus used to pub/sub global events across unrelated parts of a VueJS app.
View Mediator.js
import Vue from 'vue'
var MEDIATOR_VUE = new Vue();
var MEDIATOR = {
emit : MEDIATOR_VUE.$emit.bind(MEDIATOR_VUE),
on : MEDIATOR_VUE.$on.bind(MEDIATOR_VUE),
off : MEDIATOR_VUE.$off.bind(MEDIATOR_VUE),
once : MEDIATOR_VUE.$once.bind(MEDIATOR_VUE),
};
@wmcmurray
wmcmurray / PointerLockManager.js
Created Sep 23, 2018
A quick and simple implementation of the pointer lock API.
View PointerLockManager.js
class PointerLockManager {
constructor(elem) {
this.elem = elem || document.body;
this.elem.addEventListener('click', this.lock.bind(this));
document.addEventListener('pointerlockchange', this.onChangeHandler.bind(this));
}
isLocked() {
@wmcmurray
wmcmurray / cookie-clicker-hack.js
Last active Aug 22, 2022
Cookie Clicker hack (auto click on cookie, golden cookies and reindeers)
View cookie-clicker-hack.js