Skip to content

Instantly share code, notes, and snippets.

View catichenor's full-sized avatar

Christopher Tichenor catichenor

View GitHub Profile
@catichenor
catichenor / human-date-parser.py
Last active August 8, 2018 17:24
Command to parse a human date description and output a date.
#!/usr/bin/python
from __future__ import print_function # Need to grab the print function from Python 3.
import parsedatetime # Requires "parsedatetime" Python module
from datetime import datetime
import argparse
argparser = argparse.ArgumentParser()
@catichenor
catichenor / pomodoro_win.py
Last active July 25, 2022 16:58
Simple Pomodoro timer with Windows notifications
#!/usr/bin/env python
# ------ #
# Requires notify-send: http://vaskovsky.net/notify-send/
# To link it to this script, download notify-send,
# get the path of the `notify-send.exe` file,
# and paste it into the "notify_send_path" variable.
# ------ #
# Work for 25 minutes, break for 5 minutes.
@catichenor
catichenor / output_nvidia_driver_version.sh
Created December 22, 2016 02:47
Output the version of the installed NVIDIA driver
#!/bin/sh
nvidia-smi -q | grep "Driver Version" | awk '{ print $NF }'
@catichenor
catichenor / resultswriter.py
Last active December 28, 2016 01:49
Python example to extract results from a log file and write to a CSV
import re
import csv
import fnmatch
from os import listdir
from os.path import basename, splitext
file_list = []
for dir_file in listdir('.'):
if fnmatch.fnmatch(dir_file, '*.log'):
file_list.append(dir_file)
@catichenor
catichenor / testkeygen.py
Created December 29, 2016 19:12
Key generator test in Python
#!/usr/bin/python
import random
# int((random.random() * 90000) + 10000) # Yields numbers between 10000 and 99999
def numCheck(inDict):
inputLength = len(inDict)
while len(inDict) == inputLength:
try:
@catichenor
catichenor / separate_json.sh
Last active January 17, 2017 21:42
Separate JSON in sed
# It's better to use [jq](https://stedolan.github.io/jq/) for this instead.
# `jq '.' /path/to/jsonfile.json | less` shows a JSON file in less
cat jsonfile.json | sed 's/\}, /}, \'$'\n/g' | less # Uses an old-school escape sequence to get a real newline.
@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 = {}
@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 / 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 / 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.