Skip to content

Instantly share code, notes, and snippets.

import { type UseHook } form "./useHookShared";
import { useHookOld } from "./useHookOld";
import { useHookNew } from "./useHookNew";
type MyComponentProps = {
id: string;
variant?: "default" | "bold",
}
export function MyComponent(props: MyComponentProps) {
@cullylarson
cullylarson / config.ts
Last active January 30, 2024 14:23
Example configuration file
const stages = ['production', 'staging', 'development', 'test'] as const;
type Stage = typeof stages[number];
function getStage(stages: Stage[]) {
if (!stages.length) return 'production';
for (const stage of stages) {
// if any of the provided stages is production, assume we are in production
if (stage === 'production') {
@cullylarson
cullylarson / demo.ts
Last active July 1, 2022 17:36
Typescript Branding and Flavoring
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-console */
/* ************************************** */
export interface Branding<BrandT> {
_type: BrandT;
}
export type Brand<T, BrandT> = T & Branding<BrandT>;
@cullylarson
cullylarson / #styled-jsx-plugin-postcss-net.js
Last active January 20, 2021 22:24
A solution to slow transforms in styled-jsx-plugin-postcss.
// Most of this is copied from: https://github.com/wbyoung/babel-plugin-transform-postcss
const {spawnSync, spawn} = require('child_process')
const path = require('path')
const socketPath = path.join('/tmp', 'styled-jsx-plugin-postcss--' + process.pid + '.sock')
const nodeExecutable = process.argv[0]
const clientExcutable = path.join(__dirname, 'client.js')
const serverExcutable = path.join(__dirname, 'server.js')
@cullylarson
cullylarson / readme.md
Last active January 9, 2020 04:25
Client-side folder structure example
+ app
  - App.js
  - Layout.js
+ components
  - FormText.js
  - FormEmail.js
  - Card.js
  - CancelButton.js
 - Pagination.js
@cullylarson
cullylarson / site-performance-checklist.md
Created January 9, 2019 23:21
Site Performance Checklist

Site Performance Checklist

Do these things

  • Enable gzip
  • HTTP/2

Tools

  • Chrome Lighthouse Audit
@cullylarson
cullylarson / http-headers.md
Last active November 2, 2018 19:54
Headers I should probably be using
  1. Strict-Transport-Security. Ensures that all traffic, even the first request to a non-https version of the URL, will be encrypted.
  2. Referrer-Policy. Allows you to tell the browser what to set as the referrer URL when going to an external site.
@cullylarson
cullylarson / crontab
Created October 1, 2018 17:20
Database and file backup scripts
### ABOUND BACKUPS
DB_BK_CMD = /home/user/backups/site_name/do-db-backup.sh
FILE_BK_CMD = /home/user/backups/site_name/do-files-backup.sh
# backup / Every day @ 3 am
0 3 * * * $DB_BK_CMD do-daily database_name
0 3 * * * $FILE_BK_CMD do-daily /home/user/public_html
# rotate weekly / Every 7 days @ 3:30am
@cullylarson
cullylarson / Pushing to a clients git repo.md
Last active March 19, 2018 17:41
Pushing to a client's git repo

Pushing to a client's git repo

I'm a freelance programmer. Sometimes I work on projects where the client wants to occasionally see code updates in their own repo, but I don't want them to see my work schedule. If I push my dev repo, they'll see when I'm working, how many hours, etc. To solve that, I started maintaining a for-client branch that only shows weekly, squashed merges of master. Each commit is monolithic, with one commit message (it doesn't include all of the individual commit times, messages, etc. from the master branch).

Convenient k8s/Docker/gcloud Commands

Commands that are useful for doing stuff on Google Container Engine

Setup

$ gcloud config set project PROJECT_ID
$ gcloud config set compute/zone ZONE_NAME
$ gcloud container clusters list