Skip to content

Instantly share code, notes, and snippets.

View rg3915's full-sized avatar
🏠
Working from home

Regis Santos rg3915

🏠
Working from home
View GitHub Profile
@rg3915
rg3915 / README.md
Last active January 13, 2024 04:27 — forked from vallahor/README.md
Given a txt file with a tree structure of directories/files generate a sh with necessary commands to generate that file tree

sh from txt contains tree structure of directories and files

How to create sh commands from txt file contains tree structure of directories and files?

This program convert tree structure of directories and files generate a sh with necessary commands to generate that file tree.

He read input.txt and convert to output.sh.

This is result:

@rg3915
rg3915 / table-emmet
Created December 19, 2022 03:43 — forked from anthanh/table-emmet
Emmet table example
table[name="pepe"]>thead>tr>th*3^^+tbody>tr*7>td{Basico}*3
@rg3915
rg3915 / apps.py
Created September 13, 2022 03:53 — forked from fleepgeek/apps.py
A Django Middleware to prevent multiple sessions for the same user. It automatically logs out the previous session and replaces it with the new session.
from django.apps import AppConfig
class ForumConfig(AppConfig):
name = 'forum'
# This function is the only new thing in this file
# it just imports the signal file when the app is ready
def ready(self):
import your_app_name.signals
@rg3915
rg3915 / build.py
Created February 15, 2022 22:41 — forked from guilhermecarvalhocarneiro/build.py
Código para automatizar a geração das urls, forms, templates, views e de um projeto DRF.
"""Esse manager é responsável por gerar os arquivos padrões de um projeto Django (templates, urls, views, forms)
baseado nas informações contidas na classe da App do projeto Django.
"""
import fileinput
import os
from pathlib import Path
from bs4 import BeautifulSoup
from core.management.commands.utils import Utils
@rg3915
rg3915 / Microsoft.PowerShell_profile.ps1
Created February 1, 2022 14:16
Aliases in Powershell
function gitpush{
git push -u origin master
}
Set-Alias gpu gitpush
function create_env {
python -m venv .venv
}
Set-Alias mkenv create_env
@rg3915
rg3915 / gist:e665b81fa56a2ba24dfd870a705b31be
Created December 19, 2021 01:34 — forked from toninhocajueiro/gist:086ae0f9dca7db0cebe2256507d26844
Função simples pra testar download de arquivo no DRF
# viewsets.py
from rest_framework.decorators import api_view, permission_classes
from django.http import FileResponse
from django.shortcuts import get_object_or_404
@api_view(['GET'])
@permission_classes((IsAuthenticated,))
def download(file):
@rg3915
rg3915 / make_gh_issue.py
Last active June 28, 2021 05:24
A simple Python script that can create an issue on a specific repository. github cli github issues
"""
requires the "PyGitHub" package (`pip install pygithub`).
You can leave out things like an assignee, a label etc., by simply leaving them out of the code.
"""
from github import Github
import os
from pprint import pprint

Tested only on Ubuntu 20.04, KDE Neon User Edition (based on Ubuntu 20.04) and OSX Mojave.

will probably work on other newer versions, with no changes, or with few changes in non-python dependencies (apt-get packages)

NOTE: Don't create a .sh file and run it all at once. It will not work. Copy, paste, and execute each command below manually. :-)

Ubuntu

# DO NOT RUN THIS AS A ROOT USER
@rg3915
rg3915 / drf_utils.py
Created March 20, 2021 23:00 — forked from twidi/drf_utils.py
Make Django Rest Framework correctly handle Django ValidationError raised in the save method of a model
"""
Sometimes in your Django model you want to raise a ``ValidationError`` in the ``save`` method, for
some reason.
This exception is not managed by Django Rest Framework because it occurs after its validation
process. So at the end, you'll have a 500.
Correcting this is as simple as overriding the exception handler, by converting the Django
``ValidationError`` to a DRF one.
"""
from django.core.exceptions import ValidationError as DjangoValidationError
@rg3915
rg3915 / unions
Created March 6, 2021 12:52 — forked from djq/unions
How to union a list of geometries in GeoDjango
from django.contrib.gis.geos import GEOSGeometry
# sample data
geom_1 = GEOSGeometry('POLYGON((-71.8 42.1,-70.6 42.1,-70.5 41.2,-71.8 41.2,-71.8 42.1))')
geom_2 = GEOSGeometry('POLYGON((-71.12 42.23,-71.48 42.34,-71.52 42.55,-71.12 42.23))')
geom_3 = GEOSGeometry('POLYGON((-73.12 42.23,-71.48 42.34,-71.52 42.55,-73.12 42.23))')
polygons = [geom_1, geom_2, geom_3]
# get first polygon
polygon_union = polygons[0]