Skip to content

Instantly share code, notes, and snippets.

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
@ezekg
ezekg / README.md
Created May 4, 2023 14:49 — forked from ascendbruce/README.md
Use macOS-style shortcuts in Windows

Use macOS-style shortcuts in Windows / keyboard mappings using a Mac keyboard on Windows

Make Windows PC's shortcut act like macOS (Mac OS X) (using AutoHotkey (ahk) script)

With this AutoHotKey script, you can use most macOS style shortcuts (eg, cmd+c, cmd+v, ...) on Windows with a standard PC keyboard.

There is a new, alternative project that does similar things and more, check it out at https://github.com/stevenilsen123/mac-keyboard-behavior-in-windows

How does it work

@ezekg
ezekg / keygen.js
Created March 13, 2023 15:34
How to verify a signed and encrypted license file using Node.js (see https://keygen.sh)
import * as crypto from 'crypto'
const PUBLIC_KEY = 'MCowBQYDK2VwAyEA6GAeSLaTg7pSAkX9B5cemD0G0ixCV8/YIwRgFHnO54g='
const LICENSE_KEY = '988214-879010-F1185E-B37E91-E53AF5-V3'
const LICENSE_FILE = `-----BEGIN LICENSE FILE-----
eyJlbmMiOiJXV0tacURadUtaMlVHcFZ4WDdabnJWL2VwbnpsemxjWnU4WXo4
TlMzTEk2S25DL3RiUVhQRkQ3N2FOSWRCY1IvK2ZSYU5BZjdrZEVneGhidFA3
b1diTTBlZGI1dFhxVHNIaFZSKzBZcUhqUXpNT2UxOGVuT3ROb29reW9PWUFx
bGJHMFNpb0QzbFc2T2lvTUFjZEwxa1d3MGd5OXBrV09lR05xV3o5T0tHaXZT
UWhOcHZpT005MmorQW1nSjNjMGVDL0dyNmh1ZzJrbVJFSHF6UlVPNUN3aTM3
@ezekg
ezekg / readme.md
Created November 10, 2022 13:41 — forked from jeremywall/readme.md
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 / cursor_pagination.rb
Last active August 17, 2022 14:41
Proof of concept cursor pagination in Rails, with support for UUID primary keys.
page_dir = :desc
page_model = Post.reorder(created_at: page_dir)
page_cursor = page_model.first.id
page_size = 3
page_num = 0
loop do
page_num += 1
page = page_model.where.not(id: page_cursor)
.where(
@ezekg
ezekg / main.js
Last active July 7, 2022 22:08
How to add license key validation and automatic updates to an Electron app (more here: https://github.com/keygen-sh/example-electron-license-activation)
// Use electron-builder's Keygen integration for automatic updates
const { autoUpdater } = require('electron-updater')
const { ipcMain } = require('electron')
// Listen for a signal from renderer to start auto-updates
ipcMain.on('license:valid', async (_event, license) => {
// Pass in a license key to authenticate with the API
autoUpdater.addAuthHeader(`License ${license.attributes.key}`)
// Check for updates
@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 / Main.java
Last active March 31, 2022 21:02
How to verify a signed license key using Java, Ed25519 and the org.bouncycastle/bcprov-jdk15on-1.70 package. See: https://keygen.sh
import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters;
import org.bouncycastle.crypto.signers.Ed25519Signer;
import org.bouncycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.util.Base64;
class Main {
public static void main(String args[]) {
String licenseKey = "key/eyJhY2NvdW50Ijp7ImlkIjoiMWZkZGNlYzgtOGRkMy00ZDhkLTliMTYtMjE1Y2FjMGY5YjUyIn0sInByb2R1Y3QiOnsiaWQiOiIxZjA4NmVjOS1hOTQzLTQ2ZWEtOWRhNC1lNjJjMjE4MGMyZjQifSwicG9saWN5Ijp7ImlkIjoiMjlkOWQ4ZDMtYmYxZC00NGQxLWExYjktODIwNDQwZDQyMmZmIiwiZHVyYXRpb24iOm51bGx9LCJ1c2VyIjpudWxsLCJsaWNlbnNlIjp7ImlkIjoiZjNkNjU3ZGUtMmI1MC00YWRmLTg2N2ItZWYwM2RjODZhM2ZlIiwiY3JlYXRlZCI6IjIwMjEtMTAtMTRUMTU6MjA6MzIuNjcwWiIsImV4cGlyeSI6IjIwMjEtMTAtMTVUMDA6MDA6MDAuMDAwWiJ9fQ==.Z_fDBaVqmBxHWkzi_TCPWGOrE0rItN_xEFdc8TtR0ahB-Gx84S6r4pXPuTxeIREtLCVJt3lcFy_WuCNeCOFRAA==";
String publicKey = "e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788";
@ezekg
ezekg / license_key_validation.py
Created February 7, 2022 15:32
An example of validing a license key using Python 3's standard library
from urllib.request import Request, urlopen
import json
import sys
req = Request(
'https://api.keygen.sh/v1/accounts/demo/licenses/actions/validate-key',
method='POST',
data=json.dumps({
'meta': {
'key': 'C1B6DE-39A6E3-DE1529-8559A0-4AF593-V3',
@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