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 / image_optimize.py
Last active December 7, 2021 00:25
Recursively retrieve all images in a given site, generate retina images, convert all images to webp format.
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 March 13, 2019 12:55
Animated Terminal Session For Linkbox API
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 February 2, 2019 03:53
Google BigQuery: Create a Table With an Auto-generate Schema
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
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
"""Extract nested values from a JSON tree."""
def json_extract(obj, key):
"""Recursively fetch values from nested JSON."""
arr = []
def extract(obj, arr, key):
"""Recursively search for values of key in JSON tree."""
if isinstance(obj, dict):
@toddbirchard
toddbirchard / pwning_tableau.py
Last active April 26, 2020 07:17
Source code to extract data from your Tableau server instance. See this article: https://hackersandslackers.com/tableaus-rest-api-turning-tableau-into-an-etl-pipeline-gui/
import requests
import xml.etree.ElementTree as ET
from . import r
import pandas as pd
import io
class ExtractTableauView:
"""Class for with the Tableau server API."""
@toddbirchard
toddbirchard / .hyper.js
Last active April 1, 2019 02:03
hyper terminal preferences
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',
@toddbirchard
toddbirchard / atom_preferences.json
Last active April 1, 2019 19:48
The most mfing raw atom setup you've never seen in your life.
"*":
"activate-power-mode":
comboMode: {}
particles:
colours:
type: "random"
size:
max: 10
spawnCount:
max: 21