Skip to content

Instantly share code, notes, and snippets.

View statico's full-sized avatar

Ian Langworth ☠ statico

View GitHub Profile
@statico
statico / useModals.tsx
Created December 19, 2021 18:26
Chakra UI await-able alert, confirm, and prompt modal dialogs
/*
* Usage:
* const { alert, confirm, prompt } = useModals()
* alert("Hey!") // awaitable too
* if (await confirm("Are you sure?")) ...
* const result = await prompt("Enter a URL", "http://")
*/
import React, {
createContext,
@statico
statico / index.js
Created October 7, 2021 18:27
GitHub Project Card Sorter using GraphQL API
const { graphql } = require("@octokit/graphql")
const REPO_OWNER = "x"
const REPO_NAME = "y"
const PROJECT_NUMBER = 2
const COLUMN_TO_SORT = /To Do/
const api = graphql.defaults({
headers: {
authorization: `token ${process.env.GITHUB_TOKEN}`,
@statico
statico / index.js
Last active May 13, 2021 18:04
simple AWS Lambda -> Firehose -> JSON record -> S3
import { FirehoseClient, PutRecordCommand } from "@aws-sdk/client-firehose"
const streamName = process.env.AWS_FIREHOSE_LOG_EVENT_STREAM
const client = new FirehoseClient({})
export const logEvent = (type: string, data: Object) => {
try {
const record = Buffer.from(
JSON.stringify({
@statico
statico / useOneSignal.ts
Last active April 23, 2021 16:56
useOneSignal hook for OneSignal and Next.js with SSR
import getConfig from "next/config"
// Add publicRuntimeConfig: { oneSignalAppId: ... } to next.config.js
const { publicRuntimeConfig } = getConfig()
export const useOneSignal = (externalUserId?: string): void => {
// react-onsignal tries to use a global `document` variable, so we can only
// use it in the client side. Luckily this method doesn't trigger any "wrong
// number of hooks" errors either.
if (!process.browser) return
@statico
statico / index.js
Last active October 18, 2023 20:48
Simple AWS ECS status update notifications to Slack webhook
/*
Want to know when ECS events happen in Slack? Try this.
(1) Create a new Slack app with an incoming webhook, save the webhook URL
(2) Create an SNS topic called something like ECSEvents
(3) Create a CloudWatch Rule that publishes all ECS events to the topic
(4) Create a Node.js Lambda that is triggered by the SNS topic
(5) Add a WEBHOOK_URL environment variable to the Lambda with the webhook URL
(6) Paste this code into index.js
(7) Paste the contents of https://unpkg.com/node-fetch/lib/index.js into fetch.js
(8) Deploy and enjoy
@statico
statico / purple-air-aqi.15m.sh
Last active April 27, 2021 17:36
Purple Air Sensor Plugin for BitBar
#!/usr/bin/env bash
#
# <bitbar.title>Purple Air PM2.5 AQI</bitbar.title>
# <bitbar.dependencies>bash,jq,node</bitbar.dependencies>
#
# Derived from https://github.com/matryer/bitbar-plugins/blob/master/Weather/aqi.15m.sh by Chongyu Yuan
COLORS=("#0ed812" "#ffde33" "#ff9933" "#cc0033" "#660099" "#7e0023" "#404040")
PURPLE_AIR_SENSOR_ID=5220
@statico
statico / Dockerfile
Created March 9, 2020 22:28
Single server prototyping with docker-compose + nginx
# Remember that additional env vars can be in a .env, which docker-compose
# uses when building the image.
FROM node:12.9.0-alpine AS base
VOLUME /usr/local/share/.cache/yarn
COPY ./ /app/
WORKDIR /app/
RUN npm install --silent --global yarn
RUN yarn install --pure-lockfile --non-interactive
@statico
statico / .dockerignore
Created March 4, 2020 01:27
TypeScript + Apollo monorepo config
.DS_Store
.env
.vscode
Dockerfile
docker-compose.yml
frontend/.next
frontned/out/
node_modules
npm-debug.log*
yarn-debug.log*