Skip to content

Instantly share code, notes, and snippets.

View matuu's full-sized avatar

Matuu matuu

View GitHub Profile
@matuu
matuu / luhn.py
Created November 27, 2013 11:14
Luhn checksum
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))
@matuu
matuu / reset_last_commit.txt
Created November 27, 2013 17:28
Reset last commit
$ 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.
@matuu
matuu / ttag_query.py
Created December 22, 2013 09:38
django templatetags: query filters model
@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 %}
"""
#!/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
@matuu
matuu / Postgres-create-user-db
Last active July 8, 2016 15:30
Postgres, create user & db
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
@matuu
matuu / csv_to_tuple.py
Last active August 29, 2015 14:17
Parsea un csv tipo clave-valor a tupla (python)
#!/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:
@matuu
matuu / qpdf.py
Last active August 29, 2015 14:26 — forked from juancarlospaco/qpdf.py
PDF Conversor powered by Qt5, does NOT show up any GUI, just needs an URL string, then it Prints PDF, and returns file path string, uses UUID if no output filename is passed, optional Landscape orientation if supported, CSS3 Just Works!.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""PDF Conversor powered by Qt5."""
from uuid import uuid4
from PyQt5.QtCore import QUrl
@matuu
matuu / fstab-generate-arch
Last active September 20, 2015 16:35 — forked from Brainiarc7/fstab-generate-arch.md
Generate fstab in Arch Linux
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
@matuu
matuu / chat.py
Created March 30, 2016 03:15 — forked from gregvish/chat.py
Python 3.4 asyncio chat server example
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())
@matuu
matuu / client.py
Created March 30, 2016 03:15 — forked from dbehnke/client.py
Python AsyncIO Client and Server Example using StreamReader and StreamWriter
"""
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