Skip to content

Instantly share code, notes, and snippets.

View toddbirchard's full-sized avatar
📝
Working, learning, writing tutorials inspired by items 1 and 2.

Todd Birchard toddbirchard

📝
Working, learning, writing tutorials inspired by items 1 and 2.
View GitHub Profile
@toddbirchard
toddbirchard / Makefile
Last active December 27, 2023 05:24
Makefile template for Python projects
PROJECT_NAME := $(shell basename $CURDIR)
VIRTUAL_ENVIRONMENT := $(CURDIR)/.venv
LOCAL_PYTHON := $(VIRTUAL_ENVIRONMENT)/bin/python3
define HELP
Manage $(PROJECT_NAME). Usage:
make run - Run $(PROJECT_NAME) locally.
make dev - Run $(PROJECT_NAME) in development mode.
make install - Create local virtualenv & install dependencies.
@toddbirchard
toddbirchard / ghostupdate.sh
Last active September 24, 2021 16:57
Update Ghost & Add Storage Adapter
#!/bin/bash
PROJECT=$(pwd)
CURRENT_GHOST_VERSION=$(ghost version)
NEW_GHOST_VERSION=$(ghost check-update)
# Ensure latest NPM & Ghost CLI versions
echo "Getting latest version of NPM & Ghost-ClI"
sudo npm install -g npm@latest
sudo npm install -g ghost-cli@latest
@toddbirchard
toddbirchard / GithubWidget.js
Created August 5, 2020 02:38
Gatsby Widget: Github organization top repositories
import React from 'react'
import PropTypes from 'prop-types'
import { StaticQuery, graphql } from 'gatsby'
import { FaGithub, FaCode, FaStar, FaCodeBranch, FaProjectDiagram } from 'react-icons/fa'
/**
* Github widget
*/
const GithubWidget = ({ data }) => {
@toddbirchard
toddbirchard / Makefile
Last active July 20, 2023 19:17
Python Makefile Template
PROJECT_NAME := $(shell basename $CURDIR)
VIRTUAL_ENVIRONMENT := $(CURDIR)/.venv
LOCAL_PYTHON := $(VIRTUAL_ENVIRONMENT)/bin/python3
PROJECT_ENTRY_POINT := $(shell $CURDIR)/main.py
define HELP
Manage $(PROJECT_NAME). Usage:
make run - Run $(PROJECT_NAME) locally.
@toddbirchard
toddbirchard / TwitterWidget.js
Last active August 4, 2020 04:40
Twittter widget for GatsbyJS displaying tweets from a user's profile. Based on the tutorial: https://hackersandslackers.com/custom-twitter-widget-in-gatsbyjs/
import React from 'react'
import PropTypes from 'prop-types'
import { StaticQuery, graphql } from 'gatsby'
import { FaTwitter, FaUsers, FaRetweet, FaHeartbeat, FaReply } from 'react-icons/fa'
import { AiOutlineCalendar } from 'react-icons/ai'
const TwitterWidget = ({ data }) => {
const tweets = data.tweets.edges
const twitterProfile = data.twitterProfile.user
const twitterProfileURL = `https://twitter.com/${twitterProfile.screen_name}/`
@toddbirchard
toddbirchard / pandas_dataframe_difference.py
Last active August 26, 2023 00:48
Helper function to compare two DataFrames and find rows which are unique or shared.
"""Find Symmetric Differences between two Pandas DataFrames."""
def dataframe_difference(df1, df2, which=None):
"""Find rows which are different."""
comparison_df = df1.merge(
df2,
indicator=True,
how='outer'
)
@toddbirchard
toddbirchard / config.py
Last active August 26, 2023 01:26
Collects locally stored images listed in report generated from `https://www.deadlinkchecker.com/`
"""Script configuration."""
from os import path
BASE_DIR = path.abspath(path.dirname(__file__))
# CSV Exported from `deadlinkchecker`
CSV_EXPORTED_BROKEN_LINKS = f"{BASE_DIR}/data/brokenlinks.csv"
@toddbirchard
toddbirchard / timeit.py
Last active August 26, 2023 00:56
Python Decorator to determine execution time of a given function
"""Decorator to determine execution time of a given function."""
from time import time
def timeit(method: func):
"""Print execution time of decorated function."""
def timed(*args, **kw):
ts = time()
result = method(*args, **kw)
import sys
import pymysql
import logging
class Database:
"""Database connection class."""
def __init__(self, config):
self.host = config.db_host