Skip to content

Instantly share code, notes, and snippets.

View pkcpkc's full-sized avatar

Paul Hackenberger pkcpkc

View GitHub Profile
@pkcpkc
pkcpkc / index.js
Last active February 12, 2024 09:59
decode-ios-receipt
// see https://www.npmjs.com/package/node-apple-receipt-verify#configoptions-object
// https://medium.com/axel-springer-tech/debugging-and-reading-apple-receipts-2e47f9793f74
const params = {
"-p": {
"name": "environment",
"default": ['sandbox'],
"set": ['production']
},
"-ie": {
"name": "ignoreExpired",
@pkcpkc
pkcpkc / intersection.liquid
Created October 24, 2023 10:10
liquid-intersection
{% comment %}Input from article{% endcomment %}
{% assign articleTopics = "t3,t4,t5" | split: "," %}
{% assign articleAuthors = "a1,a2" | split: "," %}
{% comment %}This will come from user.topics, user.authors{% endcomment %}
{% assign userTopics = "t1,t3,t5" | split: "," %}
{% assign userAuthors = "a2,a4" | split: "," %}
{% for userTopic in userTopics %}
{% if articleTopics contains userTopic %}
@pkcpkc
pkcpkc / disjunct.js
Created October 24, 2023 07:31
Split in disjunct sub-requests
Array.prototype.intersection = function (otherArray) {
return this.filter(element => otherArray.includes(element));
};
Array.prototype.subArray = function (start, end) {
return this.filter(function (element, index) { return index >= start && index < end });
}
Array.prototype.includesAny = function (otherArray) {
return this.intersection(otherArray).length > 0;
@pkcpkc
pkcpkc / tech-radar.html
Last active May 7, 2021 10:22
JavaScript: Tech Radar based on Zalandos code https://opensource.zalando.com/tech-radar/
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Tech Radar</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://opensource.zalando.com/tech-radar/release/radar-0.5.js"></script>
</head>
<body>
@pkcpkc
pkcpkc / inline-images.sh
Last active August 9, 2019 19:06
Replace all local images references in HTML with base64 inline data, e.g. for HTML emails
#!/bin/bash
# Searches for <img src="localImage" alt="altText"/> in index.html and replaces with:
# <img src="data:image/png;base64,..." alt="altText"/>
# writes output to build/index.html
mkdir -p build
# awk is really awkward: does not accept regexp groups :(
# I'll keep the () anyways for my mental health!
@pkcpkc
pkcpkc / index.html
Last active March 29, 2019 17:43
HTML/UML: Default setup for mermaidJS https://mermaidjs.github.io/
<html>
<head>
<!-- https://mermaidjs.github.io/sequenceDiagram.html -->
<script>
function generateTableOfContents(maxHeaderLevel = 3, styleItem = function (text, level, itemAnchor) {
var spaces = "&nbsp;".repeat(Math.max(0, (level - 1)) * 3);
var tocEntry = spaces + '• <a href="#' + itemAnchor + '">' + text + '</a><br/>';
return tocEntry;
}) {
@pkcpkc
pkcpkc / tableOfContents.js
Last active December 22, 2023 20:27
JavaScript: HTML heading Table of Contents: Generate a navigatable, stylable table of contents based on the heading structure of an html document
/*
Collect headers (h1, h2, ..., hx) from html and generates navigatable, stylable table of contents.
@param maxHeaderLevel int Define header level depth, defaults to 3.
@param styleItem function Function that accepts text:string, level:int and itemAnchor:string to style toc entry, default renderer is set already (check source for usage).
@return string HTML table of contents
*/
function generateTableOfContents(maxHeaderLevel = 3, styleItem = function (text, level, itemAnchor) {
var spaces = "&nbsp;".repeat(Math.max(0, (level - 1)) * 3);
var tocEntry = spaces + '<a href="#' + itemAnchor + '">' + text + '</a><br/>';
@pkcpkc
pkcpkc / strip-lib.sh
Last active March 29, 2019 17:55
iOS/sh: Extract sub-libraries from a given library without access to source code to avoid namespace clashes
#!/bin/zsh
# We at WeltN24 were facing the problem that two libraries that we integrated
# in our iOS project, used the same sub-library which resulted in naming
# conflicts due to the non-existing namespaces in Swift.
#
# If you know what you are doing you can try to solve this conflict by
# extracting the shared sub-library from one of the libraries you want to
# integrate. You can even do this if you don't have access to the source code
# using the lipo (create or operate on universal files) and ar (create and