Skip to content

Instantly share code, notes, and snippets.

View IamMiracleAlex's full-sized avatar

Miracle Alex IamMiracleAlex

View GitHub Profile
@IamMiracleAlex
IamMiracleAlex / migrate_data.py
Created February 27, 2023 21:37
Migrate model (Table) data from one database to another database in chunks
import sys
from django.core import serializers
def migrate(model, dest_db, size=2000, start=0, old_db="default"):
"""
Migrate data from one database to another database in chunks
Args:
@caiolopes
caiolopes / save_thumb.py
Last active October 4, 2022 14:50
Function to resize an image of an ImageField from a Django model. It saves space on S3!
import io
from django.core.files.storage import default_storage as storage
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
img_read = storage.open(self.image.name, 'r')
img = Image.open(img_read)
@RyanBalfanz
RyanBalfanz / upload.py
Last active July 26, 2022 16:07
[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
@jtdp
jtdp / gist:5443297
Last active July 16, 2024 14:40
See changes before pulling from remote git repository
# fetch the changes from the remote
git fetch origin
# show commit logs of changes
git log master..origin/master
# show diffs of changes
git diff master..origin/master
# apply the changes by merge..