Skip to content

Instantly share code, notes, and snippets.

@thetrevorharmon
thetrevorharmon / example-query.js
Last active December 13, 2023 23:43
Query JSON with S3 Select in Node.js
// See tth.im/s3json for a full explanation of this code
const AWS = require('aws-sdk');
const S3 = new AWS.S3();
exports.handler = async (_, context) => {
try {
const query = 'SELECT * FROM s3object[*].results[*] r;';
// test query is against data from https://swapi.co/api/planets/?page=2
@thetrevorharmon
thetrevorharmon / install-apple-font-tools.sh
Created June 19, 2018 17:36
These commands help you install the Apple Font Tools, since their installer doesn't work on newer versions of macOS.
# Mount the font tools dmg as a volume on your Mac
hdiutil attach ~/Downloads/osxfonttools.dmg
# Navigate into the volume and copy
# the main .pkg file somewhere locally
# so you can manipulate it
cd /Volumes/OS\ X\ Font\ Tools/
pkgutil --expand OS\ X\ Font\ Tools.pkg ~/fontTools && cd ~/fontTools
# If you ls, here's what's in the file
@thetrevorharmon
thetrevorharmon / example-form.tsx
Last active April 5, 2021 19:30
Gatsby Mailchimp Signup Form
import addToMailchimp from 'gatsby-plugin-mailchimp';
import React, { useState } from 'react';
import * as styles from './EmailListForm.module.scss';
const EmailListForm: React.FunctionComponent<{}> = () => {
const [email, setEmail] = useState('');
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
@thetrevorharmon
thetrevorharmon / Helmet.tsx
Created January 10, 2019 19:42
A wrapper around react-helmet that makes use of StaticQuery from Gatsby.
import { graphql, StaticQuery } from 'gatsby';
import * as React from 'react';
import { Helmet as ReactHelmet } from 'react-helmet';
interface HelmetProps {
pageTitle?: string;
}
interface HelmetDataProps extends HelmetProps {
data: {
@thetrevorharmon
thetrevorharmon / StaticQuery-and-typescript.tsx
Created November 29, 2018 21:15
An example of how to use Gatsby's StaticQuery with Typescript
import { graphql, StaticQuery } from 'gatsby';
import * as React from 'react';
interface HeaderProps {
className: string;
}
interface HeaderPropsWithData extends HeaderProps {
data: {
site: {
@thetrevorharmon
thetrevorharmon / index.html.slim
Created February 7, 2018 22:19
Rails Scaffold with Slim
p#notice #{notice}
h1 <%= plural_table_name.titleize %>
table
thead
tr
<% attributes.reject(&:password_digest?).each do |attribute| -%>
th <%= attribute.human_name %>
<% end -%>
th colspan="3"
@thetrevorharmon
thetrevorharmon / index.html.erb
Created February 7, 2018 22:01
Default Rails Scaffold
<p id="notice"><%%= notice %></p>
<h1><%= plural_table_name.titleize %></h1>
<table>
<thead>
<tr>
<% attributes.reject(&:password_digest?).each do |attribute| -%>
<th><%= attribute.human_name %></th>
<% end -%>