Skip to content

Instantly share code, notes, and snippets.

@waylan
waylan / test_html_parser.py
Created March 26, 2019 00:09
A simple test HTMLParser to see how the HTMLParser for python works.
try:
import HTMLParser as parser
except ImportError:
from html import parser
class TestParser(parser.HTMLParser):
def handle_starttag(self, tag, attrs):
print ("STAG:", tag)
@waylan
waylan / date_range.py
Last active December 28, 2018 21:17
Use Pandas to get a range of start/end dates for all weeks of year
import pandas as pd
# "W-SUN" for Monday to Sunday week. Use "W-SAT" for Sunday to Saturday...
date_range = pd.period_range('1/1/2019', '12/31/2019', freq='W-SUN')
"""
>>> date_range
PeriodIndex(['2018-12-31/2019-01-06', '2019-01-07/2019-01-13',
'2019-01-14/2019-01-20', '2019-01-21/2019-01-27',
...
@waylan
waylan / applescript.py
Created December 2, 2018 01:44
Call Applescripts from Python
#!/usr/bin/python
# From http://www.leancrew.com/all-this/2013/03/combining-python-and-applescript/
# Updated for Python 3
import subprocess
def asrun(ascript):
"Run the given AppleScript and return the standard output and error."
@waylan
waylan / click_doc.py
Last active August 10, 2018 20:21
Extract click documentation
from pkg_resources import iter_entry_points
import click
def get_entry_point_object(name):
""" Return the object associated with an installed console script entry point. """
entry_points = [ep for ep in iter_entry_points('console_scripts', name=name)]
if len(entry_points) < 1:
raise ValueError("'{}' is not an installed console script.".format(name))
return entry_points[0].resolve()
@waylan
waylan / test_copy_file.py
Last active July 7, 2018 00:55
Test speed of a custom (faster?) copy_file function.
import os
import shutil
def copy_file(src, dst):
"""
Copy src to dst ensuring parent directories are created.
The dst may be a directory, as long as it already exists.
"""
# If destination directory doesn't exist, create it.
dst_dir = os.path.dirname(dst)
@waylan
waylan / office_macros.vb
Last active October 26, 2022 15:15
Some of my MS Office Macros
Sub FancyTitleCase()
'
' Fancy Title Case Macro
'
'
Dim lclist As String, wrd As Integer, sTest As String
' list of lowercase words, surrounded by spaces
lclist = " a an and at but by for from in nor of on or so the this to up yet v v. vs vs. "
Selection.Range.Case = wdTitleWord
@waylan
waylan / tempdir.py
Created May 24, 2018 20:27
A decorator for building a temporary directory with prepopulated files.
from functools import wraps
try:
# py>=3.2
from tempfile import TemporaryDirectory
except ImportError:
from backports.tempfile import TemporaryDirectory
from pathlib2 import Path
def tempdir(files=None, **kw):
"""

Still on the left!!!

Column1 Column1 Column1
Column1 Column1 Column1

A Raw HTML Table in GitHub Flavored Markdown

some thing more important up here

An example of a diff code block:

  Unchanged Line
- Removed Line
+ Added Line