Skip to content

Instantly share code, notes, and snippets.

View jefftriplett's full-sized avatar
Living the dream

Jeff Triplett jefftriplett

Living the dream
View GitHub Profile
@jefftriplett
jefftriplett / 1_hello_in_vanilla_python.py
Last active December 8, 2023 19:22
What `hello.py world` looks like in vanilla python, as a django management command, and using the Typer library to show a basic example of using Python Types.
import sys
def main():
# Check if a name argument is provided
if len(sys.argv) > 1:
name = sys.argv[1]
else:
name = "World" # Default name if no argument is provided
print(f"Hello, {name}!")
@jefftriplett
jefftriplett / .pre-commit-config.yaml
Last active November 7, 2023 14:10
👕 How to get ruff to work with checking and formatting?
...
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
...
# https://medium.com/@dave1010/amazingly-alarming-autonomous-ai-agents-62f8a785e4d8
# https://github.com/dave1010/hubcap
# to run we need a few libraries:
# pip install rich typer
import os
import subprocess
import sys
import time
@jefftriplett
jefftriplett / demo-youtube-playlist-to-markdown.py
Last active January 1, 2024 11:18
A YouTube Playlist to Markdown automation
"""
----------------------------------------------------------------------------
Author: Jeff Triplett <https://github.com/jefftriplett>
Copyright (c) 2023 - Jeff Triplett
License: PolyForm Noncommercial License 1.0.0 - https://polyformproject.org/licenses/noncommercial/1.0.0/
----------------------------------------------------------------------------
1. To extract video URLs, titles, and descriptions from a YouTube playlist using Python, you can use the google-api-python-client library. Here's a step-by-step guide on how to do this:
Install the google-api-python-client library:
@jefftriplett
jefftriplett / chatgpt.py
Last active March 1, 2023 20:14
ChatGPT API using their OpenAI Python library to generate a TailwindCSS template
# https://platform.openai.com/docs/guides/chat/chat-vs-completions
#
# python -m pip install openai
#
import openai
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
@jefftriplett
jefftriplett / .env-dist
Last active January 14, 2023 18:42
Using 1password and with ENV variables for Django via a justfile
ADMIN_URL=op://django-news/$APP_ENV/ADMIN_URL
ALLOWED_HOSTS=op://django-news/$APP_ENV/ALLOWED_HOSTS
AWS_ACCESS_KEY_ID=op://django-news/$APP_ENV/AWS_ACCESS_KEY_ID
CURATED_API_KEY=op://django-news/$APP_ENV/CURATED_API_KEY
CURATED_PUBLICATION_KEY=op://django-news/$APP_ENV/CURATED_PUBLICATION_KEY
DATABASE_URL=op://django-news/$APP_ENV/DATABASE_URL
DJANGO_DEBUG=op://django-news/$APP_ENV/DJANGO_DEBUG
USE_S3=op://django-news/$APP_ENV/USE_S3
description newsletter number published title url
PSF News, building a desktop app with Django + Electron, Meilisearch, bulk admin actions, and more!
Django News
160
2022-12-30 11:00:00 +0000
Happy Django New Year!
@jefftriplett
jefftriplett / drf_prefix_mixin.py
Created June 17, 2022 19:30
Example DRF Prefix Mixin for accepted a dict() that might have a model prefix.
class PrefixedMixin:
def __init__(self, *args, **kwargs):
self._prefix = kwargs.pop("prefix", None)
super().__init__(*args, **kwargs)
def to_internal_value(self, data):
"""Dict of native values <- Dict of primitive datatypes."""
if self._prefix:
data = {
key.replace(f"{self._prefix}_", ""): value
@jefftriplett
jefftriplett / code--list-extensions.sh
Created July 28, 2021 17:21
VS Code --list-extensions
❯ code --list-extensions
azemoh.one-monokai
bibhasdn.django-html
bokuweb.vscode-ripgrep
bradlc.vscode-tailwindcss
citycide.theme-material-cosmos
cschleiden.vscode-github-actions
DavidAnson.vscode-markdownlint
donjayamanne.githistory
dracula-theme.theme-dracula
@jefftriplett
jefftriplett / justfile-alfred.py
Last active March 19, 2024 17:31
Example Justfile Alfred Extension
"""
2021-2024 - Jeff Triplett
gist: https://gist.github.com/jefftriplett/e7d4eade12e30001065eed2636010772
pip install typer pydantic
Inspired/jumpstarted by: https://github.com/kjaymiller/Bunch_Alfred
"""