Skip to content

Instantly share code, notes, and snippets.

@ZReC
ZReC / .ts
Created June 24, 2023 11:52
Approach to combine pairs of landscape pdf pages into A4 ones, using Deno and pdf-lib. Page count will be at most half + 1.
import {
PageSizes,
PDFDocument,
PDFEmbeddedPage,
} from "https://cdn.skypack.dev/pdf-lib@1.17.1?dts";
interface FitPage {
page: PDFEmbeddedPage;
new_dims: {
width: number;
@ZReC
ZReC / crypto-aes-gcm.js
Created October 18, 2022 08:13 — forked from chrisveness/crypto-aes-gcm.js
Uses the SubtleCrypto interface of the Web Cryptography API to encrypt and decrypt text using AES-GCM (AES Galois counter mode).
/**
* Encrypts plaintext using AES-GCM with supplied password, for decryption with aesGcmDecrypt().
* (c) Chris Veness MIT Licence
*
* @param {String} plaintext - Plaintext to be encrypted.
* @param {String} password - Password to use to encrypt plaintext.
* @returns {String} Encrypted ciphertext.
*
* @example
* const ciphertext = await aesGcmEncrypt('my secret text', 'pw');
@ZReC
ZReC / gain
Created July 13, 2022 21:01 — forked from mxvin/gain
Simple Gain / Boost Volume on any website (Youtube, Vimeo, Twitch etc) video by only one click of bookmark button. Copy code below, then create new bookmark, and fill code below to location address.
javascript:var g_6z; function cI_6z(){ var ctx_6z = new AudioContext(); var el_6z = document.querySelector("video") ? document.querySelector("video") : document.querySelector("audio")? document.querySelector("audio"):alert('Media DOM not exist. Aborting.'); if (el_6z){ g_6z = ctx_6z.createGain(); g_6z.gain.value = 1; var src_6z = ctx_6z.createMediaElementSource(el_6z); src_6z.connect(g_6z).connect(ctx_6z.destination); var p = document.createElement("div"); p.innerHTML = `<div class=vpc_6z id=vpc_6z><style>.vpc_6z{float:right;width:25%;position:fixed;bottom:0;padding:20px 20px;z-index:9999999;background:#444;color:#fff}.vpc_6z-hide{position:fixed;background:#444;padding:0;width:80px;height:30px;bottom:0;z-index:999999}.vpi_6z-hide{display:none}</style><button%20onclick='d=document.getElementById("vpi_6z"),"vpi_6z"==d.getAttribute("class")?d.setAttribute("class","vpi_6z-hide"):d.setAttribute("class","vpi_6z"),c=document.getElementById("vpc_6z"),"vpc_6z"==c.getAttribute("class")?c.setAttribute("class","vpc_6z-hi
@ZReC
ZReC / output_diff.ts
Created April 20, 2022 10:03
It compares directories and outputs homonymous files bytes that aren't equal
/**
* The program compares same name files of different directories and
* outputs differences. Stops comparing if there's no bytes left in any file
*/
import { join, resolve } from "https://deno.land/std@0.134.0/path/mod.ts";
const szCHUNK = 512;
if (Deno.args.length < 2) {
throw new Error("you should provide at least two paths");
@ZReC
ZReC / roll_dice.ts
Created March 29, 2022 07:06
roll two six-sided dice a million times
// https://mathworld.wolfram.com/Dice.html
const DICE = 2;
const SIDES = 6;
const ROLLS = 1e6;
// init count
const count: { [sum: number]: number } = {};
for (let i = DICE; i <= DICE * SIDES; i++) {
count[i] = 0;
@ZReC
ZReC / bitwarden-dedup.html
Created March 13, 2022 22:27
Remove duplicate entries from an exported Bitwarden .json vault
<input type="file" accept=".json">
<a style="display: none;"></a>
<script>
/**
* The following code should remove duplicate items within a .json vault that was
* exported from Bitwarden v1.31.3 and maybe higher (needs more testing).
* Once the right .json is provided, it will prompt a dialog to save a non-formatted out.json
*
* Copyright 2022 ZReC & others