Skip to content

Instantly share code, notes, and snippets.

@danielfaust
danielfaust / usage_yubikey_otp_check_v2.py
Last active November 12, 2023 18:07
This file contains the code to check a YubiKey OTP against YubiCloud's v2 protocol servers for Python 3 and 2.7. This code is not well tested but works, it is only meant for internal stuff like to prevent accidental execution of scripts which deal with database schema migrations or such things which really shouldn't get executed accidentally
import yubikey_otp_check_v2
def verify(otp):
message = ''
user = ''
users = {
b'cccccabcdef1': b'user1',
b'cccccabcdef2': b'user2',
}
@danielfaust
danielfaust / cleanup-boot.py
Last active February 21, 2022 13:19
Running this script results in the printing of a recommended "apt purge" command to remove unused kernels, in order to free up space on the boot partition. It does not modify anything, it only shows what the system has installed and what can be removed. Keywords: ubuntu boot partition full no space left
import os
import re
print('--------------')
active_kernel_version = os.popen('uname -r').read().strip().replace('-generic', '')
existing_kernels = os.popen('dpkg --list | egrep -i --color "ii (linux-image|linux-headers|linux-modules)"').read().strip()
print(existing_kernels)
print('--------------')
existing_kernels = os.popen('dpkg --list | egrep -i --color "ii (linux-image)"').read().strip()
kernel_versions = []
@danielfaust
danielfaust / yubikey_otp_check.py
Last active November 12, 2023 18:06
Deprecated. Use this one instead https://gist.github.com/danielfaust/a9807b2f2256a49b18564daa8bc6cdf2 -- Original Text: This file contains the code to check a YubiKey OTP against YubiCloud's v2 protocol servers for Python 2.7. This code is not well tested, it is only meant for internal stuff like to prevent accidental execution of scripts which …
import sys
sys.dont_write_bytecode = True
import yubikey_otp_check_v2
users = {
'cccccabcdef1': 'user1',
'cccccabcdef2': 'user2',
}
@danielfaust
danielfaust / gist:1014131
Created June 8, 2011 09:57
Decode Email Headers to Unicode
# header = email.message_from_string(mail['header'])
# decoded_subject = myDecodeHeader(header["subject"])
def myDecodeHeader(subject):
if subject is None:
subject = ''
else:
subject = subject.replace("\r\n", "")
try:
subject = unicode(subject, 'utf-8')
@danielfaust
danielfaust / samsung_remote.py
Created May 30, 2011 04:12
Samsung TV Remote Control Python Script
import time
import socket
import base64
src = '192.168.1.2' # ip of remote
mac = '00-AB-11-11-11-11' # mac of remote
remote = 'python remote' # remote name
dst = '192.168.1.3' # ip of tv
app = 'python' # iphone..iapp.samsung