Skip to content

Instantly share code, notes, and snippets.

View a-toms's full-sized avatar
🌱
Ecstatic!

Tom a-toms

🌱
Ecstatic!
View GitHub Profile
title description created_at
Add comments to Django in 9 mins (using HTMX) 🧵
Let people leave comments in your Django app, with HTMX to make it interactive.
2024-03-27 03:31:06 -0700

We'll build a simple app that shows user comments in 9 minutes. This includes:

  • allowing users to add comments and reply to comments.
  • showing each user's profile image (using the Gravatar API).
  • adding sample comments into the Django database from yaml (using the Django loaddata management command).
@a-toms
a-toms / gist:9450829b0a6be1ceeb7016e898fa7fc9
Created March 21, 2024 13:40
Telegram bot notifications for HeyFocus when starting, stopping, pausing, and resuming pomodoros
# Started tomato.
MINUTES_REMAINING=$(awk "BEGIN {print int($FOCUS_SESSION_INTENDED_DURATION/60)}") # Bash doesn't support floating point arithmetic, so we use awk to round down to the nearest integer
MESSAGE="🍅 *Tomato started* 🍅\n Tomato due to finish at $FOCUS_SESSION_END_DATE ($MINUTES_REMAINING minutes left).\n\n"
curl -X POST \
-H 'Content-Type: application/json' \
-d "{\"chat_id\": \"<YOUR_CHAT_ID>\", \"text\": \"$MESSAGE\", \"disable_notification\": false, \"parse_mode\": \"Markdown\"}" \
https://api.telegram.org/bot<BOT_API_TOKEN>/sendMessage
# Completed tomato.
@a-toms
a-toms / css_to_dictionary.py
Last active February 13, 2024 13:04
Convert a css string to python dictionary in a simple, robust manner
import tinycss2
from tinycss2.ast import WhitespaceToken
from tinycss2 import serialize
def css_to_dict(css: str) -> Dict[str, str]:
"""
Convert a CSS string to a dictionary of CSS attributes.
"""
return {
@a-toms
a-toms / _replace_this_with_an_environment_variable_in_production_4_2_run_your_serverless_function_locally_2.txt
Created September 14, 2023 17:27
# Replace this with an environment variable in production. - ## 4.2 Run your serverless function locally
Event = {'body': {'task_id': 1}, 'httpMethod': 'POST'}
Received task_id 1
Completed task_id 1
END RequestId: ac4d9b48-9675-4513-881b-d5a89d801035
REPORT RequestId: ac4d9b48-9675-4513-881b-d5a89d801035 Init Duration: 0.76 ms Duration: 3895.27 ms Billed Duration: 3896 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"status_code": 404, "body": "{\"status\": \"task does not exist\"}"}%
@a-toms
a-toms / _replace_this_with_an_environment_variable_in_production_4_2_run_your_serverless_function_locally_1.txt
Created September 14, 2023 17:27
# Replace this with an environment variable in production. - ## 4.2 Run your serverless function locally
sam build
sam local invoke --event events/event.json
@a-toms
a-toms / _replace_this_with_an_environment_variable_in_production_4_2_run_your_serverless_function_locally_0.txt
Created September 14, 2023 17:27
# Replace this with an environment variable in production. - ## 4.2 Run your serverless function locally
{
"body": {"task_id": 1},
"httpMethod": "POST"
}
@a-toms
a-toms / _section_3_add_your_serverless_function_troubleshooting_sam_local_invoke__0.txt
Created September 14, 2023 17:27
# Section 3: Add your serverless function - ### Troubleshooting `sam local invoke`
"Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running?"
@a-toms
a-toms / _section_3_add_your_serverless_function_3_3_run_your_serverless_function_locally_1.txt
Created September 14, 2023 17:27
# Section 3: Add your serverless function - ## 3.3 Run your serverless function locally
{"statusCode": 200, "body": "{\"message\": \"hello world\"}"}
@a-toms
a-toms / _section_3_add_your_serverless_function_3_3_run_your_serverless_function_locally_0.txt
Created September 14, 2023 17:27
# Section 3: Add your serverless function - ## 3.3 Run your serverless function locally
bash
sam local invoke
@a-toms
a-toms / _section_3_add_your_serverless_function_3_2_build_your_serverless_function_0.txt
Created September 14, 2023 17:27
# Section 3: Add your serverless function - ## 3.2 Build your serverless function
bash
cd sam-app
sam build