Skip to content

Instantly share code, notes, and snippets.

a = 'abcdef'
for x in 2,3,6:
print(f'{x} : {a[x-1]}')
import requests
# from pathlib import Path
from pprint import pprint
road = 'A1'
url = f'http://www.trafficengland.com/api/events/getByRoad?road={road}&events=CONGESTION,INCIDENT,ROADWORKS,MAJOR_ORGANISED_EVENTS,ABNORMAL_LOADS&direction=all&includeUnconfirmedRoadworks=true'
r = requests.get(url)
for event in r.json():
print(event)
@DavidLutton
DavidLutton / set.py
Created May 26, 2019 12:07
Set the source of a BG7TBL USB Signal Generator
# https://sigrok.org/wiki/BG7TBL
import serial
ser = serial.Serial('/dev/ttyUSB0', 57600, timeout=1) # Linux first tty
# ser.write(b'\x8fv')
# print("Version is " + ser.read())
cmd = f'{int(1e9+26000/10):09d}' # ~ 1GHz
@DavidLutton
DavidLutton / cleanup.sh
Created May 27, 2019 19:19
find all except .dot directorys
find . -type d -empty -not -path '*/\.*' -delete
from importlib import reload
import recycling
time.sleep(60) # time to edit recycling
reload(recycling) # reload recycling
recycling.get_recycling() # make use of the module
# https://stackoverflow.com/questions/1254370/reimport-a-module-in-python-while-interactive
#!/usr/bin/env python
from pathlib import Path
from pprint import pprint
from requests_html import HTMLSession
import toml
import schedule
from time import sleep
find . -name "$1" -exec grep -Hn "$2" '{}' \;
import math
import pandas as pd
import numpy as np
def measurementfunction(columns=['Input', 'Output']):
# Inital call of next() runs the init/setup
print('Init/Setup of Instrument')
buffer = {}
# A initial call of next(generatorobject) will get to this point
x = yield # Where first input is outside the while loop
@DavidLutton
DavidLutton / bootimgwithphysicaldisk.sh
Last active July 8, 2019 00:00
Boot .img in qemu-kvm with a physical disk /dev/sdb
sudo chown root:$USER /dev/sdb && qemu-kvm -hda LibreELEC*.img -m 4096 -drive format=raw,file=/dev/sdb ; sudo chown root:disk /dev/sdb
from pathlib import Path
older, newer = sorted(list(Path('.').glob('prefix_????-??-??.ext')))[-2:] # last 2 files