Skip to content

Instantly share code, notes, and snippets.

View JosephRedfern's full-sized avatar

Joseph Redfern JosephRedfern

View GitHub Profile
import imaplib
import re
import random
from email.parser import BytesHeaderParser
from typing import List
import tqdm
@JosephRedfern
JosephRedfern / get_tracks.py
Created September 7, 2019 08:50
Scrape BBC Sounds and update a spotify playlist with the tracks found. Requires spotipy library.
import requests
from bs4 import BeautifulSoup
import json
import spotipy
import spotipy.util
"""
Various constants -- the secrets should be moved to a .env file. SPOTIFY_SCOPES too broad, should be reduced.
"""
import numpy as np
from matplotlib import pyplot as plt
from tqdm import tqdm
board = np.zeros((255, 255))
board[127][127] = 1
board[127][128] = 1
board[128][127] = 1
board[128][128] = 1
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
from django.conf import settings
import ldap
class Command(BaseCommand):
help = 'Add a specific user from LDAP'
def add_arguments(self, parser):
parser.add_argument('user_id', nargs='+', type=str)
@JosephRedfern
JosephRedfern / trace.py
Created October 4, 2018 13:55
A (slow, badly written) Python implementation of https://tmcw.github.io/literate-raytracer/.
from PIL import Image
import tqdm
import math
import vector
height = 320
width = 240
scene = {}
@JosephRedfern
JosephRedfern / call_heirarchy.py
Created April 11, 2018 17:06
Short smali analyser to generate call hierarchy and inspect methods...
import glob
from collections import defaultdict
classes = defaultdict(lambda: defaultdict(list))
class Klass:
def __init__(self, name, project):
self.name = name
self.project = project
@JosephRedfern
JosephRedfern / transmit.py
Created September 26, 2017 08:03
UDP Accelerometer data transmission
import socket
from pyvmu import vmu931, messages
class VMUTransmit(object):
def __init__(self, ip, port, device="/dev/tty.usbmodem1411", euler=True, accelerometer=True, quaternion=True):
self.__device = device
self.__euler = euler
self.__accelerometer = accelerometer
# frames is a list of mdarrays
new_image = np.zeros(frames[n].shape, dtype=frames[n].dtype)
for ny, y in tqdm(enumerate(flow)):
for nx, flow in enumerate(y):
x_flow, y_flow = flow
new_x = int(nx+x_flow*flow_scaling)
new_y = int(ny+y_flow*flow_scaling)
@JosephRedfern
JosephRedfern / evil.py
Created September 8, 2017 14:05
Slack Deleted Message logged
from slackclient import SlackClient
from datetime import datetime
import time
slack_token = 'xoxb-token-goes-here'
sc = SlackClient(slack_token)
if sc.rtm_connect():
while True:
try:
@JosephRedfern
JosephRedfern / threaded.py
Created September 5, 2017 13:32
produces "TypeError: can't pickle _thread.lock objects" under W10 w/ Python 3.6.2.
import time
import random
from queue import Queue
from multiprocessing import Process
import os
def produce_data(q):
print("[+] Producer thread started (PID: {})".format(os.getpid()))
while True: