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
Created Oct 31, 2019
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'
const TwitterWidget = ({ data }) => {
const tweets = data.allTwitterStatusesUserTimelineHackersTweets.edges
const user = data.twitterStatusesUserTimelineHackersTweets.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
View fake.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 7 should actually have 11 columns, instead of 4. in line 6.
id,initiated,hiredate,email,firstname,lastname,title,department,location,country,type
100035435,2015-12-11T09:16:20.722-08:00,3/22/67,GretchenRMorrow@jourrapide.com,Gretchen,Morrow,Power plant operator,Physical Product,Britling Cafeterias,United Kingdom,Employee
100056435,2015-12-15T10:11:24.604-08:00,6/22/99,ElizabethLSnow@armyspy.com,Elizabeth,Snow,Oxygen therapist,Physical Product,Grade A Investment,United States of America,Employee
100037955,2015-12-16T14:31:32.765-08:00,5/31/74,AlbertMPeterson@einrot.com,Albert,Peterson,Psychologist,Physical Product,Grass Roots Yard Services,United States of America,Employee
100035435,2016-01-20T11:15:47.249-08:00,9/9/69,JohnMLynch@dayrep.com,John,Lynch,Environmental hydrologist,Physical Product,Waccamaw's Homeplace,United States of America,Employee
100057657,2016-01-21T12:45:38.261-08:00,4/9/83,TheresaJCahoon@teleworm.us,Theresa,Cahoon,Personal chef,Physical Product,Cala Foods,United States of America,Employee
100056747,2016-02-01T11:25:39.317-08:00,6/26/98,KennethHPayn
You can’t perform that action at this time.