Skip to content

Instantly share code, notes, and snippets.

View dnmellen's full-sized avatar
🐙

Diego Navarro dnmellen

🐙
  • Madrid
View GitHub Profile
@dnmellen
dnmellen / hipstergram.sh
Last active January 27, 2022 22:40
Hipstergram: Bash script to convert images to a square aspect ratio with white background (Uses ImageMagick)
#!/bin/bash
for file in `ls -1`; do
echo $file;
convert -background white -gravity center $file -resize 1080x1080 -extent 1080x1080 i-$file
convert $file -crop 2x1@ i-$file
done
from django import template
register = template.Library()
@register.filter
def cool_number(value, num_decimals=2):
"""
Django template filter to convert regular numbers to a
cool format (ie: 2K, 434.4K, 33M...)
@dnmellen
dnmellen / ocrshot.py
Last active March 2, 2023 11:06
Takes an screenshot (the user draws a rectangle to select the interesting area), scans the resulting image and copy the text to clipboard
#!/usr/bin/python -tt
"""
Takes an screenshot (the user draws a rectangle to select the interesting area), scans the resulting image and copy the text to clipboard
- scrot (http://en.wikipedia.org/wiki/Scrot)
- readbot (`pip install readbot`)
- pyperclip (`pip install pyperclip`)
"""
@dnmellen
dnmellen / test_views.py
Last active May 29, 2023 13:31
How to create a unittest for a "View" Mixin (Django Testing)
from django.test import TestCase, RequestFactory
from django.views.generic import TemplateView
from ..lib.views import YourMixin
class YourMixinTest(TestCase):
'''
Tests context-data in a Django Mixin like a boss
'''
@dnmellen
dnmellen / colors.py
Created May 15, 2013 13:32
Auxiliary Python module to get styled terminal outputs in a pythonic way
# encoding: utf-8
# Copyright 2013 Diego Navarro Mellén. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#