Skip to content

Instantly share code, notes, and snippets.

View onion2k's full-sized avatar
💭
In your browser, making it do stuff.

Chris Neale onion2k

💭
In your browser, making it do stuff.
View GitHub Profile
const resHeaders = Object.prototype.hasOwnProperty.call(res, 'headers')
? res.headers.all()
: Object.fromEntries(res.headers.entries());
@onion2k
onion2k / zod input output
Created April 4, 2023 08:57
A zod validator that uses input and output
const MyFunctionProps = z.object({
date: z
.string()
.datetime()
.transform((str) => new Date(str))
});
function MyFunction(props: z.input<typeof MyFunctionProps>): z.output<typeof MyFunctionProps> {
const { date } = MyFunctionProps.parse(props);
@onion2k
onion2k / hn.js
Last active May 11, 2022 20:03
Highlight HN Posts by score.
Array.from(
document.querySelectorAll('span.score')
).filter(
(score)=>score.innerText.match(/[2,3] points/))
.forEach(
(score)=>{
[score.closest('tr'), score.closest('tr').previousSibling]
.forEach((el)=>el.style.backgroundColor = '#ffd')
}
);
@onion2k
onion2k / remotion.library.tsx
Last active October 17, 2023 16:56
A Remotion component to display a library of other components
import {getInputProps, Composition, Sequence, Img } from 'remotion';
import React from 'react';
import { Arid } from './components/arid/Arid'
import { BlurSwipe } from './components/blur-swipe/BlurSwipe'
import { CSSAnim } from './components/CSSAnim/CSSAnim'
import chrome from "./assets/chrome.png"
const props = getInputProps()
.burns-outer {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.burns-inner {
position: absolute;
width: calc(100% + 8em);
import {interpolate, Sequence, useCurrentFrame, useVideoConfig, AbsoluteFill, Easing } from 'remotion';
import './styles.css'
const TextIn:React.FC<{ text: string, color: string, duration: number }> = ({ text="Whoosh!", color="white", duration }) => {
const frame = useCurrentFrame();
const scale = interpolate(
frame,
[0,duration],
[0.1, 50],
@onion2k
onion2k / happypath.md
Last active February 4, 2021 13:03
Heuristics for making better software

Rules and guidelines for writing better apps.

Code

  • Readability is important for maintaining a good app. Make sure your code matches the standard for the project.
  • Don't try to be clever. Writing code that other developers understand is more important than writing code that runs as fast as possible, or that is as short as possible.
  • Never nest ternaries. Just don't. They're hard to read.
  • Code should either work or not work. It should be clear when something is not working. There should be never be an in-between, intermediate half-working state. Eg if a build fails then it shouldn't be in a running-but-not-working state afterwards.
  • Leave the code in a better state than it was when you found it. Refactor things that can be simplified, rename things that are badly named, add comments to explain what you've discovered, add tests for things that don't have tests.
  • Commits, PRs, and documentation are searchable, so include terms that people might be searching for in your git messages.
@onion2k
onion2k / mount.js
Created January 5, 2021 12:00
Using a hook in place of componentWillMount and componentWillUnmount
useEffect(()=>{
console.log("Mounted component")
return () => {
console.log("Unmounted component")
};
});
@onion2k
onion2k / Frontend PR Checklist
Last active January 18, 2021 17:15
A checklist to go through prior to submitting a PR. A PR should be about the change that's being proposed. In order to focus on that it's good to make sure there aren't any trivial points that need to be tidied up before people can focus on the real changes that you've made. Running through this list before making the PR should eliminate most of…
Things to check before submitting a PR.
Git
[ ] Have you definitely created a new branch for this PR using `git checkout -b <branch name>`?
[ ] `git add` all your changes to the branch.
[ ] `git pull` on the branch that you've based the branch on, and then merge that branch in to your branch.
[ ] Are there conflicts? Fix them now.
Feature/Bug
docker rm -fv `docker ps -aq`
docker rmi -f `docker images -aq`