This file contains 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
def luhn_checksum(card_number): | |
def digits_of(n): | |
return [int(d) for d in str(n)] | |
digits = digits_of(card_number) | |
odd_digits = digits[-1::-2] | |
even_digits = digits[-2::-2] | |
checksum = 0 | |
checksum += sum(odd_digits) | |
for d in even_digits: | |
checksum += sum(digits_of(d*2)) |
This file contains 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
$ git commit ... (1) | |
$ git reset --soft "HEAD^" (2) | |
$ edit (3) | |
$ git add .... (4) | |
$ git commit -c ORIG_HEAD (5) | |
1) This is what you want to undo | |
2) This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset". (The quotes are required if you use zsh) | |
3) Make corrections to working tree files. | |
4) Stage changes for commit. |
This file contains 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
@register.assignment_tag | |
def query(qs, **kwargs): | |
""" template tag which allows queryset filtering. | |
Usage: | |
{% load query from operations %} | |
{% query operations description="some things" as records %} | |
{% for r in records %} | |
... | |
{% endfor %} | |
""" |
This file contains 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
#!/bin/bash | |
sudo apt-get -y install language-pack-es-base | |
sudo apt-get -y install postgresql-9.1 libpq-dev postgresql-9.1-postgis gdal-bin | |
sudo apt-get -y install git python-pip python-dev | |
sudo apt-get -y install libxml2-dev libxslt1-dev | |
sudo -u postgres psql -c "CREATE ROLE dev LOGIN PASSWORD 'dev' SUPERUSER VALID UNTIL 'infinity';" | |
sudo -u postgres createdb template_postgis | |
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql | |
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql |
This file contains 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
Option 1 | |
su - postgres | |
psql template1 | |
CREATE USER tom WITH PASSWORD 'myPassword'; | |
CREATE DATABASE jerry; | |
GRANT ALL PRIVILEGES ON DATABASE jerry to tom; | |
Option 2: | |
su postgres | |
postgres@debian: createuser tom |
This file contains 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
#!/usb/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
if len(sys.argv) > 2: | |
print "Sólo un argumento, el nombre del csv" | |
exit -1 | |
else: | |
print "TUPLE = (" | |
with open(sys.argv[1]) as file: |
This file contains 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 python3 | |
# -*- coding: utf-8 -*- | |
"""PDF Conversor powered by Qt5.""" | |
from uuid import uuid4 | |
from PyQt5.QtCore import QUrl |
This file contains 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
First, install arch-install-scripts: | |
sudo pacman -S --needed arch-install-scripts | |
Secondly, mount your partitions in all the internal hard drives. | |
Thirdly, generate and validate your config by piping it out to stdout: | |
genfstab -U -p / | less |
This file contains 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 socket import socket, SO_REUSEADDR, SOL_SOCKET | |
from asyncio import Task, coroutine, get_event_loop | |
class Peer(object): | |
def __init__(self, server, sock, name): | |
self.loop = server.loop | |
self.name = name | |
self._sock = sock | |
self._server = server | |
Task(self._peer_handler()) |
This file contains 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
""" | |
client.py - AsyncIO Server using StreamReader and StreamWriter | |
This will create 200 client connections to a server running server.py | |
It will handshake and run similar to this: | |
Server: HELLO | |
Client: WORLD |
OlderNewer