Skip to content

Instantly share code, notes, and snippets.

@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 / WordpressAsDependency.md
Last active July 13, 2021 08:37
Installing Wordpress as a dependency

Wordpress as a Dependency

How to install Wordpress as a dependency in your project, without including the WP install in version control.

Rationale

In the spirit of The Twelve Factor App, we want to "explicitly declare and isolate dependencies". Wordpress doesn't really promote this idea out of the box, so we have jump through a few hoops to do it. This document describes a simple method to include Wordpress as a dependency in this way.

General Idea

@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).

@cullylarson
cullylarson / vagrant-local-email.sh
Last active March 14, 2017 11:20
Catch all emails sent on a dev box and deliver them to the 'vagrant' user's mailbox
#
# Many apps send email. In a dev environment, we generally don't want those emails
# to get out. However, we still want our app to think it's sending mail and we want
# to verify that emails are being sent, with the correct content and to the correct
# recipients.
#
# This setup solves that problem by delivering all out-bound emails to the local
# "vagrant" user's mailbox. You can then read the emails using the "mutt" command.
#
# Most if this is copied from: