Skip to content

Instantly share code, notes, and snippets.

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

Tatjana ZandTree

🏠
Working from home
View GitHub Profile
@TaylorBeeston
TaylorBeeston / photoOptimizer.js
Last active July 11, 2022 20:39
Optimize photos client-side
const MAX_WIDTH = process.env.PHOTO_MAX_WIDTH || 800;
const QUALITY = process.env.PHOTO_QUALITY || 0.9;
const readPhoto = async (photo) => {
const canvas = document.createElement('canvas');
const img = document.createElement('img');
// create img element from File object
img.src = await new Promise((resolve) => {
const reader = new FileReader();
INSTALLED_APPS = [
# My apps
'personal',
'account',
'blog',
# django apps
'django.contrib.admin',
@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)
@mortenpi
mortenpi / pcniter.py
Created March 17, 2014 17:41
Previous / current / next iterator in Python
def previous_current_next(iterable):
"""Make an iterator that yields an (previous, current, next) tuple per element.
Returns None if the value does not make sense (i.e. previous before
first and next after last).
"""
iterable=iter(iterable)
prv = None
cur = iterable.next()
try: