Skip to content

Instantly share code, notes, and snippets.

View StevenMaude's full-sized avatar
🏠
Working from home

Steven Maude StevenMaude

🏠
Working from home
View GitHub Profile
@StevenMaude
StevenMaude / password_animation.py
Last active August 24, 2016 22:33
Movie-like password cracking animation in Python that looks nifty. Code for guessing a string written for a problem in "Problem Solving with Algorithms and Data Structures" with my additional idea of printing every attempt and slowing down prints to make them readable. Tested with Python 2.7/3.4.
from __future__ import print_function, unicode_literals
import random
import time
def generate_random_guess(chars):
return random.choice(chars)
def repeated_guesses(target):
@StevenMaude
StevenMaude / pdf_to_html.py
Created May 16, 2014 09:53
pdf_to_html_preview messy hack to work on Windows
#forked from: Julian_Todd / PDF to HTML (https://scraperwiki.com/views/pdf-to-html-preview-1/)
#input url goes to line
import sys
import urllib, urllib2, urlparse
import lxml.etree, lxml.html
import re, os
def Pageblock(page, index):
'''
@StevenMaude
StevenMaude / tfidf_features.py
Created July 21, 2014 13:35
Do TF-IDF with scikit-learn and print top features
#!/usr/bin/env python
# encoding: utf-8
import codecs
import os
import sys
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
@StevenMaude
StevenMaude / element_and_attribute_count.py
Last active May 15, 2023 12:48
Collect the tags from a HTML string into a Python Counter; count them once only (for summing over multiple pages to see how many docs have certain tags))
#!/usr/bin/env python
# encoding: utf-8
import csv
from collections import Counter
import lxml.html
def create_test_html():
""" Return a test HTML string. """
@StevenMaude
StevenMaude / jq_select
Created November 5, 2014 11:07
Simple jq select statement to match JSON files with title value of "some title"
jq '.["title"] | select(. == "some title")' *.json
@StevenMaude
StevenMaude / extract_text_and_remove_line_breaks_from_html.py
Last active August 29, 2015 14:18
Clean up unwanted line breaks in HTML text; takes two arguments: input HTML filename and output name. (Uses lxml 3.4.2; later versions may be OK too.)
#!/usr/bin/env python
# encoding: utf-8
from __future__ import (unicode_literals, print_function,
absolute_import, division)
import codecs
import re
import sys
import lxml.html
@StevenMaude
StevenMaude / get_coffee_break_french_podcasts.sh
Last active May 8, 2016 20:23
Download the Coffee Break French podcasts using curl
#!/bin/bash
for i in {01..02} {04..24} {26..80} {301..340} ; do
curl -f -O -J -L https://media.libsyn.com/media/coffeebreakfrench/cbf-$i-basic.mp3
done
for i in {401..424} {426..440} ; do
curl -f -O -J -L https//media.libsyn.com/media/coffeebreakfrench/cbf-$i-main.mp3
done
# Handle cases which don't fit the normal pattern.
@StevenMaude
StevenMaude / sha256frompubkey.py
Last active August 14, 2022 04:06
Generate SHA256 fingerprint from a public key
#!/usr/bin/python
# coding=utf-8
# sha256frompubkey.py: Displays SHA256 fingerprint of public key in Python 2/3.
# Modified by Steven Maude from
# https://github.com/joyent/python-manta/blob/4de7445277c0971c7ff43ef246018d055ef21d20/manta/auth.py
# MIT licence.
# Usage: obtain a public key using ssh-keyscan <host> > key.pub
@StevenMaude
StevenMaude / convert_gpx.sh
Last active January 29, 2023 17:29
Use gpsbabel to convert Garmin .FIT to .gpx — requires a fairly recent version of gpsbabel (minimum 1.4.3); see https://www.stevenmaude.co.uk/posts/using-garmin-forerunner-watches-with-linux for more details on using Garmin watches with Linux
#!/bin/sh
# Usage: convert_gpx.sh <FIT filename>
# Should works whether you include the .FIT extension or not.
filename=$(basename "$1" .FIT)
gpsbabel -i garmin_fit -f "$filename".FIT -o gpx -F "$filename".gpx
@StevenMaude
StevenMaude / extract_gpx_data.py
Last active March 15, 2016 00:42
Quick hacky script to extract date and 2D length data from GPX files to CSV using gpxpy; at least compatible with Py2.7/3.4
#!/usr/bin/env python
""" Extract date and 2D length data from GPX files in current directory. """
from __future__ import division, print_function
import decimal
import glob
import gpxpy
def main():