Skip to content

Instantly share code, notes, and snippets.

View EnriqueSoria's full-sized avatar
🐍
pythoning

Enrique Soria EnriqueSoria

🐍
pythoning
View GitHub Profile
@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>
@jaimergp
jaimergp / config-highlight.cfg
Last active May 27, 2024 12:16
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
@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'
@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.
@wojteklu
wojteklu / clean_code.md
Last active July 3, 2024 15:39
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@twidi
twidi / drf_utils.py
Created December 21, 2016 14:34
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
@mattmarcum
mattmarcum / facebook-cleanse.js
Created February 12, 2018 23:03
Console script to unlike everything you ever liked on facebook
/*
This works on 2/12/2018, but will need to be updated as facebook updates it's DOM
1: Go to your profile, click More->Likes
2: Scroll down to the bottom of the page and keep scrolling as facebook loads more of your 'likes'
3: Open the console and c&p this:
*/
document.querySelectorAll('button.PageLikedButton').forEach(b=>b.click());
document.querySelectorAll('li[data-label="Unlike"] a').forEach(a=>a.click());
@hakib
hakib / custom_django_checks.py
Last active July 1, 2024 09:20
Custom django checks using Django check framework, inspect and ast.
"""
Custom django checks.
H001: Field has no verbose name.
H002: Verbose name should use gettext.
H003: Words in verbose name must be all upper case or all lower case.
H004: Help text should use gettext.
H005: Model must define class Meta.
H006: Model has no verbose name.
H007: Model has no verbose name plural.
@jonashaag
jonashaag / celery_model_serializer.py
Last active March 28, 2022 23:14
Celery Django model serializer – pass Django model instances as arguments to Celery tasks
"""Our convenience Celery Task wrapper that allows us to conveniently pass
model instances as Task arguments.
It "serializes" model instances to IDs and "deserializes" these IDs to model
instances upon task execution.
Serialized representation of a model instance is (sentinel, app_name, model_name, pk).
"""
import celery
from django.apps import apps
@jolexa
jolexa / invalidate-all.py
Created October 24, 2018 14:07
Invalidate CloudFront Cache with boto3
from time import time
import sys
import boto3
client = boto3.client('cloudfront')
# Uncomment this to pass a URL to the script
#def get_id(url):
# print("get_id args: {0}".format(url))
# # url: asdf.cloudfront.net
# # return: E2134123ASDF