Skip to content

Instantly share code, notes, and snippets.

View travishathaway's full-sized avatar
🐢
Taking it slow and easy

Travis Hathaway travishathaway

🐢
Taking it slow and easy
View GitHub Profile
@travishathaway
travishathaway / file_vs_sqlite.py
Created May 19, 2022 13:13
Storing IDs in a file vs. SQLite
import os
import sys
import sqlite3
import time
import uuid
from functools import wraps
DB_FILE = 'tester.db'
FILE = 'tester.cache'
@travishathaway
travishathaway / sync_vs_async_http_requests.py
Last active February 6, 2022 15:07
Simple python script to show the differences in implementation/speed of synchronous and asynchronous approach for downloading content.
"""
Usage:
python simple_http_example.py [sync|async]
Description:
Simple python script to show the differences in implementation/speed of
synchronous and asynchronous approach for downloading content.
The output will show what was downloaded. The script repeats five
times and prints the average run speed before exiting.
#include <SPI.h>
#include <Adafruit_GPS.h>
//#include <SoftwareSerial.h>
#include <SD.h>
#include <DHT.h>
#include <avr/sleep.h>
// Ladyada's logger modified by Bill Greiman to use the SdFat library
//
// This code shows how to listen to the GPS module in an interrupt
@travishathaway
travishathaway / degree_mins_to_decimal_degrees.py
Created May 23, 2019 01:00
Convert Degree Minutes to Decimal Degrees
def convert_degree_dec_min_to_degree_dec(degree_dec_min: str):
"""
Converts a string that looks like this:
- "12238.2974W"
To this:
- -122.63829
In other words, it converts the "Degrees and Decimal Minutes" format
@travishathaway
travishathaway / mov_to_gif
Created August 3, 2018 16:58
This is a simple script using ffmpeg to convert .mov files to .gif
#! /bin/bash
#############################################################################
# Author: Travis Hathaway #
# #
# Description: #
# This is a simple script used to transform a .mov file to a .gif file #
# #
# Example: #
# mov_to_gif <mov_file> <start_time:seconds> <duration:seconds> #
# mov_to_gif your_movie.mov 5 2.5 #
import sqlite3
from functools import wraps
def sqlite_conn(func):
@wraps(func)
def wrap(self, *args, **kwargs):
conn = getattr(self, 'conn', None)
if not conn:
raise NotImplementedError(
@travishathaway
travishathaway / decorator_presentation.py
Last active June 27, 2018 20:00
This is an example that accompanies a presentation I recently gave on decorators. In this example, I show how to create decorators for managing connections to SQLite3 databases.
from functools import wraps
import sqlite3
CONN_STR = '/tmp/foo.db'
def sqlite_conn(conn_str):
def dec_func(func):
@wraps(func)
@travishathaway
travishathaway / pyscopg2_decorator.py
Last active July 9, 2023 16:38
Postgres Connections with Python Decorators
from functools import wraps
import psycopg2
####################
# Define Decorator #
####################
def psycopg2_cursor(conn_info):
"""Wrap function to setup and tear down a Postgres connection while
providing a cursor object to make queries with.
@travishathaway
travishathaway / get_report_data.sh
Created March 11, 2017 02:47
Download Civic Apps Crime Report Data
#! /bin/bash
# Author: Travis Hathaway
#
# Description:
# This file downloads crime report data from portlandoregon.gov's FTP server
# and then loads it in to a postgres database.
#
# How to use:
# Simply change the DB_* variables to fit your local installation. I assume that
# you are using a passwordless Postgres account.
#! /bin/bash
#
# Author: Travis Hathaway
#
# Description:
# This is a script that will import csv data from gathered from
# the chicago crime reports stream. More info here:
# https://data.cityofchicago.org/Public-Safety/Crimes-2001-to-present/ijzp-q8t2/data
#
# Requirements: