Skip to content

Instantly share code, notes, and snippets.

@rattrayalex
rattrayalex / questionable-new-ternaries.js
Last active Sep 22, 2021
Questionable new ternary cases
View questionable-new-ternaries.js
// This comment looks funny… not sure what our desired behavior should be? Parens?
test ? foo
: /* comment
comment
comment
comment
A newline will be added after this comment, unfortunately – but it can be removed manually, see next statement.
*/
test ? foo
: bar
@rattrayalex
rattrayalex / .bash_profile
Last active Aug 5, 2021
Bash function to choose an open jira ticket and create a branch and empty commit for it
View .bash_profile
source "$HOME/.env"
jira-branch() (
set -eo pipefail
local jira_instance jq_template query username api_key ticket_id jira_title commit_title
username="$JIRA_USERNAME"
api_key="$JIRA_API_KEY"
jira_instance="$JIRA_INSTANCE"
@rattrayalex
rattrayalex / readme.md
Created Jul 30, 2021
Ripgrep ignore/exclude files that match a certain string
View readme.md

Say you want to search for a certain string, but exclude files which match another pattern.

PATTERN_TO_EXCLUDE="bad.+words"
DIR_TO_SEARCH=foo/bar
PATTERN_TO_FIND="good.+good"

rg $PATTERN_TO_FIND --stats $(rg $PATTERN_TO_EXCLUDE --files-without-match $DIR_TO_SEARCH)
@rattrayalex
rattrayalex / README.md
Last active Jul 6, 2021
Using Fastify with TypeScript and OpenAPI for typed requests and responses on the server and client
@rattrayalex
rattrayalex / .circleci slash config.yml
Created Jun 28, 2021
Running different CircleCI workflows based on environment variables created in a shell script
View .circleci slash config.yml
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 Jun 15, 2021
Upload a list of files and directories to b2 backblaze, and then delete them, with a single bash command
View b2-archive-files.bash
# 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 / desired-ternaries.jsx
Last active May 23, 2021
Desired Prettier formatting of (nested) ternaries
View desired-ternaries.jsx
// remain on one line if possible:
const short = isLoud() ? makeNoise() : silent();
// next, put everything after the =
const lessShort =
isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent();
// next, push the alternate to a new line at the same level of indentation:
const allNextLine =
isLoudReallyReallyReallyReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud()
@rattrayalex
rattrayalex / jsx-ternary-why-jsxexpressioncontainer.jsx
Last active May 16, 2021
Why check JSXExpressionContainer ancestor instead of JSXElement consequent for whether to use JSXMode.
View jsx-ternary-why-jsxexpressioncontainer.jsx
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
Changing a shopify order's location based on the shipping address of the order using order.created/order.updated webhooks
View webhook.js
// 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 Apr 30, 2021
Postgraphile SQL Rewrite Example
View query.gql
query MyQuery {
films(
filter: {and: [
{title: {startsWith: "A"}},
{releaseYear: {equalTo: 2006}}
]},
first: 3
) {
nodes {
title