Skip to content

Instantly share code, notes, and snippets.

View georapbox's full-sized avatar

George Raptis georapbox

View GitHub Profile
@georapbox
georapbox / counter.ts
Created January 14, 2025 06:54 — forked from rodydavis/counter.ts
Signals + Web Components
import { computed, signal } from "@preact/signals-core";
import { type SignalsTemplate, render } from "./signals-template";
import { SignalsWebComponent } from "./signals-web-component";
const tagName = "x-counter";
class Counter extends SignalsWebComponent {
counter = signal(0);
counterStr = computed(() => this.counter.value.toString());
@georapbox
georapbox / mergerefs.jsx
Created April 7, 2024 06:59 — forked from cassidoo/mergerefs.jsx
Merge refs in React so a component can have more than one ref
export function mergeRefs(refs) {
return (value) => {
refs.forEach((ref) => {
if (typeof ref === "function") {
ref(value);
} else if (ref != null) {
ref.current = value;
}
});
};
class PathMe {
moves: string[] = [];
constructor() {
this.moves = [];
return this;
}
moveTo(x: number, y: number) {
// Credit to Michal Mocny (https://twitter.com/mmocny)
//
// Copy and paste this into the console and click around to see all interactions, whether they would pass INP,
// and if you expand the entry you'll see the debug breakdown information.
//
// This is basically the same as the Core Web Vitals extension does: https://web.dev/debug-cwvs-with-web-vitals-extension/
const valueToRating = (score) => score <= 200 ? 'good' : score <= 500 ? 'needs-improvement' : 'poor';
const COLOR_GOOD = '#0CCE6A';
@georapbox
georapbox / dom-mutation-logger.js
Created November 8, 2022 11:49 — forked from captainbrosset/dom-mutation-logger.js
Useful DevTools snippets
function logMutation(mutation) {
console.log(mutation);
}
const mutationObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
// Build a reason object that will let the user know what exactly happened
let details = null;
if (mutation.type === "attributes") {
details = {
@georapbox
georapbox / Firefox tabs script
Created February 4, 2022 15:52 — forked from mikeconley/Firefox tabs script.md
A script you can execute in your Browser Console to generate a string representation of your tabs!
/**
* If you have your Browser Console command-line enabled[1], you can paste this string
* in to generate an emoji representation of your tabs, which will automatically be copied
* into your clipboard.
*
* WARNING: Be VERY careful with what you put into your Browser Console - don't run
* any scripts in there that you yourself don't understand.
* This script was written by Nicolas Chevobbe (@nicolaschevobbe)
*
* [1]: https://developer.mozilla.org/en-US/docs/Tools/Browser_Console#browser_console_command_line
// Core assets
let coreAssets = [];
// On install, cache core assets
self.addEventListener('install', function (event) {
// Cache core assets
event.waitUntil(caches.open(coreID).then(function (cache) {
for (let asset of coreAssets) {
cache.add(new Request(asset));
@georapbox
georapbox / pre-commit.sh
Created April 14, 2021 20:02 — forked from dahjelle/pre-commit.sh
Pre-commit hook for eslint, linting *only* staged changes.
#!/bin/bash
for file in $(git diff --cached --name-only | grep -E '\.(js|jsx)$')
do
git show ":$file" | node_modules/.bin/eslint --stdin --stdin-filename "$file" # we only want to lint the staged changes, not any un-staged changes
if [ $? -ne 0 ]; then
echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via npm run eslint."
exit 1 # exit with failure status
fi
done

ServiceWorker for github pages

This is a ServiceWorker template to turn small github pages into offline ready app.

Why ?

Whenever I make small tools & toys, I create github repo and make a demo page using github pages (like this one).
Often these "apps" are just an index.html file with all the nessesary CSS and JavaScript in it (or maybe 2-3 html/css/js files). I wanted to cache these files so that I can access my tools offline as well.

Notes

Make sure your github pages have HTTPS enforced, you can check Settings > GitHub Pages > Enforce HTTPS of your repository.

@georapbox
georapbox / commands.sh
Created November 26, 2020 08:01 — forked from dstranz/commands.sh
nice option to use bundler on macOS Catalina without playing with sudo or rvm like before
# install bundler in user space
gem install bundler --user-install
# then add following lines to ~/.zshrc on Catalina or ~/.bash_profile on older:
# - to set default bundle install directory
export BUNDLE_PATH=$(ls -t -U | ruby -e 'puts Gem.user_dir')
# - to add user gem directory to $PATH
export PATH="$PATH:$BUNDLE_PATH/bin"