Skip to content

Instantly share code, notes, and snippets.

@djave-co
djave-co / 1. Setup.js
Last active October 11, 2021 15:57
Automate scroll
// https://matthewlein.com/tools/ceaser
class Scroll {
constructor() {
document.documentElement.style.scrollBehavior = 'auto';
document.body.style.scrollBehavior = "auto";
window.addEventListener("scroll", this.outputScroll);
const lerp = (v0, v1, t) => {
return (1 - t) * v0 + t * v1;
}
const scale = (num, in_min, in_max, out_min, out_max) => {
return ((num - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min;
};
y=1-x^{3}
async function getGameId(){
// Create a 6 figure game code.
let idSize = 2;
let id = Math.floor(Math.random() * Math.pow(10, idSize)).toString();
id = id.padStart(idSize, '0');
// See if that game already exists
let snapshot = await db.collection("games").doc(id).get()
if (snapshot.exists) {
console.log("Game " + id + " already exists");
@djave-co
djave-co / WeightedRandom.js
Last active April 21, 2020 21:32
A tiny object that can return random numbers with different biases
// Demo / visualisation:
// https://codepen.io/EightArmsHQ/pen/BaavyPQ
let WeightedRandom = {
random(){
return Math.random();
},
sphere(){
return (Math.sin(1-Math.random() * 2 * Math.PI)+1) / 2;
},
import debounce from "lodash/debounce"
let localStorageAvailable = () => {
let test = 'test';
try {
localStorage.setItem(test, test);
localStorage.removeItem(test);
return true;
} catch(e) {
return false;
@djave-co
djave-co / gist:05808c8d8151fa0f22e289ed9cdef3d9
Last active March 8, 2018 15:41
Vue calendar component
<template>
<div class="calendar">
<nav class="calendar__nav">
<a @click="decMonth" class="calendar__chevron btn btn-primary">
&larr;
</a>
<b>{{ monthName }}</b>
<b>{{ year }}</b>
<a @click="incMonth" class="calendar__chevron btn btn-primary">
&rarr;
@djave-co
djave-co / Calendar.vue
Created April 26, 2017 12:04
A tiny calendar component
// Requires datejs
// https://github.com/datejs/Datejs
<template>
<div id="calendar">
<nav class="calendar--nav">
<a @click="decMonth" class="calendar--nav--chevron">
<i class="fa fa-chevron-left" aria-hidden="true"></i>
</a>
<b>{{ monthArray[month] }}</b>
@djave-co
djave-co / Fix SSL.md
Last active April 27, 2017 11:34
Fix the SSL on a new Wordpress roots site

SSH into Trellis server and delete the CSRs in

/var/lib/letsencrypt/csrs

SSH into Trellis server and delete the certs in

/etc/nginx/ssl/letsencrypt

Set ssl

@djave-co
djave-co / Making a Trellis install
Created April 11, 2017 14:49
How to do wordpress the right way from Dave Kiss
git clone git@github.com:roots/trellis.git trellis
cd trellis && ansible-galaxy install -r requirements.yml
cd ..
git clone git@github.com:roots/bedrock.git site
cd site && composer install
cd ..
sublime trellis/group_vars/development/wordpress_sites.yml
sublime trellis/group_vars/development/vault.yml
cd trellis && vagrant up
@djave-co
djave-co / Making a Trellis install
Created April 11, 2017 14:49
How to do wordpress the right way from Dave Kiss
git clone git@github.com:roots/trellis.git trellis
cd trellis && ansible-galaxy install -r requirements.yml
cd ..
git clone git@github.com:roots/bedrock.git site
cd site && composer install
cd ..
sublime trellis/group_vars/development/wordpress_sites.yml
sublime trellis/group_vars/development/vault.yml
cd trellis && vagrant up