Skip to content

Instantly share code, notes, and snippets.

View joduplessis's full-sized avatar
Brewing coffee.

Jo du Plessis joduplessis

Brewing coffee.
View GitHub Profile
@joduplessis
joduplessis / index.js
Created February 19, 2022 14:02
ReactQuill example (for reference, so I don't forget)
// https://github.com/afry/quill-mention
// https://github.com/zenoamaro/react-quill
// <link rel="stylesheet" href="https://unpkg.com/react-quill@1.3.3/dist/quill.snow.css">
// .ql-mention-list-container{width:270px;border:1px solid #f0f0f0;border-radius:4px;background-color:#fff;box-shadow:0 2px 12px 0 rgba(30,30,30,.08);z-index:9001;overflow:auto}.ql-mention-loading{line-height:44px;padding:0 20px;vertical-align:middle;font-size:16px}.ql-mention-list{list-style:none;margin:0;padding:0;overflow:hidden}.ql-mention-list-item{cursor:pointer;line-height:44px;font-size:16px;padding:0 20px;vertical-align:middle}.ql-mention-list-item.disabled{cursor:auto}.ql-mention-list-item.selected{background-color:#d3e1eb;text-decoration:none}.mention{height:24px;width:65px;border-radius:6px;background-color:#d3e1eb;padding:3px 0;margin-right:2px;user-select:all}.mention>span{margin:0 3px}
import React, { useEffect, useState, Component } from 'react'
import './accounts.page.css'
import ReactQuill from 'react-quill'
import Qu
@joduplessis
joduplessis / session.js
Last active February 19, 2022 14:03
Simple session tracking using cookies only
window.addEventListener('load', function() {
function registerPageView(currentSessionCookieTimestamp) {
const currentTimestamp = new Date().getTime()
const fiveMinutes = 5 * 60 * 1000
if (!currentSessionCookieTimestamp) {
// ...PV logic...
} else {
if (currentTimestamp - currentSessionCookieTimestamp > fiveMinutes) {
// ...PV logic...
@joduplessis
joduplessis / index.js
Created November 10, 2020 08:31
Replacing the classNames library with 9 lines.
const classNames = (object) => {
const classArray = [];
for (let property in object) {
if (object[property]) classArray.push(property)
}
return classArray.join(' ')
}
@joduplessis
joduplessis / config.yml
Created June 10, 2020 04:30
CircleCI file for building Windows electron apps - actual Docker image doesn't always work so well.
version: 2
jobs:
build_windows:
docker:
- image: electronuserland/builder:wine
steps:
- checkout
- run: npm i
- run: npm run build:electron
- run: npm run pack:win
@joduplessis
joduplessis / convert.sh
Created May 31, 2020 19:14
Favourite bash command for converting almost any video to H.264/AAC (web video).
#!/bin/bash
ffmpeg -i input.mp4 -vcodec libx264 -acodec aac output.mp4
@joduplessis
joduplessis / letsencrypt-acme-challenge.conf
Created April 28, 2020 06:34
Generating LE certs manually with acme challenges.
#############################################################################
# Configuration file for Let's Encrypt ACME Challenge location
# This file is already included in listen_xxx.conf files.
# Do NOT include it separately!
#############################################################################
#
# This config enables to access /.well-known/acme-challenge/xxxxxxxxxxx
# on all our sites (HTTP), including all subdomains.
# This is required by ACME Challenge (webroot authentication).
# You can check that this location is working by placing ping.txt here:
@joduplessis
joduplessis / .gitlab-ci.yml
Created October 19, 2019 07:49
GitLab CI, Ansible & Docker workflow for deploying a node app to a private VPS via SSH.
image: docker:18.09.7
services:
- docker:18.09.7-dind
stages:
- build
- push
- deploy
@joduplessis
joduplessis / matchPathToUrl.js
Created September 19, 2019 12:47
Simplistic matching of Express style URL parameters NOT using Regex.
function matchPathToUrl(path, url) {
const sanitizedUrl = url[0] == '/' ? url.substring(1) : url
const sanitizedPath = path[0] == '/' ? path.substring(1) : path
const sanitizedUrlParts = sanitizedUrl.split('/')
const sanitizedPathParts = sanitizedPath.split('/')
const pathBoundaries = sanitizedPath.split('/').map(part => part[0] == ':' ? -1 : part)
let values = {}
const passes = pathBoundaries.reduce((pass, part, index) => {
if (sanitizedUrlParts.length != sanitizedPathParts.length) return false
@joduplessis
joduplessis / Keg.js
Last active September 19, 2019 12:48
Exploring synchronous queues in JS - base for one of projects I'm working on (contain lib & implementation). See https://github.com/joduplessis/keg
class Keg {
static instance;
taps = {};
queue = {};
constructor() {
setInterval(() => {
//console.log(this.taps)
//console.log(this.queue)
@joduplessis
joduplessis / Dockerfile.development
Created August 29, 2019 13:28
Docker files for a Nodejs websocket service using Redis.
FROM node:10
MAINTAINER Jo du Plessis <jo@joduplessis.com>
WORKDIR /var/www/websocket