Skip to content

Instantly share code, notes, and snippets.

View krummja's full-sized avatar

Jonathan Crum krummja

View GitHub Profile
@krummja
krummja / make_reqs.py
Created March 9, 2023 14:29
Script to execute poetry pyproject.toml to requirements.txt for Heroku deployment
from __future__ import annotations
from beartype.typing import *
if TYPE_CHECKING:
from subprocess import CompletedProcess
import subprocess
def run(cmd: str) -> CompletedProcess[bytes]:
return subprocess.run(
from __future__ import annotations
from typing import *
from types import TracebackType
if TYPE_CHECKING:
from requests import Request, Response
import json
import requests
from enum import Enum
@krummja
krummja / structural_pattern_matching.py
Created December 9, 2022 15:29
Python 3.10+ Structural Pattern Matching
from __future__ import annotations
from typing import NamedTuple
class Point2D(NamedTuple):
x: int
y: int
class Point3D(NamedTuple):
def inspect_companies(
start: int = 0,
stop: int = 100
) -> Generator[Dict[str, Any]]:
"""Generator function to page through Hubspot contacts.
: param int start : The start page of the
: param int stop :
"""
@krummja
krummja / planet-generation.js
Created June 5, 2022 05:20
Delaunay Voronoi Sphere (from RedBlobGames)
/*
* From https://www.redblobgames.com/x/1843-planet-generation/
* Copyright 2018 Red Blob Games <[email protected]>
* License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
*/
'use strict';
/* global Delaunator, createREGL, vec3, mat4 */
const regl = createREGL({
-- Export Companies from Hubspot
-- Create a new table and import the CSV data
-- Create a new table with all Contact info, where we'll add the Company Hubspot ID as "Company HID"
-- Select all from existing contacts table
-- Left Join the table created from the exported CSV where contact company_id = exported Company EID
create table contacts_add_company_hid
as
select *
from defaultdb_public_contacts
---
--- Combine tables in preparation for CSV export.
---
-- Stage 1: contacts, accounts => full join
-- ----------------------------------------
-- We need to make a new table that consists of all contacts and all companies,
-- since not all companies have associated contacts and vice-versa.
create table all_contacts_and_companies
create table combined_accounts_contacts
as select A.*,
B.company_id,
B.first_name,
B.last_name
from defaultdb_public_accounts A
full join defaultdb_public_contacts B
on A.external_id = B.company_id;
select cdomain
into temp duplicates_2
from accounts
group by cdomain
having count(*) > 1;
select *
from duplicates_2
full join accounts
on duplicates_2.cdomain = accounts.cdomain;
@krummja
krummja / request_loop.py
Created April 5, 2022 20:09
hubspot company request loop
def inspect_companies(
start: int = 0,
stop: int = 500
) -> Generator[Dict[str, Any]]:
if start > stop:
raise Exception(f"Expected start value less than stop. " +
f"Got {start} > {stop}")
url = "https://api.hubapi.com/crm/v3/objects/companies/search?"