Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / tic_tac_toe.py
Last active August 13, 2020 14:45
Simple RL-TicTacToe game written in python (change the variable of player_1 and player_2 in line 190 and 191 to human_player to play against the AI)
#!/usr/bin/env python3
import os, re, random, copy, sys, atexit
clear = lambda: os.system('cls' if os.name == 'nt' else 'clear')
def print_header():
print(' _____ _ _____ _____ ')
print(' |_ _(_)_|_ _|_ _ _|_ _|__ ___ ')
print(' | | | / _|| |/ _` / _|| |/ _ \/ -_)')
@rubenhorn
rubenhorn / tic_tac_toe.py
Created August 13, 2020 11:52
Simple TicTacToe game written in python
#!/usr/bin/env python3
import os, re, random
clear = lambda: os.system('cls' if os.name == 'nt' else 'clear')
def print_header():
print(' _____ _ _____ _____ ')
print(' |_ _(_)_|_ _|_ _ _|_ _|__ ___ ')
print(' | | | / _|| |/ _` / _|| |/ _ \/ -_)')
@rubenhorn
rubenhorn / 2xYT.js
Created August 3, 2020 12:50
Tampermonkey script to set YouTube playback speed to 2x
// ==UserScript==
// @name 2xYT
// @version 0.1
// @description Automatically sets the playback speed to 2x on YouTube.com
// @match *://www.youtube.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
@rubenhorn
rubenhorn / broadcast.py
Created June 7, 2020 09:44
Simple UDP broadcasting demo
import socket
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-m', '--mode', choices=['sender', 'receiver'], required=True)
arguments = parser.parse_args()
is_sender = arguments.mode == 'sender'
receiver_port = 1234
receive_size = 1024