Skip to content

Instantly share code, notes, and snippets.

@blha303
blha303 / txtrecord_decode.py
Last active May 10, 2020 03:28
Encoding and decoding files with txt records
#!/usr/bin/env python3
# txtrecord_decode.py [-h] output.png logo.example.com
import dns.resolver # pip3 install dnspython
import base64
import sys
from argparse import ArgumentParser
def parse_records(name):
_next = ""
print("{}".format(name), file=sys.stderr)
q = dns.resolver.query(name,"TXT").response.answer[0]
@blha303
blha303 / aws-cloudformation-lamp-test.yml
Created May 29, 2019 11:55
generated by AWS cloudformation
AWSTemplateFormatVersion: 2010-09-09
Description: >-
AWS CloudFormation Sample Template LAMP_Single_Instance: Create a LAMP stack
using a single EC2 instance and a local MySQL database for storage. This
template demonstrates using the AWS CloudFormation bootstrap scripts to
install the packages and files necessary to deploy the Apache web server, PHP
and MySQL at instance launch time. **WARNING** This template creates an Amazon
EC2 instance. You will be billed for the AWS resources used if you create a
stack from this template.
Parameters:
@blha303
blha303 / 1001.conf
Last active July 2, 2019 08:24
Asterisk 1.0.0.1 context
[1001]
exten => _X.,1,Set(CALLERID(name)=1.0.0.1)
exten => _X.,n,Answer
exten => _X.,n,Wait(1)
exten => _X.,n,Playback(1001-recordtype) ; "Enter record type on your phone keypad, followed by the hash key. Press 1 to go to next character"
exten => _X.,n,Read(recordtype,,,si,)
exten => _X.,n,Playback(1001-domain) ; "Enter domain name to retrieve record, followed by the hash key"
exten => _X.,n,Read(domain,,,si,)
exten => _X.,n,Set(RECORD="${SHELL(/usr/bin/1001.py "${recordtype}")}")
exten => _X.,n,Set(ADDR="${SHELL(/usr/bin/1001.py "${domain}")}")
@blha303
blha303 / discord_presence_pbx.py
Last active December 3, 2022 21:04
connects to an asterisk manager and picks up ExtensionStatus messages. ties into https://gist.github.com/blha303/37e83f320b009de19e7a6c140f51e8d5
import socket
from requests import get
EXTEN = "1"
presence_api = "http://127.0.0.1:8081"
auth = ("me", "aa")
pbx_ip = "127.0.0.2"
def process_event(resp):
d = {}
@blha303
blha303 / discord_presence_working.py
Created March 17, 2019 19:38
A webpage for updating my presence while I'm at work showing what I'm up to
from pypresence import Presence # https://github.com/qwertyquerty/pypresence
from flask import *
from requests import get
from time import sleep
client_id = "556918123421368329"
RPC = Presence(client_id)
RPC.connect()
app = Flask(__name__)
@blha303
blha303 / discord_presence_plex.py
Last active December 3, 2022 21:04
uses Tautulli as an easy way to get plex session data. has to be run on the same machine as your discord desktop client for access to RPC
from pypresence import Presence # https://github.com/qwertyquerty/pypresence
from requests import get
from time import sleep
from sys import exit
client_id = "556909532417228919"
user = "blha303"
tautulli_instance = "https://tau.home.b303.me" # https://github.com/Tautulli/Tautulli
RPC = Presence(client_id)
@blha303
blha303 / wownav.py
Last active February 9, 2019 19:26
#!/usr/bin/env python3
# proof of concept for an idea i've had for a while
from peewee import *
db = SqliteDatabase("wownav.db")
class BaseModel(Model):
class Meta:
database = db
class Faction(BaseModel):
#!/usr/bin/env python3
# A script to generate videos for MP3s
from moviepy.editor import *
import numpy as np
from PIL import Image
from glob import glob
from mutagen.mp3 import MP3
from io import BytesIO
#points
@blha303
blha303 / gmgetalbum.py
Last active November 10, 2018 12:07
I'm sure I've made this before...
#!/usr/bin/env python3
import gmusicapi
import os
from argparse import ArgumentParser
import requests
from mutagen import File
gmusic = gmusicapi.Mobileclient()
gmusic.login(os.environ["GMUSICAPI_EMAIL"], os.environ["GMUSICAPI_PASSWORD"], os.environ["GMUSICAPI_MACADDR"])
@blha303
blha303 / getgmusic.py
Last active September 24, 2018 03:38
A gmusicapi script
#!/usr/bin/env python3
import subprocess,gmusicapi,sys,mutagen,os
c = gmusicapi.Mobileclient()
c.login(os.environ["GMUSICAPI_EMAIL"], os.environ["GMUSICAPI_PASSWORD"], os.environ["GMUSICAPI_MACADDR"])
for track in c.get_album_info(sys.argv[1], include_tracks=True)["tracks"]:
try:
fn = "{trackNumber:0>2} {artist} - {title}.mp3".format(**track).replace("/", "-")
print(fn)
p = subprocess.run(["wget", c.get_stream_url(track["storeId"]), "-O", fn], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)