Skip to content

Instantly share code, notes, and snippets.

@rubenhorn
rubenhorn / mnist_demo.py
Last active August 16, 2020 17:27
Neural network digit recognition example with GUI
# Based on https://www.tensorflow.org/datasets/keras_example
# Requires numpy, pygame, tensorflow and tensorflow-datasets
NUMBER_OF_EPOCHS = 8
import numpy as np
import pygame
pygame.init()
pygame.display.set_caption('MNIST digits')
@rubenhorn
rubenhorn / retrolink-nes-controller.js
Created December 10, 2020 09:49
Function for reading input from Retrolink NES controller (https://www.gadgetreview.com/retrolink-usb-nes-controller-review) in the browser
@rubenhorn
rubenhorn / list-videos.py
Last active March 18, 2021 15:29
A script to process youtube playlist takeout
#!/usr/bin/python3
import os, sys, requests, re, html
banner = '''
#==================================================
# A script to process youtube playlist takeout
#==================================================
'''
print(banner)
@rubenhorn
rubenhorn / conda_snippets.md
Last active May 26, 2021 12:57
The following snippets can be used to build a (cross platform) script to manage a local Anaconda environment by anyone.

Conda snippets

The following snippets can be used to build a cross platform script to manage a local Anaconda environment by anyone.

Create new environment

conda create -y -p ./.env python=3.9 && conda activate ./.env

Deactivate environment

conda deactivate

Remove environment

@rubenhorn
rubenhorn / totp.py
Last active June 23, 2021 15:59
Simple TOTP implementation using Python
#!/usr/bin/python3
import time, hashlib, hmac, base64
secret = 'q5ma qo4x irgv cm6k auai kjyv ak57 5keu'
T_0 = 0
X = 30
d = 6
K = base64.b32decode(secret.upper().replace(' ', ''))
@rubenhorn
rubenhorn / random-wallpaper.ps1
Created July 6, 2021 08:25
Run from autostart folder using .bat-script with: start /min powershell -File path\to\random-wallpaper.ps1
#====================
# Settings
#====================
$superSampling = 2
$urlTemplate = "https://picsum.photos/{width}/{height}?grayscale"
#====================
# Await connection
#====================
$null = $urlTemplate -match "^https?://([^/]*)/"
@rubenhorn
rubenhorn / aws-mfa.py
Last active January 3, 2022 15:55
Simple command line tool for updating AWS MFA session credentials
#!/usr/bin/python3
import json
from pathlib import Path
from subprocess import PIPE, Popen
import sys
"""
Before using this script:
- Configure AWS cli to output JSON (https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-output-format.html)
@rubenhorn
rubenhorn / firebase-sms-jwt.py
Created March 13, 2022 22:53
Generate Firebase ID token for SMS based authentication
#!/usr/bin/python3
import argparse, requests
url_request_code = (
"https://identitytoolkit.googleapis.com/v1/accounts:sendVerificationCode"
)
url_sign_in_with_phone_number = (
"https://identitytoolkit.googleapis.com/v1/accounts:signInWithPhoneNumber"
)
@rubenhorn
rubenhorn / aws-mfa
Created July 31, 2022 16:25
A simple shell script to generate AWS CLI credentials using MFA
#! /usr/bin/bash
ACCOUNT=$1
USER=$2
OTP=$3
PROFILE=$4
if [ -n "$PROFILE" ]; then
PROFILE="--profile $PROFILE"
fi
@rubenhorn
rubenhorn / eduroam-connect
Created October 6, 2022 11:16
nmcli eduroam script
#! /bin/bash
if [ "$1" == "rm" ]
then
nmcli connection delete eduroam 2>/dev/null
exit
fi
if [ -z "$(nmcli con show | grep eduroam)" ]
then