Skip to content

Instantly share code, notes, and snippets.

@tokland
tokland / apkpure-dl.sh
Created June 22, 2024 15:06
Download APK files from APKPure
#!/bin/bash
set -e -u -o pipefail
download_apk() {
local app_id=$1
# https://github.com/EFForg/apkeep/blob/master/src/apkpure.rs#L18C54-L18C61
curl -sS "https://api.pureapk.com/m/v3/cms/app_version?hl=en-US&package_name=$app_id" \
-H 'x-sv: 29' \
-H 'x-abis: arm64-v8a,armeabi-v7a,armeabi' \
@tokland
tokland / search-history.sh
Last active June 22, 2024 15:33
Fast search of commands in shell history
#!/bin/bash
# Search commands in history
set -e -u -o pipefail
if [ "$#" -lt 1 ]; then
echo "Usage: $0 wordToMatch anotherWordToMatch -skipIfWordMatches +wordToMatchCaseSensitive ..."
exit 1
fi
command="cat ~/.bash_history"
#!/bin/bash
set -e -u -o pipefail
run() {
for version in "$@"; do
local url="https://play.dhis2.org/$version/api"
echo "# $version"
curl -sS -u 'admin:district' -L "$url/events.json?event=QsAhMiZtnl2&fields=*" | jq >events.json
@tokland
tokland / rac1-alacarta-userscript.js
Created April 2, 2022 16:01
Add forward/backward buttons to RAC1 A la Carta web player [tampermonkey] [greasemonkey] [userscripts]
// ==UserScript==
// @name rac1-alacarta
// @description Add back/forward buttons to audio player
// @namespace https://github.com/tokland
// @homepage https://github.com/cvzi/rollup-userscript-template
// @author tokland
// @match https://www.rac1.cat/a-la-carta*
// @icon https://www.google.com/s2/favicons?sz=64&domain=rac1.cat
// @run-at document-start
// @version 0.0.1
@tokland
tokland / flask_cors_proxy.py
Created March 21, 2022 11:45
Flask CORS proxy redirector
import json
import requests
import urllib
from flask import Flask, Response, stream_with_context, request
app = Flask(__name__)
@app.route('/<path:url>', methods=["GET", "POST", "PUT", "DELETE"])
def proxy(url):
@tokland
tokland / get-request-urls.py
Last active February 12, 2022 21:54
Get all requests of a page in Python using gtk webkit2
#!/usr/bin/python3
import os
import sys
from contextlib import contextmanager
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import Gtk, WebKit2
@tokland
tokland / immutable-selectors.ts
Last active May 23, 2021 15:39
Example of immutable get/set using nested and composable selectors/lenses
type IsArray<T> = T extends unknown[] ? true : false;
type IsObject<T> = T extends object ? (IsArray<T> extends true ? false : true) : false;
type ObjectS<From, To> = {
[K in keyof To]: Selector<From, To[K]>;
};
interface BaseFns<From, To> {
get: (from: From) => To;
@tokland
tokland / har-stats.ts
Created April 29, 2021 08:06
Get some simple stats from a HAR file
import _ from "lodash";
import fs from "fs";
import crypto from "crypto";
import { Har } from "har-format";
function getMd5(data: string) {
return crypto.createHash("md5").update(data).digest("hex");
}
interface Request {
@tokland
tokland / tee2.sh
Created April 23, 2021 19:43
Show command output while redirecting stdout/stderr to files
#!/bin/bash
# Like tee, but redirect both stdout and stderr to different files.
#
# Example: exec_and_tee2 file-with-stdout.txt file-with-stderr.txt find / -maxdepth 1 -type d
exec_and_tee2() {
local stdout=$1 stderr=$2
shift 2
{ "$@" > >(tee "$stdout"); } 2> >(tee "$stderr")
}
@tokland
tokland / maybe-controlled-value-hook.ts
Created January 6, 2021 12:21
React hook for optional value/setValue
import React from "react";
export interface OptControlledValue<T> {
value?: T;
set?: (value: T) => void;
initial: T;
}
export function useMaybeControlledValue<T>(options: OptControlledValue<T>): [T, (val: T) => void] {
const optionsSet = options.set;