Skip to content

Instantly share code, notes, and snippets.

View patrickfav's full-sized avatar
🐿️
Nam nam nam

Patrick Favre patrickfav

🐿️
Nam nam nam
View GitHub Profile
@patrickfav
patrickfav / plugin-so-turndown.ts
Last active May 27, 2023 16:07
A Turndown Plugin parsing Stack Overflow HTML answers; converts it to GitHub-Flavored-Markdown (GFM) with correct language. Turndown is a JS Markdown Parser
import TurndownService from "turndown";
export const stackOverflowHighlightedCodeBlock = function (service: TurndownService): void {
const highlightRegExp = /lang-([a-z0-9]+)/
service.addRule('stackOverflowHighlightedCodeBlock', {
filter: function (node: HTMLElement, options: Options): boolean | null {
const firstChild = node.firstChild
return (
node.nodeName === 'PRE' &&
@patrickfav
patrickfav / AesCbcExample.java
Last active June 30, 2023 03:51
Companion code to my article about AES+CBC with Encrypt-then-MAC.
package at.favre.lib.armadillo;
import org.junit.Test;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.Arrays;
@patrickfav
patrickfav / example_jekyll.md
Last active January 7, 2024 19:39
A Liquid Filter for obfuscating an Email Address (can be used with Jekyll aswell).

In Jekyll set a variable for the mail, e.g. in the _config.yml

email: name@mail.com

then use it in your page

Reach me under:	{{ site.email | mailObfuscate }}

which will generate the following HTML

@patrickfav
patrickfav / AesGcmTest.java
Last active February 27, 2024 11:32
Java Authenticated Encryption with AES and GCM.
package at.favre.lib.bytes.otherPackage;
import org.junit.Test;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;