Skip to content

Instantly share code, notes, and snippets.

View tmgldn's full-sized avatar
🏙️
londinium

Tom G tmgldn

🏙️
londinium
View GitHub Profile
@tmgldn
tmgldn / clonify.sh
Created January 30, 2018 17:05
Script used to help mark assignments at UC Berkeley Web Dev, with example urls.txt file
#!/bin/bash
touch urls.txt
CURR=`pwd`
if [ $# -ne 0 ]
then
let COUNT=0
mkdir $1
while read url
@tmgldn
tmgldn / withWindowWidth.jsx
Created May 8, 2019 06:20
withWindowWidth React Higher Order Component (HOC) using Hooks
import React, { useState, useEffect, useRef } from 'react';
window.windowWidthListeners = window.windowWidthListeners || {};
window.prevWidth = window.prevWidth || window.innerWidth;
window.addEventListener('resize', () => {
if (window.prevWidth !== window.innerWidth) {
window.prevWidth = window.innerWidth;
Object.values(window.windowWidthListeners).forEach(fn => fn(window.prevWidth));
}
@tmgldn
tmgldn / debounce.js
Created May 8, 2019 06:30
Lightweight JS promise debounce
const debounce = (func, ms = 500) => {
let timeout;
return function(...args) {
clearTimeout(timeout);
return new Promise(resolve => {
timeout = setTimeout(() => {
resolve(func.bind(this)(...args));
}, ms);
});
};
@tmgldn
tmgldn / convert.js
Created November 8, 2019 17:12
A very short way to safely encode arbitrary data as an id friendly, url safe slug
// For node and pre-babel src
const toSafeSlug = str => "_" + encodeURIComponent(str)
.replace(/[.!~*'()_-]/g, match => `%${match.charCodeAt(0).toString(16)}`.toUpperCase())
.replace(/%/g, "_");
const fromSafeSlug = str => decodeURIComponent(str.substring(1).replace(/_/g, "%"));
// ES5 friendly
@tmgldn
tmgldn / bitwardenTidy.js
Last active December 30, 2022 23:57
Import bitwarden export json, interactive deduplicate and export bitwarden import json
const fs = require('fs');
const path = require('path');
const inquirer = require('inquirer');
const uuidv4 = require('uuid/v4');
const owasp = require('owasp-password-strength-test');
const words = new Set([...require('wordlist-english')['english/10'], ...require('wordlist-english')['english/20']]);
const thingsIDontDoAnyMore = require("./thingsIDontDoAnyMore.json");
const { items } = require('./bitwarden_export_file.json');
@tmgldn
tmgldn / css-shorthand-map.json
Created March 21, 2020 16:17
JSON map from CSS shorthand properties to their sub-properties
{
"animation": [
"animation-name",
"animation-duration",
"animation-timing-function",
"animation-delay",
"animation-iteration-count",
"animation-direction",
"animation-fill-mode",
"animation-play-state"
@tmgldn
tmgldn / Queue.ts
Created April 11, 2020 19:46
Fast implementation of a queue in TypeScript/JavaScript
class Queue {
private readonly queue: any[];
private start: number;
private end: number;
constructor(array: any[] = []) {
this.queue = array;
// pointers
this.start = 0;
@tmgldn
tmgldn / progressive-browserlist-config.md
Last active December 20, 2023 12:10
Low-effort, high-reward browserlist config to avoid vendor prefix hell

Low-effort, high-reward browserlist config to avoid vendor prefix hell

(Stats used from 2022-06-20)

chrome >= 79, and_chr >= 81, safari >= 13, ios_saf >= 12.4, firefox >= 73

...or more generally

[
@tmgldn
tmgldn / optionalDependenciesRollup.md
Last active May 31, 2020 04:58
How to use optionalDependencies in a Rollup library (with ES and TS examples)

Using csso as the example library I'm making an optional dependency

ES Module example (file.js)

let csso = globalThis && globalThis.csso
if (!csso) {
  import('csso')
    .then(_csso => {
      csso = _csso.default
@tmgldn
tmgldn / inotify-instructions.md
Last active January 12, 2026 11:46
[Arch Linux] [Manjaro] How to avoid "Visual Studio Code is unable to watch for file changes in this large workspace" (error ENOSPC)

To avoid this error, we need to increase the inotify watcher limit.

The way to do this is different on Arch based distributions than other Linux distributions.

Instructions for Arch Linux/Manjaro

Check for an already existing inotify config file (recent versions of Manjaro include one)