Skip to content

Instantly share code, notes, and snippets.

View custom_route.sh
#!/bin/bash
# don't use this if all your need is a route that goes through your ISP router
# instead of an openvpn tunnel. OpenVPN has this as a built-in feature!
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit 1
fi
View ldap_ssh_key.sh
#!/bin/bash
# https://gist.github.com/koenpunt/40c0b042c453a1add0e8
#
# Check if the user is in the right group
# and afterwards retrieve the SSH public key from LDAP
# Logs directly in Syslog
# requires ldap-utils
#
# sshd_config for OpenSSH 6.2 or higher:
#
View redis-discon.py
@app.get("/sse/stream")
async def stream(req: Request, channel: str = "default", redis: Redis = Depends(depends_redis)):
# return EventSourceResponse(subscribe(channel, redis))
async def event_publisher():
_log.info(f"Subscribing for client {req.client}")
(channel_subscription,) = await redis.subscribe(channel=Channel(channel, False))
try:
View flask-sse.py
from queue import Queue
from collections import defaultdict
class Publisher(object):
"""
Contains a list of subscribers that can can receive updates.
Each subscriber can have its own private data and may subscribe to
different channel.
"""
View two.py
import asyncio
import uvicorn
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.routing import Route
from sse_starlette.sse import EventSourceResponse, unpatch_uvicorn_signal_handler
# unpatch_uvicorn_signal_handler() # if you want to rollback monkeypatching of uvcorn signal-handler
View get_spf_ip.py
#!/usr/bin/env python3
import ipaddress
from SPF2IP import SPF2IP
ignore_list = set({'127.0.0.1/32'})
ignore_list.update({ # Microsoft O365
'40.92.0.0/15',
View ldap_cert_fetch.py
import logging
import ssl
import uuid
from urllib.parse import urlparse
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from django.db import models
from django.utils.functional import cached_property
View parse-usb-devices.sh
#!/usr/bin/env bash
# parse-usb-devices.sh
#
# Parse the output of the "usb-devices" bash script and filter
# only for Mass Storage devices (Class 08). Include the active
# device speed (to see whether it is USB2 or USB3.
set -e
View token_auth.py
from channels.auth import AuthMiddlewareStack
from channels.db import database_sync_to_async
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
from django.http.cookie import parse_cookie
@database_sync_to_async
def get_user(token_key):
try:
View ip2tor_snip.sh
#!/bin/bash
# store values from environment
env_IP2TOR_SHOP_URL=${IP2TOR_SHOP_URL-notset}
env_IP2TOR_HOST_ID=${IP2TOR_HOST_ID-notset}
env_IP2TOR_HOST_TOKEN=${IP2TOR_HOST_TOKEN-notset}
# if config file exists use it (but vars set from environment overwrite file vars)
if [ -f /etc/ip2tor.conf ]; then
unset IP2TOR_SHOP_URL