Skip to content

Instantly share code, notes, and snippets.

View ddanier's full-sized avatar
🤩
Code, sleep, repeat.

David Danier ddanier

🤩
Code, sleep, repeat.
View GitHub Profile
@ddanier
ddanier / class_or_instance_method.py
Last active July 10, 2020 18:46
Python class_or_instance_method decorator, passes cls and self (if available)
from typing import Callable, Type
import functools
class class_or_instance_method:
func: Callable
def __init__(self, func: Callable):
self.func = func
@ddanier
ddanier / fastapi_globals.py
Last active May 15, 2024 19:53
flask.g for FastAPI.
"""
This allows to use global variables inside the FastAPI application using async mode.
# Usage
Just import `g` and then access (set/get) attributes of it:
```python
from your_project.globals import g
@ddanier
ddanier / git-cc.nu
Last active June 23, 2024 18:37
Conventional commit as `git cc` custom command for nu shell
# This nu modules adds "git cc" to create commits following the conventional commit schema, see
# https://www.conventionalcommits.org/en/v1.0.0/
#
# Example usage:
# git cc -t feat -s my-feature -i my-issue -m "My feature"
# git cc fix -s my-fix -m "My fix"
#
# Is uses a slightly extended version of conventional commits to also include a commit type
# emoji and a commit issue. The commit scope will be inferred from the current git status,
# using changes folder names by default (using the "git cc-get-scope" command also provided
@ddanier
ddanier / nurify.nu
Last active June 15, 2024 10:16
Create `nurfile` containing all tasks/commands from `justfile` when using `just` or `build/Taskfile` when using `b5`. Use https://github.com/ddanier/nur/blob/main/scripts/nurify.nu for latest version.
# IMPORTANT:
# An up to date version is available here: https://github.com/ddanier/nur/blob/main/scripts/nurify.nu
# How I installed this:
# > mkdir $env.NU_LIB_DIRS.0
# > vim ($env.NU_LIB_DIRS.0 | path join "nurify.nu")
# PUT CODE IN HERE
# > vim $nu.config-path
# Add `use nurify.nu *` at the end