Skip to content

Instantly share code, notes, and snippets.

View wmcmurray's full-sized avatar
🙂
working on networking when I have the time ⏳

William McMurray wmcmurray

🙂
working on networking when I have the time ⏳
View GitHub Profile
@wmcmurray
wmcmurray / cookie-clicker-hack.js
Last active November 15, 2024 01:30
Cookie Clicker hack (auto click on cookie, golden cookies and reindeers)
@wmcmurray
wmcmurray / PointerLockManager.js
Created September 23, 2018 01:01
A quick and simple implementation of the pointer lock API.
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 / Mediator.js
Created September 23, 2018 14:02
A simple events bus used to pub/sub global events across unrelated parts of a VueJS app.
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 / Observable.js
Last active February 20, 2019 05:05
Watch changes on objects using Proxy and Reflect (with an API very similar to VueJS watch mechanism)
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 / BasicCustomShader.js
Last active September 21, 2024 13:44
A basic example of a ThreeJS (r108) ShaderMaterial with shadows, fog and dithering support.
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 / FpsCap.js
Last active October 28, 2020 18:09
Ensure consistent frame-rate in a javascript game/app (threejs or anything else).
/**
* 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 / main.css
Created October 19, 2020 17:28
Chrome newtab extension exemple
body {
margin: 0px;
font-size: 40px;
font-family: system-ui, sans-serif;
}
.my-newtab {
display: flex;
align-items: center;
justify-content: center;
@wmcmurray
wmcmurray / backup-database.bash
Created October 9, 2021 15:15
A simple bash script to create Daily, Monthly and Yearly MySQL database backups
#!/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 / basic-linode-server-security
Last active November 8, 2021 19:39
Basic linode web server security configuration.
# 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