Skip to content

Instantly share code, notes, and snippets.

View christiannaths's full-sized avatar
🍕
Eating pizza

Christian Naths christiannaths

🍕
Eating pizza
View GitHub Profile
==========================
How Software Companies Die
==========================
- Orson Scott Card
The environment that nurtures creative programmers kills management and
marketing types - and vice versa.
Programming is the Great Game. It consumes you, body and soul. When
you're caught up in it, nothing else matters. When you emerge into
function useElementSize(): [
(el: HTMLElement | null) => void,
{ width?: number; height?: number }
] {
const [el, ref] = React.useState(null);
const width = React.useSyncExternalStore(noop, () => el?.offsetWidth);
const height = React.useSyncExternalStore(noop, () => el?.offsetHeight);
return [ref, { width, height }];
}
@christiannaths
christiannaths / input.scss
Created March 30, 2023 18:53
Generate TW Grid
@use "sass:string";
@function abr($string) {
@return string.slice($string, 0, 3);
}
.grid {
display: grid;
}
function getX3(p1, p2, y3) {
let [x1, y1] = p1;
let [x2, y2] = p2;
let slope = (y2 - y1) / (x2 - x1);
let dy = y3 - y1
return x1 + ((1 / slope) * dy)
}
@christiannaths
christiannaths / README.md
Created November 14, 2018 20:27 — forked from mbleigh/README.md
Automate the deletion of old Firebase Hosting versions.

Firebase Hosting Version Cleanup

This is a simple utility script for cleaning up Firebase Hosting versions, leaving a specified number of versions remaining. This is primarily done to conserve storage usage, but may have other uses.

USE AT YOUR OWN RISK. NO WARRANTY IS PROVIDED. THIS SCRIPT DOES DELETE STUFF PERMANENTLY

Usage

node cleanupVersions.js [commit]

@christiannaths
christiannaths / split-at-word-boundry.js
Last active June 3, 2018 19:25
Split a template literal at word boundry
function w() {
arguments[0] = { raw: arguments[0] };
const str = String.raw(...arguments);
return str.match(/\b(\w+)\b/gm);
}
w`this is a string of words`
// => ["this", "is", "a", "string", "of", "words"]
@christiannaths
christiannaths / image-cropping.coffee
Last active March 16, 2018 18:43
image-cropping.coffee
$image = $('#player_photo-preview')
$submit = $('#fake-submit')
$input = $('#player_photo')
$imageDataInput = $('#player_photo_crop_data')
form = document.forms[0]
formData = new FormData(form)
cropX = 0
cropY = 0
@christiannaths
christiannaths / webpack-symlink-trick.md
Last active October 8, 2017 19:59
Webpack: avoid relative import paths by symlinking a shortcut
@christiannaths
christiannaths / package.json
Created July 3, 2017 20:00
SVG file to JSX Component Script
"scripts": {
"build": "yarn icons:crush && yarn icons:to-jsx && yarn diagrams:crush && yarn diagrams:to-jsx",
"icons:crush": "svgo --pretty --indent=2 -f ./icons/assets",
"icons:to-jsx": "babel-node --presets=react,es2015 ./scripts/svg-to-jsx.js ./icons/assets ./icons",
"diagrams:crush": "svgo --pretty --indent=2 -f ./diagrams/assets",
"diagrams:to-jsx": "babel-node --presets=react,es2015 ./scripts/svg-to-jsx.js ./diagrams/assets ./diagrams"
}
@christiannaths
christiannaths / article-feed.md
Last active May 20, 2017 17:49
Article Feed Component

Component Structure

Option: pre-render articles via server-side page load & pass them directly into component via props. You'd still need to wait for the JS bundle to load before users would see the list, but it would cut out an extra round-trip to your server

render(
  <ArticleFeed articles={articlesArrayProvidedFromPageLoad} />,
  document.getElementById('#article-feed-root')
);