Skip to content

Instantly share code, notes, and snippets.

View archatas's full-sized avatar
💭
https://igg.me/at/pybazaar/x/36938670#/ - Raising funds for PyBazaar

Aidas Bendoraitis archatas

💭
https://igg.me/at/pybazaar/x/36938670#/ - Raising funds for PyBazaar
View GitHub Profile
@archatas
archatas / base.html
Created May 4, 2024 22:48
Boilerplate base.html template inspired by django-allauth
{% load i18n %}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
{% block head_title %}
{% endblock head_title %}
</title>
@archatas
archatas / combine_js.sh
Created April 29, 2024 16:48
A bash script combining remote and local JS files into one
#!/usr/bin/env bash
CURRENT_DIR=$(dirname "$0")
BASE_DIR=$CURRENT_DIR/../../..
# Define output filename
OUTPUT_FILE="$BASE_DIR/site_static/site/js/combined.js"
echo "" > $OUTPUT_FILE
@archatas
archatas / pagination.html
Created April 28, 2024 18:23
Pagination widget using TailwindCSS markup
{% load query_params_tags %}
<div class="grid md:grid-cols-12 grid-cols-1 mt-8">
<div class="md:col-span-12 text-center">
<nav aria-label="Page navigation example">
<ul class="inline-flex items-center -space-x-px">
{% if page_obj.has_previous %}
<li><a href="{% modify_query page=page_obj.previous_page_number %}" class="size-[40px] inline-flex justify-center items-center text-slate-400 bg-white dark:bg-slate-900 rounded-s-3xl hover:text-white border border-gray-100 dark:border-gray-800 hover:border-sky-600 dark:hover:border-sky-600 hover:bg-sky-600 dark:hover:bg-sky-600"><i class="uil uil-angle-left text-[20px] rtl:rotate-180 rtl:-mt-1"></i></a></li>
{% if page_obj.number > 3 %}
<li><a href="{% modify_query page=1 %}" class="size-[40px] inline-flex justify-center items-center text-slate-400 hover:text-white bg-white dark:bg-slate-900 border border-gray-100 dark:border-gray-800 hover:border-sky-600 dark:hove
@archatas
archatas / decorators.py
Created April 19, 2024 07:46
The @basic_authentication decorator for Django views
import base64
from functools import wraps
from django.conf import settings
from django.http import HttpResponse
from django.utils.encoding import force_str
def basic_authentication(function):
@wraps(function)
def wrap(request, *args, **kwargs):
@archatas
archatas / build.sh
Last active February 14, 2024 10:50
Interactive build bash script for releasing Python packages
#!/bin/bash
echo "Did you update the CHANGELOG.md and commit the changes? (y/N)"
read answer
if [[ $answer != "y" && $answer != "Y" ]]; then
echo "Please update and commit the changelog before building."
exit 1
fi
@archatas
archatas / replace_version.sh
Created February 10, 2024 20:18
Replaces semantic versions in the documentation written in Markdown format.
#!/bin/bash
# Get old and new versions
read -p "Enter old software version (major.minor.patch): " old_version
read -p "Enter new software version (major.minor.patch): " new_version
# Check if versions are valid
if ! [[ $old_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ || $new_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format. Please enter in major.minor.patch format."
exit 1
@archatas
archatas / vapid_helper.py
Created May 9, 2023 17:31 — forked from cjies/vapid_helper.py
Python based VAPID key-pair generator
import base64
import ecdsa
def generate_vapid_keypair():
"""
Generate a new set of encoded key-pair for VAPID
"""
pk = ecdsa.SigningKey.generate(curve=ecdsa.NIST256p)
vk = pk.get_verifying_key()
@archatas
archatas / og_parser.py
Created May 8, 2023 02:24
Open Graph Parser Example
from html.parser import HTMLParser
import requests
from pprint import pprint
class OpenGraphParser(HTMLParser):
"""
Parses the Open Graph tags and returns a dictionary with values:
For example,
@archatas
archatas / html_to_text.py
Created May 7, 2023 15:37
Converting HTML to plain text
import re
from html.parser import HTMLParser
class HTMLStripper(HTMLParser):
# stackoverflow.com/questions/753052/strip-html-from-strings-in-python
def __init__(self):
super().__init__()
self.reset()
self.strict = False
@archatas
archatas / forms.py
Created January 8, 2023 23:51
Password Reset for a Django Project (accounts app)
import re
from crispy_forms import layout, bootstrap
from crispy_forms.helper import FormHelper
from django import forms
from django.conf import settings
from django.contrib.auth import authenticate
from django.contrib.auth.forms import PasswordResetForm as PasswordResetFormBase
from django.contrib.auth.forms import SetPasswordForm as SetPasswordFormBase
from django.urls import reverse_lazy, reverse