Skip to content

Instantly share code, notes, and snippets.

View migonzalvar's full-sized avatar

Miguel Gonzalez migonzalvar

  • Vigo, Pontevedra, Spain
View GitHub Profile
@migonzalvar
migonzalvar / Vagrantfile
Created September 14, 2017 18:47
Simple Vagrantfile to install Odoo
$script = <<SCRIPT
yum install -y epel-release
yum install -y postgresql-server
postgresql-setup initdb
systemctl enable --now postgresql
yum install -y yum-utils
yum-config-manager --add-repo=https://nightly.odoo.com/10.0/nightly/rpm/odoo.repo
yum install -y odoo
systemctl enable --now odoo
yum install -y https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.1/wkhtmltox-0.12.1_linux-centos7-amd64.rpm
@migonzalvar
migonzalvar / byzanz-gui.sh
Last active September 29, 2016 17:05
Record Screen as Animated GIF in Ubuntu with Byzanz (from https://www.maketecheasier.com/record-screen-as-animated-gif-ubuntu/)
#!/bin/bash
# AUTHOR: (c) Rob W 2012
# modified by MHC (http://askubuntu.com/users/81372/mhc)
# and by Rodolfo Carvalho
# NAME: GIFRecord 0.1-fedora
# DESCRIPTION: A script to record GIF screencasts.
# LICENSE: GNU GPL v3 (http://www.gnu.org/licenses/gpl.html)
# DEPENDENCIES: byzanz,zenity,notify-send
@migonzalvar
migonzalvar / pep484_use_case.py
Created August 16, 2016 12:09
Demostración casos de uso de `PEP 484 -- Type Hints`
import datetime as dt
from collections import OrderedDict as odict
import inspect
import types
from rest_framework import serializers
def function(a: int, b: str):
pass
@migonzalvar
migonzalvar / marionette.rst
Created August 2, 2016 18:20
Proof of concept Marionette, the next generation of FirefoxDriver.

Proof of concept Marionette, the next generation of FirefoxDriver.

Install recent firefox

Download recent firefox, for instance latest aurora, and install.

#!/usr/bin/env python
"""Use of a callable to implement lazy evaluation of keys in a dict."""
data = {
'name': 'John',
'surname': 'Smith',
'full_name': lambda x: '{name} {surname}'.format(**x)
}

Serving Django and Twisted using HAproxy

Why?

Because we wanted to achive the following while developing a webapp using websockets:

Static serving (nginx), Django application (gunicorn) and Websockets service (twisted)

  • on the same IP
import psycopg2
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
import eventlet
from eventlet import wsgi
from eventlet import websocket
from eventlet.hubs import trampoline
dsn = "dbname=test" # customise this

Why?

Most commonly because you'd like to use JDBC to connect to your local Postgres server without using password auth. Very quickly you'll realise Unix sockets aren't supported in Java, so you can't use peer authentication.

How?

First, ensure your /var/lib/pgsql/pg_hba.conf uses ident for TCP/IP connections:

# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
import sqlite3
import yaml
DATABASE = 'inventory.db'
with open('schema.yaml') as f:
schema = yaml.load(f)
def create_table(table, *fields):
#! /usr/bin/env python3
""" Calcula los días transcurridos desde una fecha.
"""
import datetime
DAY_LABELS = "Lunes,Martes,Miércoles,Jueves,Viernes,Sábado,Domingo".split(',')
user_date = input('Fecha> ')
day, month, year = [int(s) for s in user_date.split('-')]