Skip to content

Instantly share code, notes, and snippets.

@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 / Quiver_HTML_importer.py
Created May 5, 2016 13:35
Quiver HTML importer
import json
import uuid
from pathlib import Path
from urllib.parse import urlparse
from datetime import datetime
import html2text
import requests
from bs4 import BeautifulSoup
@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 / 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 / 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 / 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 / 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: