Skip to content

Instantly share code, notes, and snippets.

View adrianbrowning's full-sized avatar

Adrian Elton-Browning adrianbrowning

  • Tealium
  • Reading, UK
View GitHub Profile
in_thinking=false
while read -r line; do
thinking=$(echo "$line" | jq -r '.message.content[]? | select(.type == "thinking") | .thinking // empty' 2>/dev/null)
text=$(echo "$line" | jq -rj '.message.content[]? | select(.type == "text") | .text // empty' 2>/dev/null)
if [ -n "$thinking" ]; then
if [ "$in_thinking" = false ]; then
printf '\r\n───────────────\r\n💭 '
in_thinking=true
  • Always use Typescript.
  • I like descriptive TypeScript type names (no one-letter type names for me). I also prefer the Array generic over the bracket syntax.
  • Prefer types over interfaces.
  • When writing HTML author with semantic HTML, using div and span as a very last resort. Try not to over use aria-label.
  • Always use plain CSS, never use tailwind.
  • Prefer function declarations (placed at bottom of scope).
  • Be terse
  • Suggest solutions that I didn’t think about—anticipate my needs
  • Treat me as an expert
  • Be accurate and thorough
@adrianbrowning
adrianbrowning / import-analyser.js
Created September 12, 2024 12:20
Simple ESM JS file import analyser
import * as acorn from "acorn";
import fs from "node:fs";
import path from "node:path";
const file = '/path/to/js/file.js';
const allNodes = new Map<string, TreeNode>();
class TreeNode {
@adrianbrowning
adrianbrowning / react-forwardref.tsx
Created April 19, 2023 07:46
react-forwardref.tsx
// https://fettblog.eu/typescript-react-generic-forward-refs/
declare module "react" {
function forwardRef<T, P = {}>(
render: (props: P, ref: React.Ref<T>) => React.ReactElement | null
): (props: P & React.RefAttributes<T>) => React.ReactElement | null;
}
// Usage
// Just write your components like you're used to!
@adrianbrowning
adrianbrowning / index.html
Created January 10, 2023 15:45
Input Fields — Interactive, Animated, Validated
<form>
<fieldset>
<input
type="text"
placeholder=" "
id="first-name"
minlength="5"
required
/>
<label for="first-name">Full name</label>
@adrianbrowning
adrianbrowning / lint_with_css.css
Last active September 21, 2022 14:38
lint_html_with_css.css
/* https://github.com/lorenzodelijser/lint-html-with-css */
:root {
--lint: 2px dotted red;
--lintw: 2px dashed #ffc107
}
/* Debug inputs and labels without id or for attribute */
/* Are you sure your code is ok? Explicit relation between an input and its label is always better. Use id and for attributes to do so. */
/* By Geoffrey Crofte */