This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from validators import MimetypeValidator | |
| class MyForm(forms.Form): | |
| file = forms.FileField( | |
| allow_empty_file=False, | |
| validators=[MimetypeValidator('application/pdf')], | |
| help_text="Upload a PDF file" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ssh-keygen -b 4096 -t rsa | |
| ssh-copy-id user@server |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cat /proc/sys/net/ipv4/ip_local_port_range | |
| firewall-cmd --permanent --add-port=32768-61000/udp | |
| firewall-cmd --reload | |
| firewall-cmd --permanent --zone=home --add-port=32768-61000/udp | |
| iptables -A INPUT -s 192.168.0.0/24 -p udp -m udp --dport 32768:61000 -j ACCEPT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| from django import template | |
| register = template.Library() | |
| @register.filter(name='round_step') | |
| def round_step(x, base=5): | |
| return int(base * round(float(x)/base)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Download Command Line Tools (OS X Mavericks) for Xcode | |
| # https://developer.apple.com/downloads/index.action | |
| # You can setting the following environment variables prior compilation (.bash_profile or .bashrc): | |
| export CFLAGS=-Qunused-arguments | |
| export CPPFLAGS=-Qunused-arguments | |
| pip install psycopg2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "bold_folder_labels": true, | |
| "close_windows_when_empty": false, | |
| "color_scheme": "Packages/Color Scheme - Default/Blackboard.tmTheme", | |
| "fade_fold_buttons": false, | |
| "file_exclude_patterns": | |
| [ | |
| "*.xlsx", | |
| "*.pyc", | |
| "*.directory" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| from django import template | |
| register = template.Library() | |
| from django.utils.encoding import smart_unicode | |
| def _verifier(rut): | |
| rut = smart_unicode(rut).replace(' ', '').replace('.', '').replace('-', '') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import date | |
| def calculate_age(born): | |
| today = date.today() | |
| try: | |
| birthday = born.replace(year=today.year) | |
| except ValueError: # raised when birth date is February 29 and the current year is not a leap year | |
| birthday = born.replace(year=today.year, day=born.day-1) | |
| if birthday > today: | |
| return today.year - born.year - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| from django.core.exceptions import ObjectDoesNotExist | |
| from django.http import Http404 | |
| class DoesNotExistTo404Middleware(object): | |
| def process_exception(self, request, exception): | |
| if isinstance(exception,ObjectDoesNotExist): | |
| raise Http404(exception.message) |