Skip to content

Instantly share code, notes, and snippets.

Avatar
💥
Boom!

Ian Langworth ☠ statico

💥
Boom!
View GitHub Profile
@statico
statico / index.js
Last active May 13, 2021
simple AWS Lambda -> Firehose -> JSON record -> S3
View index.js
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 Apr 23, 2021
useOneSignal hook for OneSignal and Next.js with SSR
View useOneSignal.ts
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 Apr 17, 2021
Simple AWS ECS status update notifications to Slack webhook
View index.js
/*
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 Apr 27, 2021
Purple Air Sensor Plugin for BitBar
View purple-air-aqi.15m.sh
#!/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 Mar 9, 2020
Single server prototyping with docker-compose + nginx
View Dockerfile
# 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 Mar 4, 2020
TypeScript + Apollo monorepo config
View .dockerignore
.DS_Store
.env
.vscode
Dockerfile
docker-compose.yml
frontend/.next
frontned/out/
node_modules
npm-debug.log*
yarn-debug.log*
@statico
statico / google-hire-to-csv.js
Last active Mar 17, 2021
Google Hire data export to useful CSV
View google-hire-to-csv.js
// This is free and unencumbered software released into the public domain.
const csv = require('fast-csv')
const dir = process.argv[2]
if (!dir) {
throw new Error('usage: export.js <export-dir>')
}
// Raw data from Google Hire export
@statico
statico / 00_statico.link_README.md
Last active Feb 18, 2021
Ian's Personal Short Link Bookmark Service
View 00_statico.link_README.md