Skip to content

Instantly share code, notes, and snippets.

Avatar
💸
Building open-source projects that I should really be charging money for.

Todd Birchard toddbirchard

💸
Building open-source projects that I should really be charging money for.
View GitHub Profile
@toddbirchard
toddbirchard / ghostupdate.sh
Last active May 23, 2021
Update Ghost & Add Storage Adapter
View ghostupdate.sh
#!/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 Aug 5, 2020
Gatsby Widget: Github organization top repositories
View GithubWidget.js
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 May 4, 2021
Python uWSGI Makefile
View Makefile
SRCPATH := $(shell pwd)
PROJECTNAME := $(shell basename $(CURDIR))
ENTRYPOINT := $(PROJECTNAME).ini
VIRTUAL_ENVIRONMENT := $(CURDIR)/.venv
LOCAL_PYTHON := $(VIRTUAL_ENVIRONMENT)/bin/python3
define HELP
Manage $(PROJECTNAME). Usage:
make run - Run $(PROJECTNAME) by assuming a systemd service exists.
@toddbirchard
toddbirchard / TwitterWidget.js
Last active Aug 4, 2020
Twittter widget for GatsbyJS displaying tweets from a user's profile. Based on the tutorial: https://hackersandslackers.com/custom-twitter-widget-in-gatsbyjs/
View TwitterWidget.js
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
Created Oct 20, 2019
Helper function to compare two DataFrames and find rows which are unique or shared.
View pandas_dataframe_difference.py
def dataframe_difference(df1, df2, which=None):
"""Find rows which are different."""
comparison_df = df1.merge(df2,
indicator=True,
how='outer')
if which is None:
diff_df = comparison_df[comparison_df['_merge'] != 'both']
else:
diff_df = comparison_df[comparison_df['_merge'] == which]
diff_df.to_csv('data/diff.csv')
View find_dead_link_images.py
View timeit.py
def timeit(method):
"""Print execution time of decorated function."""
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
if 'log_time' in kw:
name = kw.get('log_name', method.__name__.upper())
kw['log_time'][name] = int((te - ts) * 1000)
else:
View pymysql_tutorial.py
import sys
import pymysql
import logging
class Database:
"""Database connection class."""
def __init__(self, config):
self.host = config.db_host
@toddbirchard
toddbirchard / image_optimize.py
Last active Nov 14, 2020
Recursively retrieve all images in a given site, generate retina images, convert all images to webp format.
View image_optimize.py
import os
import json
import glob
import PIL
from PIL import Image
def get_all_images():
"""Create an array of PNGs and JPGs."""
img_arr = []