Skip to content

Instantly share code, notes, and snippets.

View tuck1s's full-sized avatar

tuck1s tuck1s

View GitHub Profile
@tuck1s
tuck1s / csvfix.py
Last active June 6, 2018 22:40
clean up ragged .csv files to make them square
#!/usr/bin/env python3
# Fix up ragged columns to work around problem https://github.com/wireservice/agate/issues/666
import sys, csv
max_sniff_lines = 1000
sniff_buf = []
def columns_in(l):
split_l = list(csv.reader(l.splitlines())) # list, 0th entry holds content
return len(split_l[0])
@tuck1s
tuck1s / chk_ssl.php
Created July 4, 2018 15:26
PHP / Guzzle6 code to check client TLS version
<?php
require_once 'vendor/autoload.php';
function hows_my_ssl()
{
$target = "https://www.howsmyssl.com/a/check";
$client = new \GuzzleHttp\Client(['http_errors' => false]);
$res = $client->request("GET", $target);
echo $res->getStatusCode() . PHP_EOL;
var_dump(json_decode($res->getBody(), false));
@tuck1s
tuck1s / chk_ssl.py
Created July 4, 2018 15:44
Check client ssl characteristics - Python
import requests
from pprint import pprint
def hows_my_ssl():
target = "https://www.howsmyssl.com/a/check"
res = requests.get(target)
print(res.status_code)
pprint(res.json())
hows_my_ssl()
@tuck1s
tuck1s / clean_sound.sh
Last active July 27, 2018 13:32
Take mono sound from captured video(s), clean and normalise it, merge back in as centred stereo
#!/usr/bin/env bash
# put output files in subdir "done"
mkdir -p done
for i in *.mp4
do
# Extract mono (left) channel from captured video into a .wav file
ffmpeg -i "$i" -vn -ac 1 aud1.wav
# Learn noise profile from first x seconds of file, which should be "silence"
sox aud1.wav -n trim 0 1.0 noiseprof speech.noise
# Noise reduction, with mild strength, normalise file volume to -3dB, mix as identical (centre) L R stereo
@tuck1s
tuck1s / mimeshow.py
Created October 8, 2018 15:11
Show MIME structure of email file
#!/usr/bin/env python3
from __future__ import print_function
import email, argparse
def xstr(s):
return str(s) if s else ''
def print_part(m, depth):
pad = ' ' * depth
for i in m.items():
@tuck1s
tuck1s / smtp_example.py
Created November 20, 2018 13:17
Example Python smtplib with STARTTLS negotiation
try:
startT = time.time()
with SMTP(cfg['smtp_host'], port=cfg['smtp_port']) as smtp:
smtp.set_debuglevel(2) # Uncomment this if you wish to see the SMTP conversation / STARTLS neg.
smtp.ehlo(name='sparkpostSMIME')
if 'starttls' in smtp.esmtp_features:
smtp.starttls() # raises an exception if it fails. If continues, we're good
smtp.ehlo(name='sparkpostSMIME')
mode_str = 'STARTTLS'
else:
@tuck1s
tuck1s / SparkPost_win_powershell_example.ps1
Created April 29, 2019 13:28
Windows PowerShell Script to send email via SparkPost using TLS 1.2 and API key credentials
# The Win 10 commandlet defaults to TLS 1.0 which is deprecated as incecure! (see https://www.sparkpost.com/blog/tls-v1-0-deprecation/)
# Make Windows negotiate higher TLS version as follows:
[System.Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Build a Credential object containing SparkPost API key as password
$pwd = ConvertTo-SecureString "<<Your API KEY HERE>>" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ("SMTP_Injection", $pwd)
# Send. This is using the SparkPost EU service. If you are using the US service, change SmtpServer to be smtp.sparkpostmail.com.
Send-MailMessage -From "[email protected]" -To [email protected] -Subject "Hello World" -Body "Here it is" -SmtpServer smtp.eu.sparkpostmail.com -Port 587 -Credential $creds -UseSsl
#!/usr/bin/env python3
# Bubble blaster game from Carol Vorderman book pp.164 onwards
from tkinter import *
HEIGHT = 500
WIDTH = 800
window = Tk()
window.title("Bubble Blaster")
window.attributes("-topmost", 1)
@tuck1s
tuck1s / count-domains.py
Last active July 3, 2020 17:17
Simple tool to count distinct domains in a [list of] file or stdin
#!/usr/bin/env python3
import argparse, csv, sys
import dns.resolver
def domainpart(n):
# A valid email address contains exactly one @, otherwise return None = invalid
parts = n.split('@')
if len(parts) == 2:
return parts[1]
return None
#!/usr/bin/env python3
import imaplib, os
# Very simple IMAP client - prints messages in inbox
imap_host = os.getenv('IMAP_HOST')
imap_user = os.getenv('IMAP_USER')
imap_pass = os.getenv('IMAP_PASSWORD')
# connect to host using SSL
imap = imaplib.IMAP4_SSL(imap_host)