Skip to content

Instantly share code, notes, and snippets.

View geotrev's full-sized avatar
🏠
Working from home

George Treviranus geotrev

🏠
Working from home
View GitHub Profile
@geotrev
geotrev / try-catch.ts
Created March 20, 2025 14:59 — forked from t3dotgg/try-catch.ts
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};
@geotrev
geotrev / fail.js
Created November 6, 2020 20:29
it's a fail
console.log(
(![] + [])[+[]] +
(![] + [])[+!+[]] +
([![]] + [][[]])[+!+[] + [+[]]] +
(![] + [])[!+[] + !+[]]
);
@geotrev
geotrev / tcg-player-add-card-script.js
Last active May 31, 2020 02:03
Add missing cards to collection
;(() => {
const productRows = document.querySelectorAll('tr[id^="StoreProductId_"]')
productRows.forEach((row) => {
const quantity = row.querySelector(".CollectionText").innerText
const value = row.querySelector('.minPrice').innerText
if (parseInt(quantity) > 0 || value === "$0.00") return
row.querySelector(".CollectionUpArrow").click()
@geotrev
geotrev / live-exp-active-element.js
Last active February 1, 2024 15:23
Active Element Live Expression
/**
* This script recursively checks `shadowRoot`s and `contentDocument`s until the true `activeElement` is found.
*
* HOW TO USE: Copy and paste this into your Chrome dev tools in the `Create live expression` input.
*/
(function(){function d(){var u=arguments[0]||document.activeElement;if(u.shadowRoot&&u.shadowRoot.activeElement){return d(u.shadowRoot.activeElement)}if(u.contentDocument&&u.contentDocument.activeElement){return d(u.contentDocument.activeElement)}return u}return d()})();
/**
Unminified version:
@geotrev
geotrev / tic-tac-toe.js
Last active March 3, 2020 01:26
Tic Tac Toe
class TicTacToe {
constructor() {
this.handleMouseEnter = this.handleMouseEnter.bind(this)
this.handleMouseLeave = this.handleMouseLeave.bind(this)
this.handleClick = this.handleClick.bind(this)
this.handleResetClick = this.handleResetClick.bind(this)
this.tiles = []
this.start()
}
@geotrev
geotrev / deploy.sh
Created January 3, 2020 02:54
Bash Script: Auto Deploy to gh-pages Branch
#!/usr/bin/env bash
set -o nounset
set -o errexit
set -o pipefail
git config user.name "$USER_NAME"
git config user.email "$USER_EMAIL"
# Add github to known_hosts to enable push from CI
@geotrev
geotrev / config.yml
Created January 3, 2020 02:46
Circle CI Config for GH Pages
version: 2
jobs:
build:
working_directory: ~/repo-working-dir
docker:
- image: circleci/ruby:2.6.5-node-browsers
steps:
- checkout
- save_cache:
@geotrev
geotrev / rollup.config.js
Last active February 3, 2022 01:02
Jekyll Rollup Config
import { terser } from "rollup-plugin-terser"
import path from "path"
import resolve from "rollup-plugin-node-resolve"
import babel from "rollup-plugin-babel"
import glob from "glob"
const scriptPattern = path.resolve(__dirname, "_scripts/**/!(_)*.js")
const inputs = glob.sync(scriptPattern).reduce((files, input) => {
const parts = input.split("/")
@geotrev
geotrev / simple-timer-mock.md
Last active January 10, 2020 17:30
timer mock
const mockTimers = () => {
	const globalTimerFn = window.setTimeout;

	const runAllTimers = () => (window.setTimeout = (fn) => fn());
	const restoreAllTimers = () => (window.setTimeout = globalTimerFn);

	return {runAllTimers, restoreAllTimers};
};
@geotrev
geotrev / dom.js
Last active September 6, 2019 01:41
Simple DOM manipulator utility
export const dom = {
// Attribute manipulation
getAttr: (element, attr) => element.getAttribute(attr),
setAttr: (element, attr, value) => element.setAttribute(attr, value),
removeAttr: (element, attr) => element.removeAttribute(attr),
toggleAttr: (element, attr, forceCondition) => element.toggleAttribute(attr, forceCondition),
hasAttr: (element, attr) => element.hasAttribute(attr),
// Element selection
find: (selector, parent = document) => parent.querySelector(selector),