Skip to content

Instantly share code, notes, and snippets.

View revmischa's full-sized avatar
🇺🇦

Mischa Spiegelmock revmischa

🇺🇦
View GitHub Profile
@revmischa
revmischa / zodMiddleware.ts
Created January 5, 2024 00:47
Zod + middy + AWS lambda API Gateway
import middy, { MiddlewareObj } from '@middy/core'
import httpErrorHandler from '@middy/http-error-handler'
import httpHeaderNormalizer from '@middy/http-header-normalizer'
import httpJsonBodyParser from '@middy/http-json-body-parser'
import { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2, Handler } from 'aws-lambda'
import { zodValidator } from 'middy-zod-validator'
import { ZodSchema, z, infer as ZInfer } from 'zod'
import { isHttpError } from 'http-errors'
@revmischa
revmischa / appsyncDirectives.graphql
Last active June 13, 2023 17:57 — forked from davidimoore/_aws.graphql
AWS AppSync GraphQL scalars and directives
# AWS AppSync GQL directives
#
## Scalars come from here:
# https://raw.githubusercontent.com/aws-amplify/amplify-cli/master/packages/amplify-graphql-types-generator/awsAppSyncDirectives.graphql
# https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html
#
## Directives came from a GitHub issue here:
# https://github.com/apollographql/eslint-plugin-graphql/issues/263
## And comparing with the JSON output of
# https://docs.aws.amazon.com/appsync/latest/APIReference/API_GetIntrospectionSchema.html
@revmischa
revmischa / pglisten.c
Last active February 23, 2023 19:52
Example postgresql asynchronous connection with LISTEN handler
#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
// channel to LISTEN on
const char *listenChannel = "foo";
@revmischa
revmischa / awsecsdeploy-stack.ts
Created November 20, 2022 18:06 — forked from windlessuser/awsecsdeploy-stack.ts
Deploys Mastodon using AWS CDK v2
import cdk = require("aws-cdk-lib");
import ec2 = require("aws-cdk-lib/aws-ec2");
import elastic = require("aws-cdk-lib/aws-elasticache");
import rds = require("aws-cdk-lib/aws-rds");
import es = require("aws-cdk-lib/aws-elasticsearch");
import ecs = require("aws-cdk-lib/aws-ecs");
import s3 = require("aws-cdk-lib/aws-s3");
import elbv2 = require("aws-cdk-lib/aws-elasticloadbalancingv2");
import route53 = require("aws-cdk-lib/aws-route53");
import certificateManager = require("aws-cdk-lib/aws-certificatemanager");
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import * as sst from '@serverless-stack/resources';
import { Function, getStack } from '@serverless-stack/resources';
import { Match, Template } from 'aws-cdk-lib/assertions';
import { useBaseInfra } from 'stacks';
import { test } from 'vitest';
import { Functions } from './functions';
function TestStack({ stack }: sst.StackContext) {
@revmischa
revmischa / build-video-server.sh
Created December 16, 2010 00:25
Build and install libx264, libav and rtmpd
#!/usr/bin/env bash
# This script fetches and builds libx264, libav, rtmpd and their dependencies.
# you may have to add /usr/local/lib to /etc/ld.so.conf
# BASEDIR = build directory (default current dir)
# PREFIX = install directory (default /usr/local)
if [ -z "$BASEDIR" ]; then
BASEDIR=`pwd`
fi
@revmischa
revmischa / cloudformationEnv.ts
Created August 18, 2022 18:22
Get cloudformation exports or outputs at runtime
/**
* CloudFormation exports. Unique per-region.
*/
export enum StackExports {
GREMLIN_PORT = "GremlinPort",
GREMLIN_ENDPOINT = "GremlinEndpoint"
}
/**
@revmischa
revmischa / ansi2unicode.pl
Created November 6, 2012 06:59
Convert raw ANSI to IRC or HTML
#!/usr/bin/perl
# ansi2unicode.pl
# 4/18/2007
#
# convert an ANSI file to unicode, suitable for display in irssi/mirc or html
# usage: ansi2unicode.pl inputfile [-tc] [-o outputmode] [outputfile]
# -t = terminal output, no color
# -o = output mode, currently only html and irc supported, default is irc
# outputfile = filename to output to if html specified
@revmischa
revmischa / install-plenv.sh
Last active July 12, 2022 02:25
Set up plenv, install perl, cpanm, carton, set up environment
#!/bin/bash
# installs plenv, perl, carton, cpanminus, sets up environment in .bash_profile
# from https://github.com/tokuhirom/plenv#readme
PLENV_PERL_VERSION='5.18.1'
if [[ -n "$PERL_MB_OPT" ]]; then
echo "You must unset your local::lib environment variables first"
@revmischa
revmischa / DockerfileLambdaChromium
Created April 1, 2020 18:45
Build chromium on amazon linux 2
FROM lambci/lambda:build-python3.8
# ref: https://chromium.googlesource.com/chromium/src.git/+refs
ARG VERSION
ENV VERSION ${VERSION:-master}
LABEL maintainer="Mischa Spiegelmock <me@mish.dev>"
LABEL chromium="${VERSION}"
WORKDIR /