Skip to content

Instantly share code, notes, and snippets.

💸
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.
Block or report user

Report or block toddbirchard

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@toddbirchard
toddbirchard / TwitterWidget.js
Last active Mar 7, 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 { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
const TwitterWidget = ({ data }) => {
const tweets = data.tweets.edges
const twitterProfile = data.twitterProfile.user
return (
@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 Mar 28, 2019
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 = []
@toddbirchard
toddbirchard / animated-terminal-session.markdown
Created Mar 13, 2019
Animated Terminal Session For Linkbox API
View animated-terminal-session.markdown
View boto3_optimize_cdn.py
import os
import json
import boto3
from botocore.client import Config
import botocore
from urllib.parse import unquote
import PIL
# Initialize a session using DigitalOcean Spaces.
@toddbirchard
toddbirchard / main.py
Created Feb 2, 2019
Google BigQuery: Create a Table With an Auto-generate Schema
View main.py
from google.cloud import storage
from google.cloud import bigquery
import pprint
bucket_uri = 'gs://your-bucket/'
bucket_name = 'your-bucket'
bucket_target = 'datasets/data_upload.csv'
local_dataset = 'data/test.csv'
bucket_target_uri = bucket_uri + bucket_target
You can’t perform that action at this time.