Skip to content

Instantly share code, notes, and snippets.

@danslinky
danslinky / fastapi_keycloak_oidc.py
Created August 14, 2024 05:32
Python: FastAPI OpenID Connect using Keycloak
from fastapi import FastAPI, Request, HTTPException
from starlette.responses import RedirectResponse
from keycloak import KeycloakOpenID
import logging
app = FastAPI()
keycloak_openid = KeycloakOpenID(
server_url="https://keycloak.example.com/",
client_id="your-client",
@danslinky
danslinky / apple_music_dev_token.py
Created August 14, 2024 05:29
Python: Generate Apple Music Developer Token
# %%
import jwt
import time
from datetime import timedelta
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.backends import default_backend
# Load your private key from the .p8 file
with open('./your_key.p8', 'rb') as key_file:
private_key = serialization.load_pem_private_key(
@danslinky
danslinky / apple_music_album_library.py
Created August 14, 2024 05:27
Python: Add Album to Apple Music Library
# %%
import requests
url = "https://api.music.apple.com/v1/me/library"
params = {
"ids[albums]": "1590556925"
}
headers = {
"Authorization": "Bearer changeme",
@danslinky
danslinky / apple_music_artist_search.py
Created August 14, 2024 05:22
Python: Apple Music Artist search
# %%
import requests
import csv
region = "us"
base_url = f"https://api.music.apple.com/v1/catalog/{region}/search"
bearer_token = "changme"
music_user_token = "changeme"
def search_artist(artist_name):
@danslinky
danslinky / example.c
Created August 9, 2024 21:43
Simple kernel module
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/mm.h> // For get_vmalloc_info
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Dan Slinky");
MODULE_DESCRIPTION("A simple Linux module for displaying basic system stats.");
MODULE_VERSION("0.1");
@danslinky
danslinky / ebpf.c
Last active August 9, 2024 21:41
An ebpf example that listens for DNS requests sent over the network
#include <linux/if_link.h>
#include <linux/socket.h>
#include <linux/ip.h>
#include <linux/icmp.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/in.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/string.h>
@danslinky
danslinky / email-dkim.py
Last active August 21, 2024 16:53
Send DKIM signed emails #python #postfix #dkim
# %% [markdown]
# Send a DKIM-signed email from a home Postfix server
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import dkim
import uuid
# SMTP server configuration
@danslinky
danslinky / mbox.ipynb
Created June 10, 2024 19:55
exploring an gmail mbox using python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danslinky
danslinky / runpod-automatic1111.py
Last active June 9, 2024 22:47
A text-to-image toy that creates images on a serverless # [RunPod](https://www.runpod.io/) endpoint.
# %% [markdown]
# # RunPod Automatic1111 Stable Diffusion
#
# A text-to-image toy that creates images on a serverless
# [RunPod](https://www.runpod.io/) endpoint. Enter a prompt,
# using the form or function.
#
# ```py
# new("a cow in space")
# ```