Skip to content

Instantly share code, notes, and snippets.

View douglasmiranda's full-sized avatar
👽

Douglas Miranda douglasmiranda

👽
  • Earth, Brazil
View GitHub Profile
@douglasmiranda
douglasmiranda / mutool.md
Last active October 3, 2024 18:05
Clean and output all pages but the first one.

Today (2024-10-02) the docs for mutool clean just doesn't include proper info for this.

mutool clean a.pdf b.pdf 2-N

In the Ubuntu page, there's a better description:

From Ubuntu Man pages:

@douglasmiranda
douglasmiranda / Dockerfile
Created October 3, 2024 00:57
ttf-mscorefonts-installer on Debian 12 - Dockerfile
# For errors like:
# Package 'ttf-mscorefonts-installer' has no installation candidate
# You could always do like the entire internet gonna tell you
# just add contrib to your /etc/apt/sources.list
# example for debian 12
# echo "deb http://deb.debian.org/debian bookworm main contrib" >> /etc/apt/sources.list
# But that can mess with your other dependencies
# In my case was PrinceXML and it's dependencies.
@douglasmiranda
douglasmiranda / install.sh
Created October 2, 2024 00:22
Install MuPDF (cli only)
wget https://mupdf.com/downloads/archive/mupdf-1.24.9-source.tar.gz -O /mupdf-source.tgz && \
cd / && tar -zxf mupdf-source.tgz && rm mupdf-source.tgz && \
cd /mupdf-1.24.9-source && make HAVE_X11=no HAVE_GLUT=no prefix=/usr install && \
rm -rf /mupdf-1.24.9-source /var/lib/apt/lists/*
@douglasmiranda
douglasmiranda / calculate.py
Created October 1, 2024 03:55
PyMuPDF - Calculate the percentage of the page height filled with text blocks.
from dataclasses import dataclass
import pymupdf
@dataclass
class Margin:
"""Margin in points
1 inch = 72 points
1 cm = 28.35 points
@douglasmiranda
douglasmiranda / forms.py
Created September 10, 2024 02:29
Django BaseInlineFormset custom attributes to DELETE button
class ScheduleInlineFormSet(BaseInlineFormSet):
def add_fields(self, form, index):
super().add_fields(form, index)
# customizing for bootstrap needs
if "DELETE" in form.fields:
form.fields["DELETE"] = forms.BooleanField(
label="Excluir",
widget=forms.CheckboxInput(attrs={"class": "btn-check"}),
required=False,
)
@douglasmiranda
douglasmiranda / forms.py
Created September 10, 2024 02:26
Django forms.MultiWidget dict example
# this dict can be accessed in get_context()
{
"widget": {
"name": "publishing_dates",
"is_hidden": False,
"required": False,
"value": "[datetime.date(2024, 9, 5), datetime.date(2024, 9, 6), datetime.date(2024, 9, 7), datetime.date(2024, 9, 8)]",
"attrs": {
"class": "form-control",
"placeholder": "Data de publicação",
@douglasmiranda
douglasmiranda / nolabelsuffix.py
Created August 29, 2024 00:06 — forked from jleeothon/nolabelsuffix.py
Change label suffix for Django forms
# have all your forms extend this mixin
class NoLabelSuffixMixin:
def __init__(self, *args, **kwargs):
if 'label_suffix' not in kwargs:
kwargs['label_suffix'] = ''
super(NoLabelSuffixMixin, self).__init__(*args, **kwargs)
@douglasmiranda
douglasmiranda / extract_date_from_string.py
Created August 21, 2024 02:25
python - extract date from string (and return the format of matching)
from dataclasses import dataclass
from datetime import datetime
# This is basically a draft
# it works, it's just very simplistic
# looks for a single occurrence; match; return
# The main goal it's just parse the date and have control of
# the format I matched.
# Example: read autocomplete field and trigger a search when
# the search term match at least the dd/mm (%d/%m) format.
@douglasmiranda
douglasmiranda / warp.md
Last active August 18, 2024 03:23
Cloudflare Warp useful links
@douglasmiranda
douglasmiranda / templatetags.py
Created August 16, 2024 01:05 — forked from benbacardi/templatetags.py
Django query_transform templatetag
from django import template
register = template.Library()
@register.simple_tag(takes_context=True)
def query_transform(context, **kwargs):
'''
Returns the URL-encoded querystring for the current page,
updating the params with the key/value pairs passed to the tag.