Skip to content

Instantly share code, notes, and snippets.

@broofa
broofa / checkForUndefinedCSSClasses.js
Last active January 21, 2024 17:22
ES module for detecting undefined CSS classes (uses mutation observer to monitor DOM changes). `console.warn()`s undefined classes.
/**
* Sets up a DOM MutationObserver that watches for elements using undefined CSS
* class names. Performance should be pretty good, but it's probably best to
* avoid using this in production.
*
* Usage:
*
* import cssCheck from './checkForUndefinedCSSClasses.js'
*
* // Call before DOM renders (e.g. in <HEAD> or prior to React.render())
const Sequelize = require('sequelize');
async function main() {
const sequelize = new Sequelize(null, null, null, {
dialect: 'sqlite',
storage: ':memory:',
});
await sequelize.query('CREATE TABLE things (id INTEGER PRIMARY KEY, aColumn TEXT DEFAULT NULL)');
@broofa
broofa / worker_thread_test.js
Last active August 19, 2019 13:00
Playing around with worker_threads
const {Worker, isMainThread, parentPort, workerData} = require('worker_threads');
const gameIdToWorker = new Map();
const gameIds = []; // Not required. just makes it easy to pick a random game id
let messageCount = 0;
/** Initialize a worker thread */
function makeWorker(workerId) {
const worker = new Worker(__filename, {workerData: {workerId}});
@broofa
broofa / broofa_unicode_literal.md
Last active June 23, 2020 14:00
Broofa's Unicode Literal v1.0

The following string literal is intended for use as a test case for code that works with Unicode strings. It includes the first character from each of the Unicode ranges mentioned at https://www.ling.upenn.edu/courses/Spring_2003/ling538/UnicodeRanges.html

Unicode (be careful copy/pasting this, as it may not yield the correct string): �Āƀɐʰ̀ͰЀԀ԰֐؀܀ހऀঀ਀઀଀஀ఀಀഀ඀฀຀ༀကႠᄀሀᎠ᐀ ᚠᜀᜠᝀᝠក᠀ᤀᥐ᧠ᴀḀἀ ⁰₠⃐℀⅐←∀⌀␀⑀①─▀■☀✀⟀⟰⠀⤀⦀⨀⬀⺀⼀⿰ ぀゠㄀㄰㆐ㆠㇰ㈀㌀㐀䷀一ꀀ꒐가𐀀豈ffﭐ︀︠︰﹐ﹰ＀￰𐀀𐂀𐄀𐌀𐌰𐎀𐐀𐑐𐒀𐠀𝀀𝄀𝌀𝐀𠀀丽󠀀󠄀

JS Literal: \u{0000}\u{0080}\u{0100}\u{0180}\u{0250}\u{02b0}\u{0300}\u{0370}\u{0400}\u{0500}\u{0530}\u{0590}\u{0600}\u{0700}\u{0780}\u{0900}\u{0980}\u{0a00}\u{0a80}\u{0b00}\u{0b80}\u{0c00}\u{0c80}\u{0d00}\u{0d80}\u{0e00}\u{0e80}\u{0f00}\u{1000}\u{10a0}\u{1100}\u{1200}\u{13a0}\u{1400}\u{1680}\u{16a0}\u{1700}\u{1720}\u{1740}\u{1760}\u{1780}\u{1800}\u{1900}\u{1950}\u{19e0}\u{1d00}\u{1e00}\u{1f00}\u{2000}\u{2070}\u{20a0}\u{20d0}\u{2100}\u{2150}\u{2190}\u{2200}\u{2300}\u{2400}\u{2440}\u{2460}\u{2500}\u{2580}\u{25a0}\u{2600}\u{2700}\u{27c0}\u{27f0}\u{2800}\u{2900

-- b-CAP.lua
--
-- a basic Wireshark's LUA dissector for Binary Controller Access Protocol
-- see README for installation and usage
--
-- Copyright (C) 2014 DENSO WAVE INCORPORATED
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
@broofa
broofa / git-hub
Created December 22, 2017 18:28
Open GitHub web page on to current repo+branch+file
#!/bin/bash
# File: git-hub
#
# Description: Open github webpage for the current repo+branch[+file]
# (for MacOSX, not tested on other platforms)
#
# Usage: git hub
# git hub <file>
#
# Installation: Save as "git-hub" in a directory in your PATH, then `chmod a+x git-hub`
@broofa
broofa / IdiotsGuide.md
Last active May 13, 2019 20:38
The Idiot's Guide to Managing an OpenSource Project on Github (and NPM)

The Idiot's Guide to Managing an OpenSource Project on Github (and NPM)

This doc attempts to capture some of the more nuanced tips and tricks involved in managing an NPM-based open source project, specifically with an eye toward maintaining a structured release process that limits the pain and surprises you cause your audience.

Preface

Contrary to the title, this guide is going to assume you're not an idiot. In fact, a working knowledge of git, GitHub, and NPM are assumed. Moreover, we're going to gloss over the basic steps involved in creating a project and instead focus on the less-obvious aspects of how you maintain a project. So, things this guide assumes you've done before you got here:

  • Write some useful code
  • Create a github repo for it
@broofa
broofa / Chrome_Go_To_Line.js
Created September 12, 2017 16:11
Bookmarklet for Go To Line in Chrome "view-source" pages
// Instructions
// 1. Go to Chrome -> Bookmarks -> Bookmarks Manager
// 2. Right-click Bookmarks Bar -> "Add Page ..."
// 3. Enter "Go To Line" for Name
// 4. Copy/paste the code below into URL (From-and-including "javascript:" to "void 0;"
//
// Now on any "view-source:..." page in Chrome, click the Bookmarks -> Go To Line menu
// item to scroll to and highlight the line of your choice
// -----
@broofa
broofa / git-hub
Last active May 23, 2017 16:07
Open github page for current repo/branch/file from command line (MacOSX)
#!/bin/bash
# File: git-hub
#
# Description: Open github webpage for the current repo+branch[+file]
# (for MacOSX, not tested on other platforms)
#
# Usage: git hub
# git hub <file>
#
# Installation: Save as "git-hub" in a directory in your PATH, then `chmod a+x git-hub`
@broofa
broofa / pre-commit
Last active February 23, 2024 08:55
Git pre-commit hook that runs `eslint` with the `--fix` option to fix up issues where possible, and adds "fix"ed files into the commit
#!/bin/bash
cd "$(git rev-parse --show-toplevel)"
ESLINT="node_modules/.bin/eslint"
pwd
if [[ ! -x "$ESLINT" ]]; then
printf "\t\033[41mPlease install ESlint\033[0m (npm install eslint)\n"
exit 1
fi