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 / celery_daemon.config
Created August 27, 2019 15:04 — forked from bahiamartins/celery_daemon.config
Daemonization process of Celery and Celery Beat using Supervisord in AWS Elastic Beanstalk
files:
"/tmp/100_celery_worker.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/sh
# for_log_and_pid
mkdir -p /var/log/celery/ /var/run/celery/
@rg3915
rg3915 / call_celery_post_deploy_aws.config
Created August 27, 2019 15:05 — forked from bahiamartins/call_celery_post_deploy_aws.config
call celery in AWS Elastic Beanstalk via post deploy. Process of Daemonization using Supervisord
{
"container_commands": {
"celery_configure": {
"command": "mv /tmp/100_celery_worker.sh /opt/elasticbeanstalk/hooks/appdeploy/post && chmod 774 /opt/elasticbeanstalk/hooks/appdeploy/post/100_celery_worker.sh",
"leader_only": true
}
}
}
@rg3915
rg3915 / df_manual.py
Last active January 22, 2020 16:39 — forked from brianckeegan/diverse_df.py
Generates a random pandas DataFrame containing categories, timestamps, integers, and random floats. Useful for debugging or answering StackOverflow questions.
# Generate df manually.
df = pd.DataFrame({
'A': ['apple', 'orange', 'pear', 'peach', 'black berry', 'grape', 'mandarine', 'watermelon', 'melon', 'pineapple', 'fig', 'banana', 'lemon', 'kiwi'],
'B': [21, 15, 3, 28, 9, 46, 28, 34, 47, 4, 38, 9, 5, 3],
})
@rg3915
rg3915 / upload.py
Created May 26, 2020 01:22 — forked from RyanBalfanz/upload.py
[Heroku] Direct to S3 File Uploads in Python
"""
Fix for some issues with the original code from Heroku:
https://devcenter.heroku.com/articles/s3-upload-python
This example is also designed for use with Django, not Flask as in the original.
"""
import base64
import hashlib
import hmac
@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]
@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

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 / 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
@rg3915
rg3915 / gist:e665b81fa56a2ba24dfd870a705b31be
Created December 19, 2021 01:34 — forked from antonioccneto/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 / 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