Skip to content

Instantly share code, notes, and snippets.

View MatthiasKunnen's full-sized avatar

Matthias Kunnen MatthiasKunnen

View GitHub Profile
@MatthiasKunnen
MatthiasKunnen / remove-non-local-sources.ts
Last active April 14, 2023 21:26
Removing all non local scripts from HTML using cheerio
const dom = cheerio.load(html);
dom('script').each((index, item) => {
if ('src' in item.attribs && !item.attribs.src.startsWith('http')) {
dom(item).remove();
}
});
const editedDom = dom.html();
@MatthiasKunnen
MatthiasKunnen / get-indices.sql
Last active December 27, 2018 16:42
Postgres
select
t.relname as table_name,
array_to_string(array_agg(a.attname), ', ') as column_names,
i.relname as index_name
from
pg_class t,
pg_class i,
pg_index ix,
pg_attribute a
where
@MatthiasKunnen
MatthiasKunnen / index.html
Created September 1, 2018 00:54
Visualize a hierarchy.xml file. Outputted by uiautomator dump /sdcard/hierarchy.xml
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
}
@MatthiasKunnen
MatthiasKunnen / create_labels.sh
Last active May 18, 2018 15:50 — forked from omegahm/create_labels.sh
Create Gtihub labels from Bash
#!/usr/bin/env bash
# Colours picked from https://robinpowered.com/blog/best-practice-system-for-organizing-and-tagging-github-issues/
###
# Label definitions
###
declare -A LABELS
# Platform
@MatthiasKunnen
MatthiasKunnen / throw-if.operator.ts
Last active April 18, 2018 12:57
throwIf pipeable operator for RxJs
import { MonoTypeOperatorFunction } from 'rxjs/interfaces';
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import { TeardownLogic } from 'rxjs/Subscription';
class ThrowIfSubscriber<T> extends Subscriber<T> {
constructor(
private myDestination: Subscriber<T>,
@MatthiasKunnen
MatthiasKunnen / rewrite-spiders.htaccess
Created November 9, 2017 19:24
Rewrite spider to static HTML files
RewriteEngine On
# Remove trailing /
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Rewrite spiders to static html
RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot|msnbot|yahoo|Baidu|aolbuild|facebookexternalhit|iaskspider|DuckDuckBot|Applebot|Almaden|iarchive|archive.org_bot) [NC]
RewriteCond %{DOCUMENT_ROOT}/static%{REQUEST_URI}.html -f
RewriteRule ^(.*)$ /static/$1.html [L]
@MatthiasKunnen
MatthiasKunnen / build-static.ts
Created November 9, 2017 18:44
Getting a HTML snapshot via puppeteer
import * as cheerio from 'cheerio';
import * as fs from 'fs';
import * as mkdirp from 'mkdirp';
import * as path from 'path';
import * as puppeteer from 'puppeteer';
import { routes } from './routes'; // Array of strings representing routes
const host = 'https://forcit.be/';
@MatthiasKunnen
MatthiasKunnen / MessageAuthenticationHelper.php
Created August 18, 2017 09:19
Wrapper for generating and verifying HMACs
class MessageAuthenticationHelper
{
const HMAC_TAG_NAME = 'tag';
/** @var string The hash algorithm used for generating a HMAC */
protected $hashAlgorithm = 'sha256';
/** @var string The secret HMAC key. */
protected $hmacKey;