Skip to content

Instantly share code, notes, and snippets.

View catichenor's full-sized avatar

Christopher Tichenor catichenor

View GitHub Profile
@catichenor
catichenor / getParentHTML.applescript
Created February 27, 2017 20:25
Get the parent HTML of the current selection in Safari from Applescript
tell application "Safari"
set selected to (do JavaScript "x=(function() { self.focus() ; b= self.getSelection().anchorNode.parentNode.outerHTML; return b ; })();x" in document 1) as string
return selected
end tell
@catichenor
catichenor / fade-edges.py
Last active December 12, 2022 04:43
Non-Pythonista Python script to fade image edges with Pillow
#!/usr/bin/env python
import argparse
from os import path
from PIL import Image, ImageDraw, ImageFilter
argparser = argparse.ArgumentParser()
argparser.add_argument('input_file', help='File to add faded edges to')
@catichenor
catichenor / pomodoro_linux.py
Last active August 8, 2018 20:04
Simple Pomodoro timer for GNOME 3, this time with Python
#!/usr/bin/python
# Thanks to http://www.devdungeon.com/content/desktop-notifications-python-libnotify
import time
from datetime import datetime
from gi.repository import Notify
Notify.init('pomodoro_linux.py')
@catichenor
catichenor / pomodoro_mac.py
Last active August 8, 2018 20:04
Simple Pomodoro timer, this time for Mac.
#!/usr/bin/python
# Work for 25 minutes, break for 5 minutes.
# Thanks to lukaszb for the gist at https://gist.github.com/lukaszb/5001170
import time
from datetime import datetime
from Foundation import NSUserNotification
from Foundation import NSUserNotificationCenter
@catichenor
catichenor / type_from_clipboard.applescript
Last active August 9, 2023 13:54
Type text from the clipboard with AppleScript/Automator
--Adapted from http://apple.stackexchange.com/questions/194567/how-can-i-use-applescript-to-type
--Types text in where TypeIt4Me dare not tread (like in a VNC session).
on run {input, parameters}
tell application "System Events"
set textToType to the clipboard
delay 1
keystroke textToType
end tell
@catichenor
catichenor / num_grid.py
Last active January 24, 2017 01:33
Print a 10x10 numeric grid from 0-99
#!/bin/python
for i in range(0,100,10):
for j in range(0,10):
print(str(i+j).rjust(3), end='')
print('')
@catichenor
catichenor / current-business-week.py
Last active January 17, 2017 22:31
Print out the date range for the current business week in Python.
from datetime import datetime, timedelta
today = datetime.now()
date_today = datetime(today.year, today.month, today.day)
day_of_the_week = date_today.weekday()
date_start_delta = timedelta(-(date_today.weekday()))
date_start = date_today + date_start_delta # Result should be Monday of this week.
date_end_delta = timedelta(4)
date_end = date_start + date_end_delta # Result should be Friday of this week.
@catichenor
catichenor / csv_check.py
Last active October 12, 2025 18:54
Check CSV file for a header row, and detect the dialect.
import csv
input_csv_file = '/path/to/test_csvfile.csv'
with open(input_csv_file, 'rb') as csvfile: #`with open(input_csv_file, 'r') as csvfile:` for Python 3
csv_test_bytes = csvfile.read(1024) # Grab a sample of the CSV for format detection.
csvfile.seek(0) # Rewind
has_header = csv.Sniffer().has_header(csv_test_bytes) # Check to see if there's a header in the file.
dialect = csv.Sniffer().sniff(csv_test_bytes) # Check what kind of csv/tsv file we have.
inputreader = csv.reader(csvfile, dialect)
@catichenor
catichenor / time_code.py
Last active January 11, 2017 22:29
Timing a piece of code in Python
import datetime
def time_code(time1, time2, label):
time_difference = (time2 - time1).total_seconds()
return 'Time to run ' + label + ': ' + str(time_difference) + ' seconds.'
time_a = datetime.datetime.now()
sleep 10 # Replace with whatever code needs to be timed.
@catichenor
catichenor / fade_edges-pythonista.py
Last active January 10, 2017 03:44
Pythonista: PIL/Pillow fade image edges
from PIL import Image, ImageDraw, ImageFilter
import dialogs
import console
import photos
assets = photos.pick_asset(title='Pick some assets', multi=True)
for this_asset in assets:
im = this_asset.get_image()
im = im.convert('RGBA')
settings = {}