Skip to content

Instantly share code, notes, and snippets.

@WoozyMasta
WoozyMasta / Dockerfile
Created July 12, 2022 02:49
An example of building a Python application into a self-contained statically linked binary and packaging it into a container image based on scratch
FROM docker.io/python:3.9-bullseye AS build
WORKDIR "/app"
# Install dependecies
# hadolint ignore=DL3008,DL3013
RUN set -eux && \
apt-get update; \
apt-get install --no-install-recommends -y \
python3-dev build-essential patchelf upx; \
apt-get clean; \
@brandonpapworth
brandonpapworth / README.md
Last active January 31, 2022 09:03
[WIP] TypeScript: Creating "Enums" from Tuple of String Literals

Creating Enums from Tuple of String Literals

Description

It is as it sounds: this function will create something similar to an enum (in this case, an object with a null prototype) from a tuple of string literals.

Why?

Even though native enums have some convenient benefits, they can get a little "wordy" when you wish them to work like holders of string constants.

@brandonpapworth
brandonpapworth / README.md
Last active March 8, 2021 14:20
Simple "what's-my-ip" service (think ipify) via Lambda@Edge

Simple "what's-my-ip" service

via Lambda@Edge

Usage

This will return the IPv4 or IPv6 address of the client making the GET request to the domain you specified when making the CloudFront distribution. If you add an Accept header with application/json present, it will return an json-parseable object like { "ip": "127.0.0.1" }, but if not specified or text/plain appears before application/json, it will default to text/plain and just return the IP address like 127.0.0.1 (following standard handling of Accept headers).

Shitty Directions

@brandonpapworth
brandonpapworth / README.md
Created June 3, 2020 13:57
Project: Temp Management System for AC Unit
@ajbeach2
ajbeach2 / ray_trace_postgres.sql
Last active October 11, 2019 15:10
ray_trace_postgres.sql
-- ported to postgres from https://observablehq.com/@pallada-92/sql-3d-engine
WITH RECURSIVE numbers AS (
SELECT 0 AS n UNION ALL SELECT n+1 FROM numbers WHERE n<89
),
pixels AS (
SELECT rows.n as row, cols.n as col
FROM numbers as rows CROSS JOIN numbers as cols
WHERE rows.n > 2 AND rows.n < 40 AND cols.n > -1 AND cols.n < 89
), rawRays AS (
SELECT
@Kmaschta
Kmaschta / generate-self-signed-certificate-with-custom-CA.md
Created January 9, 2019 14:43
How to generate a self-signed that is valid for your browser (by creating your custom certificate authority)

If you're using self-signed certificate for your web server on development, you might know the browser warning saying that your certificate isn't valid. If like me you had manually added an exception for this certificate error each time it showed up, this gist is for you.

Properly Configure OpenSSL with your DNS aliases

You'll have to create a self-signed certificate with a custom SubjectAltName.

  1. Find your openssl config. find /usr/lib -name openssl.cnf
@HyperBrain
HyperBrain / lifecycle-cheat-sheet.md
Last active June 7, 2024 05:17
Serverless Lifecycle Cheat Sheet

Serverless plugin author's cheat sheet

This cheat sheet provides a detailed overview of the exposed lifecycle events and available commands (and entrypoints) of the Serverless framework, that can be hooked by plugins (internal and external ones). The document is structured by the commands invoked by the user.

Lifecycle events are shown as the globally available outer events (all providers) and sub lifecycle events that are provider specific in the called order. Currently only the AWS provider is shown. If you have information about the other provider,

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@BBNicolas
BBNicolas / AuthenticaionHelper.cs
Last active December 10, 2019 20:28
Cognito register, validation and login with remember Devices enabled
using System;
using System.Security.Cryptography;
using System.Text;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Math;
using System.Globalization;
namespace cognito
{
@deanproctor
deanproctor / GzipDocument.java
Created March 2, 2017 04:00
GzipTranscoder
/*
* Copyright (c) 2016 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software