Skip to content

Instantly share code, notes, and snippets.

View rattrayalex's full-sized avatar

Alex Rattray rattrayalex

View GitHub Profile
@rattrayalex
rattrayalex / README.md
Last active July 6, 2021 18:18
Using Fastify with TypeScript and OpenAPI for typed requests and responses on the server and client
@rattrayalex
rattrayalex / .circleci slash config.yml
Created June 28, 2021 18:55
Running different CircleCI workflows based on environment variables created in a shell script
version: 2.1
setup: true
orbs:
continuation: circleci/continuation@0.1.2
jobs:
determine-workflow:
machine: true
@rattrayalex
rattrayalex / b2-archive-files.bash
Last active June 15, 2021 21:25
Upload a list of files and directories to b2 backblaze, and then delete them, with a single bash command
# usage:
#
# export BUCKET='my-bucket-name'
# b2-archive-files myfile mydirectory myotherfile
#
# You can find large files in a directory with "du -ahx . | sort -h".
archive() (
set -eo pipefail
@rattrayalex
rattrayalex / jsx-ternary-why-jsxexpressioncontainer.jsx
Last active May 16, 2021 17:56
Why check JSXExpressionContainer ancestor instead of JSXElement consequent for whether to use JSXMode.
const WhyShouldTheseBeDifferent = () => {
return (
<div>
If you start with this code:
{showTheThing || pleaseShowTheThing ? (
<Foo attribute="such and such stuff here" />
) : showTheOtherThing ? (
<Bar />
) : null}
@rattrayalex
rattrayalex / webhook.js
Created May 13, 2021 02:49
Changing a shopify order's location based on the shipping address of the order using order.created/order.updated webhooks
// For posterity, I'm saving/sharing some code I wrote for a shopify app I ran
// in which I had two physical warehouses: one in Maryland, and one in California.
// Each of these was its own "Location" in Shopify, and I wanted every order
// to be automatically assigned to one or the other based on the shipping address.
// I ran this webhook on Autocode: https://autocode.com/
// which makes it really easy to stand up a webhook without futzing with servers.
const Shopify = require('shopify-api-node');
const shopify = new Shopify({
@rattrayalex
rattrayalex / query.gql
Last active April 30, 2021 18:22
Postgraphile SQL Rewrite Example
query MyQuery {
films(
filter: {and: [
{title: {startsWith: "A"}},
{releaseYear: {equalTo: 2006}}
]},
first: 3
) {
nodes {
title
@rattrayalex
rattrayalex / query.gql
Last active April 21, 2021 13:09
Postgraphile Pagila gql to sql demo
query MyQuery {
actor(actorId: 10) {
firstName
lastName
filmActors {
nodes {
film {
title
description
}
@rattrayalex
rattrayalex / ideas.md
Last active April 14, 2021 14:19
PostGraphile Framework Sketches

I want something that I can share with a development team that's just focused on features and doesn't want to think about the tools at hand very much (but can deeply fine-tune where needed).

Postgraphile seems like an amazing place to start for this.

Here's what I might want to build on top of it (though ideally it'd be baked-in):

Each "table" (think pg_class) should have a single file where ~all logic around that table is contained in as declarative a format as possible.

@rattrayalex
rattrayalex / play-html5-video-on-scroll-into-view-or-click.js
Created November 22, 2020 13:25
Vanilla JS ES6 snippet to play html5 video on scroll into view or click (and pause when out of view or clicked while playing)
function debounce(callback) {
let timeout = null;
return function() {
const next = () => callback.apply(this, arguments);
cancelAnimationFrame(timeout);
timeout = requestAnimationFrame(next);
}
}
const observerOptions = {
@rattrayalex
rattrayalex / index.html
Last active November 17, 2020 02:30
Fall back to twitter's twemoji emoji when there is inadequate native emoji support (eg; on Windows)
<html>
<body>
<div class="has-emoji">Hello world! I'm a unicorn: 🦄</div>
<script>
// Stolen from Modernizr: https://github.com/Modernizr/Modernizr/blob/v3.5.0/feature-detects/emoji.js
const hasEmojiSupport = () => {
var pixelRatio = window.devicePixelRatio || 1;
var offset = 12 * pixelRatio;
var node = document.createElement('canvas');