Skip to content

Instantly share code, notes, and snippets.

View EnriqueSoria's full-sized avatar
🐍
pythoning

Enrique Soria EnriqueSoria

🐍
pythoning
View GitHub Profile
@lgyanf
lgyanf / add_query_parameters.py
Created June 14, 2016 10:49
A python decorator that adds query parameters to django-rest-framework swagger docstring.
# -*- coding: utf-8 -*-
import collections
import yaml
from rest_framework import fields
"""
Convert rest_framework.fields classes to Swagger data types according to http://swagger.io/specification/
Return 'string' by default.
@jlazic
jlazic / decorators.py
Created May 21, 2016 18:49
Add HIT/MISS info to headers with Django cache middleware
from django.views.decorators.cache import decorator_from_middleware_with_args
from django.middleware.cache import CacheMiddleware
class LocalCacheMiddleware(CacheMiddleware):
def process_request(self, request):
response = super(LocalCacheMiddleware, self).process_request(request)
# Add X-Cache: HIT header if response is returned from cache
if response:
response['X-Cache'] = 'HIT'
@pardo
pardo / debounced_celery_task.py
Last active February 27, 2025 15:20
Debounced celery task in python
def debounced_wrap(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
key = kwargs.pop("key") # it's required
call_count = kwargs.pop("call_count", 1)
count = cache.get(key, 1)
if count > call_count:
# someone called the function again before the this was executed
return None
# I'm the last call
@jaimergp
jaimergp / config-highlight.cfg
Last active July 19, 2025 13:09
Dark highlighting theme for Python IDLE based on SublimeText's Monokai color scheme
# Place this file inside your ~/.idlerc/ folder
# or paste its contents inside
# /path/to/python/idlelib/config-highlight.def
# Adapted from SublimeText's Monokai
[monokai]
normal-foreground= #F8F8F2
normal-background= #272822
keyword-foreground= #F92672
keyword-background= #272822
@rymawby
rymawby / convert-aac-to-mp3.sh
Created October 19, 2012 15:56
Convert aac to mp3 using ffmpeg
ffmpeg -i <audio.aac> -acodec libmp3lame <audio.mp3>