Skip to content

Instantly share code, notes, and snippets.

View nicksspirit's full-sized avatar
❤️
Currently in a committed relationship with python

Nick Muoh nicksspirit

❤️
Currently in a committed relationship with python
View GitHub Profile
@jexp
jexp / graphrag-load-neo4j-1.ipynb
Last active September 8, 2024 19:28
Quick Neo4j Loaders for GraphRAG Parquet
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@willmcgugan
willmcgugan / last_lines.py
Created March 2, 2024 16:10
Get the last lines from a file
import mmap
def get_last_lines(path: str, count: int) -> list[str]:
"""Get count last lines from a file."""
with open(path, "r+b") as text_file:
text_mmap = mmap.mmap(text_file.fileno(), 0, mmap.ACCESS_READ)
position = len(text_mmap)
while count and (position := text_mmap.rfind(b"\n", 0, position)) != -1:
count -= 1
@AlexWaygood
AlexWaygood / last_n_lines.py
Last active March 10, 2024 16:30
Script to find the last `n` lines of a file
import os
from collections import deque
from collections.abc import Iterator, Sequence
from typing import Final, Protocol
class SeekableBytesFile(Protocol):
def seek(self, position: int, whence: int = ..., /) -> int: ...
def read(self, amount: int, /) -> bytes: ...
@nymous
nymous / README.md
Last active April 14, 2025 13:44
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

@getflourish
getflourish / Import CustomElements from .html files.md
Last active June 23, 2024 15:01
Import CustomElements from .html files

Import CustomElements from .html files

This is the technical implementation of the idea and concept described in my article “Why don’t we use HTML to author web components?

Instead of using template literals, constructors and other specifics to define CustomElements, this is a proposal to just use standard HTML to define CustomElements.

The goal is to import CustomElements like this:

@avi-perl
avi-perl / df_to_table.py
Last active December 15, 2022 21:27
Convert a pandas.DataFrame object into a rich.Table object for stylized printing in Python.
from datetime import datetime
from typing import Optional
import pandas as pd
from rich import box
from rich.console import Console
from rich.table import Table
console = Console()
@jamiebuilds
jamiebuilds / tradeoffs-in-value-derived-types-in-typescript.md
Last active December 16, 2022 17:21
Value-derived types in TypeScript are super powerful, but you should be thoughtful in how/when you use them

Tradeoffs in value-derived types in TypeScript

Many of the more "advanced" typescript features can be used for creating "value-derived" types.

At its simplest form:

let vehicle = { name: "Van", wheels: 4 }
@bobmayes
bobmayes / download_from_drive.py
Created August 6, 2020 21:37 — forked from lelogrott/download_from_drive.py
downloads all files in a google drive folder keeping the folder structure.
from __future__ import print_function
import pickle
import io
import argparse
import sys
import os.path
from pathlib import Path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
@jfcherng
jfcherng / st4-changelog.md
Last active August 18, 2024 07:25
Sublime Text 4 changelog just because it's not on the official website yet.
@belljustin
belljustin / split.py
Created January 26, 2018 19:40
Script to split a dataset into an 80/20 training/test set by sampling from a binomial distribution
#!/usr/bin/python
import sys
import numpy.random as rand
'''
Splits a dataset into an 80/20 train/test set by sampling from a binomial
distribution with each datapoint deciding which set it belongs to.
'''