Skip to content

Instantly share code, notes, and snippets.

@gusostow
gusostow / logging_meta.py
Created February 25, 2024 04:02
Logging metaclass compatible with super()
import inspect
from functools import wraps
def _log_method(method):
@wraps(method)
def wrapped(self, *a, **kw):
doc = {
# module where class was defined
"module": type(self).__module__,
from collections import Counter
def pad(board):
"""
Zero-pad a square board
"""
n = len(board)
return [[0] * (n + 2)] + [[0, *row, 0] for row in board] + [[0] * (n + 2)]
@gusostow
gusostow / sudoku.py
Last active July 2, 2020 20:50
Solve 9x9 Sudoku with a tree-based backtracking algorithm
"""Solve 9x9 Sudoku with a tree-based backtracking algorithm
Approach:
- On an empty cell select an available digit and move on.
- If there isn't an available digit then backtrack to the
previous cell to try a different available digit.
- If there is a valid digit for the last cell then the game is solved.
Implementation:
Model a solution as a particular path down a tree, where
CREATE ROLE writeaccess;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO writeaccess;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO writeaccess;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO writeaccess;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE, SELECT ON SEQUENCES TO writeaccess;
CREATE USER admin WITH PASSWORD 'password';
GRANT writeaccess TO admin;
@gusostow
gusostow / gist:3ebea3956a05e20b69628c9eddcea332
Created December 10, 2019 15:45
Vanilla pyproject.toml
[tool.poetry]
name = "example"
version = "0.1.0"
description = ""
authors = ["Gus Ostow <ostowster@gmail.com>"]
[tool.poetry.dependencies]
python = "^3.7"
[tool.poetry.dev-dependencies]
@gusostow
gusostow / gist:20cca38284a000bfac874abfa1730411
Created December 10, 2019 15:45
Vanilla pyproject.toml
[tool.poetry]
name = "example"
version = "0.1.0"
description = ""
authors = ["Gus Ostow <ostowster@gmail.com>"]
[tool.poetry.dependencies]
python = "^3.7"
[tool.poetry.dev-dependencies]
@gusostow
gusostow / longest_fib_subsequence.py
Created October 14, 2019 00:29
Leetcode problem
from itertools import combinations
class Solution:
def lenLongestFibSubseq(self, A: List[int]) -> int:
"""
Brute force solution
"""
terms = set(A)
max_len = 0 # max length is 0 unless there's a sequence > 3 long
[tool.poetry]
name = "db_scripts"
version = "0.1.0"
description = ""
authors = ["Gus Ostow <ostowster@gmail.com>"]
[tool.poetry.dependencies]
python = "=3.6.8"
numpy = "1.16.4"
pandas = "=0.24.2"