Skip to content

Instantly share code, notes, and snippets.

@mendhak
mendhak / README.md
Last active August 27, 2024 20:58
Playwright, using a proxy, with a domain being transparently mapped to another domain

With Playwright in a container, I want to have it call 'example.com', and when it does, reroute that request to some other domain, such as httpbin.org. In my case this would be a load balancer.

How it works - Playwright uses its proxy feature and calls Squid.
The Squid container has been configured to think that example.com is on the nginx container's IP address.
Nginx just uses TCP forwarding and sends the request on to httpbin.org.
Nginx doesn't use HTTP proxying because then it would need to host a certificate.

Bring up the nginx and squid

@mendhak
mendhak / README.md
Last active August 27, 2024 21:04
In docker, transparently route a domain to another domain through TCP proxying

Basically I want a container to call 'example.com' and when it does, it should go to Nginx which in turn forward the request to some-other-domain.com

This worked with curl and other basic applications.

This doesn't seem to work with Playwright though, for some reason Chrome just ignores the 'DNS' being set up here. For Playwright, I used this method with Squid.

Bring up the nginx

docker-compose up nginx
@mendhak
mendhak / add-all-aws-ca.sh
Last active July 22, 2024 18:14
Script to add all Amazon AWS CAs to the local Ubuntu trust store
certdir=/tmp/aws-certs
mkdir -p "${certdir}"
sudo mkdir -p /usr/local/share/ca-certificates/aws/
curl -sS "https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem" > ${certdir}/global-bundle.pem
awk 'split_after == 1 {n++;split_after=0} /-----END CERTIFICATE-----/ {split_after=1}{print > "aws-ca-" n+1 ".crt"}' < ${certdir}/global-bundle.pem
for cert in aws-ca-*; do
sudo mv $cert /usr/local/share/ca-certificates/aws/
@mendhak
mendhak / sidecar_cleanup.sh
Last active April 28, 2024 20:58
Script to delete XMPs and other sidecar files in a specified directory, if the base image file does not exist
#!/bin/bash
# modified from # https://stackoverflow.com/questions/48757748/removing-orphaned-sidecar-files-by-extension
# Check if directory is provided as argument
if [ $# -ne 1 ]; then
echo "Usage: $0 directory_path"
exit 1
fi
@mendhak
mendhak / .keychron_k2_pro_via_layout.md
Created March 11, 2024 19:22
Keychron K2 Pro - VIA layout, with sterling symbol and em dash

Remapped the lighting key to printscreen.

Removed the lighting related keys on layer 3

Macro for £ (fn1 + g) and — (fn1 + d)

@mendhak
mendhak / .keychron_k6_pro_via_layout.md
Last active February 27, 2024 08:44
Keychron K6 Pro - VIA layout, with sterling symbol and em dash

Remapped the rightmost keys to delete, home, end. (Instead of Home, pg up, pg down).

Remapped the lighting key to printscreen.

Removed the lighting related keys on layer 3

Macro for £ (fn1 + g) and — (fn1 + d)

@mendhak
mendhak / README.md
Created July 24, 2023 22:13
Run Llama2 on GPU
@mendhak
mendhak / Dockerfile
Last active May 9, 2023 11:21 — forked from jpallari/Dockerfile
saml2aws Docker image, updated to work with symlink and get latest version
FROM debian:stable-slim
RUN apt-get update && \
apt-get install -y ca-certificates curl && \
rm -rf /var/lib/apt/lists/*
RUN CURRENT_VERSION=$(curl -Ls https://api.github.com/repos/Versent/saml2aws/releases/latest | grep 'tag_name' | cut -d> curl -L "https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws_${CURRENT_VERSION}_linu> tar xvfz saml2aws.tar.gz && \
mv saml2aws /usr/local/bin/saml2aws && \
chmod +x /usr/local/bin/saml2aws && \
@mendhak
mendhak / example.js
Created April 23, 2021 14:11
swagger-jsdoc with JSON and YAML jsdoc examples
/**
* @openapi
* "/abc": {
* "get": {
* "description": "Welcome to swagger-jsdoc!",
* "responses": {
* "200": {
* "description": "Returns a mysterious string.",
* "content": {
* "text/xml": {
@mendhak
mendhak / example_call.py
Last active April 18, 2021 12:14
pygithub rate limit Python decorator
@rate_limited_retry()
def get_search_issues(gh, author, type):
return gh.search_issues('', author=author, type=type)