Skip to content

Instantly share code, notes, and snippets.

@jeremywall
jeremywall / readme.md
Last active October 5, 2023 19:04
R2, CORS, Presigned Put Object URLs, and uploading directly from browser side JavaScript

First and foremost you need to set the CORS configuration for your bucket. I'm a Java developer so here's the code I wrote using the AWS Java SDK v2 to define the CORS configuration for my R2 bucket. Alternatively you can also edit your bucket CORS configuration using Postman following the tutorial at https://kian.org.uk/configuring-cors-on-cloudflare-r2/

// update the config section here with your information first
String bucketName = "YOUR_BUCKET";
String accessKeyId = "YOUR_R2_ACCESS_KEY_ID";
String secretAccessKey = "YOUR_R2_SECRET_ACCESS_KEY";
String accountId = "YOUR_ACCOUNT_ID";
URI uri = new URI("https://" + accountId + ".r2.cloudflarestorage.com");
@ezekg
ezekg / main.js
Created July 6, 2022 16:57
How to quickly parse a parameterized HTTP header, such as Cookie or Signature, using Node.
const header = `keyid="bf9b523f-dd65-48a2-9512-fb66ba6c3714",
algorithm="ed25519",
signature="KhgcM+Ywv+DnQj4gE+DqWfNTM2TG5wfRuFQZ/zW48ValZuCHEu1h95Uyldqe7I85sS/QliCiRAF5QfW8ZN2vAw==",
headers="(request-target) host date digest"`
// Parse the parameterized header into an object
const params = header.split(/,\s*/g)
.map(keyvalue => keyvalue.match(/(?<key>[^=]+)="(?<value>[^"]+)"/i))
.map(matches => matches.groups)
.reduce(
@ezekg
ezekg / _README.md
Last active January 27, 2022 16:40
How to verify a signed license key using C#, .NET 6, RSA PKCS1 v1.5 and System.Security.Cryptography. See: https://keygen.sh

Setup dependencies

dotnet --version
# => 6.0.101

Run the example

@ezekg
ezekg / _README.md
Last active August 19, 2023 10:30
How to verify a signed license key using C#, Ed25519 and the NSEC crypto package. See: https://keygen.sh

Setup dependencies

dotnet --version
# => 6.0.101

dotnet add package NSec.Cryptography

Run the example

@sploders101
sploders101 / updateProxy.ts
Last active August 6, 2021 13:58
Example update proxy for electron
import http from "http";
import https from "https";
import {
AddressInfo,
} from "net";
import { URL } from "url";
const updateServer = "https://updates.yourserver.com/path/to/update/dir/without/trailing/slash";
const updateAuth = `Basic ${Buffer.from("username:password").toString("base64")}`
@stouset
stouset / LICENSE
Last active May 27, 2022 16:46
Best-practices based API key authentication
Copyright © 2021 Stephen Touset <stephen@touset.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SO

This recipe is a work in progress and has never been run as-is.

  • timeouts are in ms
  • lock timeout: in postgres, when a statement that wants a restrictive lock waits on another lock, other statements that want locks can't jump the queue. so even though the statement that is waiting might only take a very short amount of time, when it starts running, while it is waiting no other statements can begin. So we set the lock timeout pretty low and retry if we don't get it.
  • statement timeout: we set a short statement timeout before statements which do lock and which we expect to take a short amount of time, just in case something about our assumptions/understanding is wrong and the statement ends up taking a long time. if this happens the statement will bail early without causing harm, and we can investigate what is wrong with
@IanColdwater
IanColdwater / twittermute.txt
Last active April 22, 2024 17:26
Here are some terms to mute on Twitter to clean your timeline up a bit.
Mute these words in your settings here: https://twitter.com/settings/muted_keywords
ActivityTweet
generic_activity_highlights
generic_activity_momentsbreaking
RankedOrganicTweet
suggest_activity
suggest_activity_feed
suggest_activity_highlights
suggest_activity_tweet
@slykar
slykar / docker-compose-hackintosh.md
Last active May 7, 2024 13:53
Docker and Docker Compose on AMD OSX Hackintosh via Docker Machine

Introduction

Docker.app will complain about incompatible processor, so we will use Docker Machine.

Instalation

Download Docker for Mac (Docker.app). It contains some binaries that are necessary.

brew install virtualbox docker-machine
@Inndy
Inndy / WSL-Clipboard.sh
Created July 18, 2019 18:13
Access system clipboard within WSL
# put these lines into your ~/.bashrc
alias paste="powershell.exe -Command Get-Clipboard"
alias copy="powershell.exe -Command 'Set-Clipboard([Console]::In.ReadToEnd())'"