Skip to content

Instantly share code, notes, and snippets.

@ericness
ericness / sum_api.py
Created July 26, 2023 12:34
FastAPI to sum a list of numbers.
app = FastAPI()
class Numbers(BaseModel):
numbers: List[float]
@app.post("/sum/")
async def sum_payload(nums: Numbers) -> JSONResponse:
"""Sum a list of numbers."""
result = sum(nums.numbers)
@ericness
ericness / eric_ness_linkedin_profile.json
Created May 28, 2023 23:01
JSON from LinkedIn profile for testing Langchain
{
"public_identifier": "ericnessdata",
"profile_pic_url": "https://s3.us-west-000.backblazeb2.com/proxycurl/person/ericnessdata/profile?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=0004d7f56a0400b0000000001%2F20230528%2Fus-west-000%2Fs3%2Faws4_request&X-Amz-Date=20230528T225639Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=fbeb1506bcd70a2ad22de7953eb24793afe65c5f6618ad47e0e15c293a28be75",
"background_cover_image_url": "https://s3.us-west-000.backblazeb2.com/proxycurl/person/ericnessdata/cover?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=0004d7f56a0400b0000000001%2F20230528%2Fus-west-000%2Fs3%2Faws4_request&X-Amz-Date=20230528T225639Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=20ed017262c2885e72c7539aefa906971fd3d529dad43dbc9a48581ed8ab437e",
"first_name": "Eric",
"last_name": "Ness",
"full_name": "Eric Ness",
"follower_count": 1554,
"occupation": "Principal Machine Learning Engineer at C.H. Robinson",
"headline": "Principal Machine
@ericness
ericness / 647_palindromic_substrings.py
Created March 31, 2022 00:59
LeetCode 647 optimal solution
class Solution:
def countSubstrings(self, s: str) -> int:
"""Find number of palindromic strings in s
Args:
s (str): String to analyze
Returns:
int: Count of palindromes
"""
@ericness
ericness / 647_palindromic_substrings.py
Created March 27, 2022 02:43
LeetCode 647 Brute force solution
class Solution:
def countSubstrings(self, s: str) -> int:
"""Find number of palindromic strings in s
Args:
s (str): String to analyze
Returns:
int: Count of palindromes
"""
@ericness
ericness / 19_remove_nth_node_from_end_of_list.py
Created March 27, 2022 02:00
LeetCode 19 two pointer solution
from typing import Optional
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution:
@ericness
ericness / 19_remove_nth_node_from_end_of_list.py
Created March 26, 2022 03:12
LeetCode 19 One Pass Solution
from typing import Optional
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution:
if current == head and node_to_remove == 0:
head = current.next
elif current.next:
current.next = current.next.next
else:
current.next = None
@ericness
ericness / 19_remove_nth_node_from_end_of_list.py
Created March 24, 2022 22:43
LeetCode 19 Two Pass attempt 1
from typing import Optional
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution:
@ericness
ericness / 200_number_of_islands.py
Created March 21, 2022 23:12
200 BFS solution
import collections
from enum import Enum
from typing import List, Set, Tuple
Node = collections.namedtuple("Node", "row col")
Direction = collections.namedtuple("Direction", "rows_down cols_right")
DIRECTIONS = [
Direction(-1, 0),
Direction(1, 0),
@ericness
ericness / pyinstrument.txt
Created March 21, 2022 23:11
LeetCode 200 pyinstrument output
_ ._ __/__ _ _ _ _ _/_ Recorded: 18:04:16 Samples: 277
/_//_/// /_\ / //_// / //_'/ // Duration: 0.277 CPU time: 0.277
/ _/ v4.1.1
Program: 200_number_of_islands.py
0.277 <module> <string>:1
[4 frames hidden] <string>, runpy
0.277 _run_code runpy.py:64
└─ 0.277 <module> 200_number_of_islands.py:8