Skip to content

Instantly share code, notes, and snippets.

View DSchau's full-sized avatar

Dustin Schau DSchau

View GitHub Profile
@DSchau
DSchau / gatsby-node-bad.js
Created August 19, 2019 16:13
Gatsby Node anti-pattern
/*
* This is bad -- it will not "hot reload" with changes
* and leads to confusing bugs
*/
exports.createPages = async function createPages({ actions, graphql }) {
const { data } = await graphql(`
{
allMarkdownRemark {
nodes {
frontmatter {
@DSchau
DSchau / network-tips.md
Last active September 1, 2020 02:21
Ubuntu + HTPC Setup stuff
  1. Hold SHIFT at boot to enter recovery mode
  2. Select Ubuntu -> Recovery Mode
  3. Root
  4. mount -o rw,remount /
  5. Now edit etc/network/interfaces with correct gateway

(Note also, consider adding DHCP to /etc/network/interfaces) to test and then reset /etc/network/interfaces

iface ens160 inet dhcp
@DSchau
DSchau / gatsby-ssr.js
Created August 2, 2019 00:01
gatsby-remark-timestamps
/*
* you will probably also want to do something like gatsby-remark-autolink-headers
* https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-autolink-headers/src/gatsby-ssr.js
*/
@DSchau
DSchau / responsive-iframe.js
Created July 26, 2019 18:11
A responsive iFrame for React
import React from "react"
export default function IFrame({ src, height, title, width, ...rest }) {
return (
<div
className={`gatsby-resp-iframe-wrapper`}
css={{
paddingBottom: `${(height / width) * 100}%`,
position: `relative`,
height: 0,
@DSchau
DSchau / gatsby-node.js
Created July 17, 2019 18:46
Webhook Data from Gatsby Cloud
exports.sourceNodes = async function sourceNodes({ actions, webhookBody }) {
/*
* Note: this is the webhook body that is passed from
* your CMS -> Gatsby Preview -> this function
* It will be a JS object, and you can use this data to "get consistent"
* with the remote CMS state
* Note: if you have a structure for deletes/creates/updates use it here!
*/
if (webhookBody && webhookBody.updates) {
await Promise.all(
@DSchau
DSchau / plex.js
Created July 9, 2019 15:52
Get all Plex User Emails
async function getAllUsers() {
const delay = duration => new Promise(resolve => setTimeout(resolve, duration))
const items = Array.from(document.querySelector('.friends-container').querySelectorAll('li'))
let emails = []
for (let el of items) {
if (el && el.querySelector('.edit-btn')) {
el.querySelector('.edit-btn').click()
await delay(1000)
@DSchau
DSchau / gatsby-node.js
Last active June 27, 2019 18:54
Awaiting the Cloudinary Promise
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`
})
const path = require("path")
const createPaginatedPages = require("gatsby-paginate")
const cloudinary = require("cloudinary").v2
cloudinary.config({
cloud_name: `${process.env.CLOUDINARY_NAME}`,
@DSchau
DSchau / gatsby-node.js
Created June 20, 2019 19:48
Example using execa in onPreBootstrap
const execa = require('execa')
exports.onPreBootstrap = () => {
return execa('npm', ['run', 'compile'])
}
@DSchau
DSchau / index.js
Last active January 16, 2022 07:02
Higher Order Components + Gatsby Sitting In a Tree
import React from "react"
import { Link, graphql } from "gatsby"
import Layout from "../components/layout"
import Image from "../components/image"
import SEO from "../components/seo"
const withAuthentication = Page => {
return class extends React.Component {
state = {
title
Gatsby and GraphQL: Sitting in a Tree K-I-S-S-I-N-G

Gatsby uses GraphQL — although it does not require it. In this talk, I go into the technical reasons of why gatsby uses graphql and why that is so appealing. I’ll deep dive into the innards of Gatsby to show what tools and libraries we use to make this schema as extensible and useful as possible, and reveal our vision for the future for how we envision Gatsby’s usage of GraphQL evolving. At the end, I’ll do some live coding to show how we can extend this internal schema with any data source and query it at build time (optional).