Skip to content

Instantly share code, notes, and snippets.

View MattWoodhead's full-sized avatar

MattWoodhead

  • UK
View GitHub Profile
In [9]: import array
In [10]: import pickle
In [11]: double_array = array.array("i", range(10 ** 6))
...: start_time = time.time()
...: with open("array_temp.bin", "wb") as f:
...: double_array.tofile(f)
...: array_end_time = time.time() - start_time
In [12]: int_list = list(range(10 ** 6))
...: start_time = time.time()
...: with open("list_temp.bin", "wb") as f:
@MattWoodhead
MattWoodhead / nmea_checksum.py
Created February 17, 2018 13:56
Concise Python 3 function for validating an NMEA string using its included checksum
import operator
from functools import reduce
def nmea_checksum(sentence: str):
"""
This function checks the validity of an NMEA string using it's checksum
"""
sentence = sentence.strip("$\n")
nmeadata, checksum = sentence.split("*", 1)
calculated_checksum = reduce(operator.xor, (ord(s) for s in nmeadata), 0)
@schmich
schmich / ducky.md
Last active September 24, 2024 08:54
Programming media keys on the Ducky One 2 Skyline

Programming Media Keys on the Ducky One 2 Skyline

To use media keys on the Ducky One 2 Skyline, you must record a macro to bind the media function to a hotkey combination, i.e. Fn plus some key.

Example

Important: In the instructions below, "Press X+Y+Z" means press and hold key X, press and hold key Y, press and hold key Z in that order, and then release all three.

As an example, to bind Fn+PgUp to the play/pause media function:

@MattWoodhead
MattWoodhead / ExplorerOnItem.py
Created June 25, 2017 14:21
Open windows explorer with a specific folder or file selected
import subprocess
def explorer_on_file(url):
""" opens a windows explorer window """
subprocess.Popen(f'explorer /select,"{url}"')
explorer_on_file(r"C:\Python\python.exe")
@mowings
mowings / readme.md
Last active April 9, 2024 20:51
ffmpeg stream and save video from Dahua 4300s IP Camera

Use ffmpeg to stream video from a dahua 4300s to a file or files

You can use ffmpeg to directly pull frames off of a dahua 4300s at full resolution. May be a good alternative to pricey dvrs which likely cannot record at full resolution, may not work with the camera, or are prohibitevly expensive

Simple Stream to file

Simple stream to file. Full resolution

ffmpeg -loglevel debug -rtsp_transport tcp -i "rtsp://admin:[email protected]:554/live" \

-c copy -map 0 foo.mp4

@miku
miku / withsqlite.py
Last active November 30, 2022 20:31
Simple sqlite3 context manager for Python.
#!/usr/bin/env python
import sqlite3
class dbopen(object):
"""
Simple CM for sqlite3 databases. Commits everything at exit.
"""
def __init__(self, path):
self.path = path