Skip to content

Instantly share code, notes, and snippets.

View revmischa's full-sized avatar
🇺🇦

Mischa Spiegelmock revmischa

🇺🇦
View GitHub Profile
@revmischa
revmischa / gpio_button_hue.rs
Created September 30, 2024 05:30
Rust GPIO controller for Hue bridge
use gpio_cdev::{Chip, LineRequestFlags};
use reqwest::blocking::Client;
use serde_json::json;
use std::thread::sleep;
use std::time::{Duration, Instant};
// Hue API base URL and credentials
const HUE_API_URL: &str = "http://192.168.0.243/api/c7Gjkq902f8j12g10AfgG39GBj8/lights/5/state";
// Function to send a request to the Hue API to change bulb color
@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 / 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 / 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 / prismaLayer.ts
Created March 24, 2022 13:31
Prisma CDK lambda layer
import { Construct } from "constructs"
import { Code, LayerVersion, LayerVersionProps } from "aws-cdk-lib/aws-lambda"
import { AssetHashType, IgnoreMode } from "aws-cdk-lib"
import crypto from "crypto"
import path from "path"
import { getProjectRoot } from "./paths"
import { DEFAULT_RUNTIME } from "../stacks"
// deps to npm install to the layer
const PRISMA_DEPS = ["prisma", "@prisma/migrate", "@prisma/sdk", "@prisma/client"]
@revmischa
revmischa / appSyncClient.ts
Last active January 11, 2022 14:36
AWS AppSync Call From Lambda - using the AWS NodeJS SDK v3
/*
- Enable IAM authentication
- Grant IAM permission to lambda function
*/
import { HttpRequest } from "@aws-sdk/protocol-http"
import { parseUrl } from "@aws-sdk/url-parser"
import { Response, got, RequestError } from "got"
import { GraphQLResponse } from "graphql-request/dist/types"
import { signHttpRequest } from "./signedAwsRequest"
@revmischa
revmischa / readme.spec.ts
Created May 16, 2021 11:53
Unit test that tries to compile each code block in the README.md
import { createProjectSync, ts } from "@ts-morph/bootstrap"
import * as fs from "fs"
import * as path from "path"
import { default as SimpleMarkdown } from "simple-markdown"
describe("README examples", () => {
const readmePath = path.join(__dirname, "..", "..", "README.md")
const readmeContents = fs.readFileSync(readmePath)
// extract examples
@revmischa
revmischa / latynka.md
Last active May 8, 2021 20:21
Latínka Mishí

Ukrainian Latínka Amerikanskiy

A proposal to make life easy for Anglo/Romantic/Germanic speakers.

Latin Cyrillic Comment
í и Easy to write on mac
j дж Like Jesus would want
y й Fuck a "j" for this sound
v в Fuck using "w" for this