Skip to content

Instantly share code, notes, and snippets.

@kspeeckaert
kspeeckaert / projectoxford.py
Last active March 14, 2016 14:29
Calling project Oxford from Python to perform OCR on an image on the clipboard
import requests
import subprocess
import sys
from PIL import Image
from io import BytesIO
api_url='https://api.projectoxford.ai/vision/v1/ocr'
header = {'Ocp-Apim-Subscription-Key': '',
'Content-Type': 'application/octet-stream'}
@kspeeckaert
kspeeckaert / Answer
Created July 24, 2016 22:18
SO: Pandas gives an error from str.extractall('#')
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
@kspeeckaert
kspeeckaert / sqlserver_tracefiles.py
Created March 14, 2016 14:32
Read SQL server deadlock tracefile (exported to XML format) in Python and convert it to Pandas
import timeit
from lxml import etree
from pandas import DataFrame
from uuid import uuid4
# List of process attributes to retrieve
def analyze_deadlock(elem, data_locks, data_procs):
# Generate a UUID to identify all processes belonging to the same deadlock event
dl_uuid = uuid4().hex
databases = set()
@kspeeckaert
kspeeckaert / notebook.ipynb
Created June 30, 2016 08:29
Efficient query pandas dataset
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kspeeckaert
kspeeckaert / tab2md.py
Created March 14, 2016 15:08
Convert an HTML table (on the clipboard) to Markdown
from bs4 import BeautifulSoup
from tabulate import tabulate
import xerox
raw_html = xerox.paste()
tab_html = BeautifulSoup(raw_html, 'lxml')
rows = []
for row in tab_html.find_all('tr'):
cols = [x.get_text().strip() for x in row.find_all(['td', 'th'])]
@kspeeckaert
kspeeckaert / packt_books.py
Last active December 19, 2018 00:43
PacktPub e-books downloader
from pathlib import Path
import logging
import re
import requests
from bs4 import BeautifulSoup
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
class PacktBooks:
@kspeeckaert
kspeeckaert / pdf_toc_to_opml.py
Last active September 16, 2019 11:07
Extract the table of contents from a PDF file and save it as an OPML, e.g. for import into a mind map
# Requirements
# yattag==1.12.2
# PyPDF2==1.26.0
# Tested with Python 3.7.4 on macOS
import sys
from pathlib import Path
@kspeeckaert
kspeeckaert / url2mdlink.py
Created March 14, 2016 15:10
Create a Markdown link from a URL, using the page's title as link description
@kspeeckaert
kspeeckaert / WaitForIt.ps1
Last active September 13, 2021 11:47
Wait until a remote host comes online and has RDP available, after a reboot.
#Requires -Module BurntToast
[cmdletbinding()]
param (
[Parameter(Mandatory)][string]$ComputerName,
[Parameter(Mandatory)][string]$ConnectionID
)
function Test-TCPPort {
# Replacement for Test-NetConnection, because ping cannot be disabled.
@kspeeckaert
kspeeckaert / Test-DCResponse.ps1
Last active September 16, 2021 10:21
Given a username and a domain, perform a lookup on each DC and measure the time it takes (if successful).
function Test-ADUser() {
[CmdletBinding()]
<#
Perform a user account lookup on a given DC and return a boolean
indicating success or failure.
#>
param(
[string]$UserName,
[string]$Server
)