Skip to content

Instantly share code, notes, and snippets.

Avatar

Ian Langworth ☠ statico

View GitHub Profile
@statico
statico / 01-minimal-seed.ts
Created January 30, 2023 18:52
Jest + Node.js + Postgres testing pipeline
View 01-minimal-seed.ts
import { Knex } from "knex"
export async function seed(knex: Knex): Promise<void> {
// Delete order is specific because of foreign key references
await knex.delete().from("...")
await knex("users").insert(TestUsers)
...
await knex.raw("refresh materialized view ...")
@statico
statico / smallify.sh
Last active January 11, 2023 23:22
Use gifsicle to resize GIFs for Slack emoji
View smallify.sh
#!/usr/bin/env bash
set -eo pipefail
srcdir="$1"
if [ -z "$srcdir" ]; then
echo "usage: $0 <dir>"
exit 1
fi
@statico
statico / temp.glsl
Created November 27, 2016 18:14
CSS-style `background-size: cover` for an image texture in a GLSL shader
View temp.glsl
// An implementation of CSS `background-size: cover`
// using http://stackoverflow.com/a/6565988 and my own crappy math
vec2 s = uScreenSize; // Screen
vec2 i = uBGSize; // Image
float rs = s.x / s.y;
float ri = i.x / i.y;
vec2 new = rs < ri ? vec2(i.x * s.y / i.y, s.y) : vec2(s.x, i.y * s.x / i.x);
vec2 offset = (rs < ri ? vec2((new.x - s.x) / 2.0, 0.0) : vec2(0.0, (new.y - s.y) / 2.0)) / new;
vec2 uv = vTexCoord * s / new + offset;
gl_FragColor = texture2D(uBGTex, uv);
@statico
statico / gpu.cpp
Last active November 16, 2022 10:33
Trick to tell AMD and Nvidia drivers to use the most powerful GPU instead of a lower-performance (such as integrated) GPU
View gpu.cpp
#ifdef _WIN32
// Use discrete GPU by default.
extern "C" {
// http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
// http://developer.amd.com/community/blog/2015/10/02/amd-enduro-system-for-developers/
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
#endif
@statico
statico / Dockerfile
Last active November 3, 2022 15:54
Push-to-deploy architecture using AWS Fargate and GitHub Actions
View Dockerfile
# ------------------------------
# * Dependencies
FROM node:16.13.0-alpine3.14 AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
@statico
statico / useModals.tsx
Created December 19, 2021 18:26
Chakra UI await-able alert, confirm, and prompt modal dialogs
View useModals.tsx
/*
* 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 / light-off
Last active August 18, 2022 16:04
Control Logitech Litra with Raycast
View light-off
#!/usr/bin/env bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Logitech Litra Glow Light Off
# @raycast.mode silent
$HOME/bin/litra dark
@statico
statico / 00_README.md
Last active June 15, 2022 20:23
angular bug: An unhandled exception occurred: Object prototype may only be an Object or null: undefined
View 00_README.md

we have a project that’s using Node v12 and Angular 7. when i try to build the project with ng build i get An unhandled exception occurred: Object prototype may only be an Object or null: undefined

lots of people on the internet have this problem. there are a few dozen stackoverflow answers, and there are issues on both webpack and typescript the blame each other. it seems to have something to do with circular dependencies, but i’ve run madge --circular --extensions ts ./ which claims to find circular deps but it says none are found. in fact, if i delete all of the page source code other than the entry point, the error still occurs. so this seems to be a bug with the angular build system. i’ve hooked up a debugger and tried to step through the stack but i haven’t found anything useful.

a lot of people say “ok, run ng update.” well, that doesn’t seem to do anything useful. i’ve tried updating to just node v14 and v16, i’ve tried running node-check-updates to update dependencies. warping ahead to Angu

@statico
statico / angular-module-reload.html
Last active May 19, 2022 15:06
demo of hot-reloading/replacing angularjs modules
View angular-module-reload.html
<!doctype html>
<html>
<head>
<title>angular test</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js"></script>
</head>
<body>
<h3>demo of reloading/replacing angularjs modules</h3>