Skip to content

Instantly share code, notes, and snippets.

View statico's full-sized avatar

Ian Langworth ☠ statico

View GitHub Profile
@statico
statico / PressableWithAnimation.jsx
Created September 18, 2023 02:07
Simple Pressable with Opacity component for React Native
/**
* Why?
*
* Pressable is the newer and superior component in React Native for buttons.
* It has a built in affordance for near-misses and, most importantly, it
* doesn't respond or show an animation while the user is dragging.
*
* However, Pressable doesn't have any feedback, like TouchableOpacity. This
* simple component adds the animation you want *when* the user is actually
* committed a press. This is how, for example, the official Facebook app works.
@statico
statico / db.ts
Created September 12, 2023 23:10
Configure Sentry performance tracing because the default integration doesn't work
// Configure Sentry performance tracing because the default Postgres integration doesn't work with Knex:
// https://github.com/getsentry/sentry-javascript/blob/main/packages/tracing-internal/src/node/integrations/postgres.ts
const sentrySpans = new Map<string, Span>()
db.on("query", (query: any) => {
const span = Sentry.getActiveSpan()?.startChild({
op: "db.query",
description: query.sql,
})
if (span) sentrySpans.set(query.__knexQueryUid, span)
})
@statico
statico / pom.xml
Last active August 24, 2023 23:21
minimal maven pom.xml to download JARs in to a lib/ directory
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo</groupId>
<artifactId>bar</artifactId>
<version>0.0.1-SNAPSHOT</version>
@statico
statico / temp.glsl
Created November 27, 2016 18:14
CSS-style `background-size: cover` for an image texture in a GLSL shader
// 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 / index.mjs
Created May 28, 2023 03:11
AWS Kinesis Firehose + S3 bucket to ClickHouse import Lambda
/*global fetch*/
import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3'
const s3 = new S3Client({ region: 'us-east-2' })
export const handler = async (event, context) => {
// console.log('Received event:', JSON.stringify(event, null, 2))
const bucket = event.Records[0].s3.bucket.name
@statico
statico / cloudWatchAlarmsToSlack.js
Created January 19, 2022 21:20
Lambdas for Slack Notifications
const fetch = require('./fetch')
const RED = '#cd3131'
const YELLOW = '#e5e512'
const GREEN = '#05bc79'
const BLUE = '#2472c8'
exports.handler = async function(event, context) {
// Debugging
// console.log('event', JSON.stringify(event, null, 2))
@statico
statico / policy.json
Created April 25, 2023 22:06
Metabase Athena Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"athena:StartQueryExecution",
"athena:ListDataCatalogs",
"glue:GetTableVersions",
@statico
statico / index.mjs
Created April 17, 2023 19:33
sanity blog backup to lambda (not working because of --raw)
/*global fetch*/
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
const client = new S3Client({});
export const handler = async (event) => {
const projectId = process.env.SANITY_PROJECT_ID
const dataset = process.env.SANITY_DATASET
const token = process.env.SANITY_TOKEN
@statico
statico / 01-minimal-seed.ts
Created January 30, 2023 18:52
Jest + Node.js + Postgres testing pipeline
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
#!/usr/bin/env bash
set -eo pipefail
srcdir="$1"
if [ -z "$srcdir" ]; then
echo "usage: $0 <dir>"
exit 1
fi