Skip to content

Instantly share code, notes, and snippets.

@shapiromatron
shapiromatron / renameFilesByDatestamp.py
Last active August 29, 2015 14:05
Rename files in a path based on the file creation date. Useful for renaming pictures and movies from multiple sources.
from datetime import datetime, timedelta
import os
def renameByDatestamp(path, hourAdjustment):
"""
Rename files in a path using the time-created stamp. Adjust name by adding
an integer if files have non-unique timestamps.
Ideal for renaming pictures and videos from multiple sources.
@shapiromatron
shapiromatron / gmail.py
Last active August 29, 2015 14:05
send email using gmail and built-in python smtplib
import smtplib
def send_email(email, pw, subject, text):
FROM = email
TO = [email]
try:
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s\n""" % (FROM, ", ".join(TO), subject, text)
server = smtplib.SMTP("smtp.gmail.com", 587) # alternatively port 465
server.ehlo()
@shapiromatron
shapiromatron / prepare_css.py
Last active December 20, 2015 09:08
Prepares one CSS stylesheet for all styles which may be applied to D3 objects.
#usr/bin/python
import os
import re
this_path = os.path.abspath(__file__)
static_path = os.path.abspath(os.path.join(this_path, r'../../project/static'))
@shapiromatron
shapiromatron / gist:5024948
Last active January 31, 2025 12:43
Convert an Excel Range to a Bootstrap HTML table
' Example function call: =BuildHTMLTable(A1:D5)
Public Function BuildHTMLTable(rng As Range) As String
' Given a Range of Cells, build a Bootstrap HTML table, using the formatting
' specified in the Excel cells. If "header" is specified to equal true, assumes
' the first row in the table is a header row.
Dim last_r As Long: last_r = rng.Cells(1, 1).Row
Dim tds As New Collection
Dim txt As String
Dim isFirstRow As Boolean: isFirstRow = True