Skip to content

Instantly share code, notes, and snippets.

View jose-lpa's full-sized avatar

José L. Patiño Andrés jose-lpa

View GitHub Profile
@jose-lpa
jose-lpa / conftest.py
Last active September 15, 2020 16:28
Disposable database with Pytest, with data cleanup per-test for proper isolation
import pytest
from sqlalchemy import create_engine, engine, MetaData
from sqlalchemy.orm import sessionmaker
from sqlalchemy_utils import create_database, database_exists, drop_database
from my_project.database import Base
@pytest.fixture(scope="session", autouse=True)
#!/usr/bin/env bash
clean_containers() {
containers=$(docker ps -q)
echo "Stopping any running containers..."
docker stop $containers
echo "Removing all containers..."
docker rm -v $containers 2>/dev/null
echo "Containers removed from system."
}
@jose-lpa
jose-lpa / spam_blocker
Created February 13, 2015 22:38
Collection of spammers, snoopers and trojanizers to be added to the /etc/hosts file.
# Privacy settings and SPAM blocker.
# Redirect all those nasty guys background requests to localhost.
127.0.0.1 google-analytics.com
127.0.0.1 www.google-analytics.com
127.0.0.1 adbooth.net
127.0.0.1 softigloo.com
127.0.0.1 www.softigloo.com
127.0.0.1 ero-advertising.com
127.0.0.1 beursvoorbeginners.com
@jose-lpa
jose-lpa / gist:6151906
Created August 4, 2013 20:54
Default Jenkins configuration file for Nginx, set up to use SSL with automatic redirection when a user requests for ``http://`` instead of ``https://``.
server {
listen 80; # Listen on port 80 for IPv4 requests
server_name jenkins.example.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443 default ssl;
@jose-lpa
jose-lpa / gist:5299720
Created April 3, 2013 09:25
A Mezzanine 5-level dropdown menu. Very dirty and strict, but it just works. You can design (via CSS) a dropdown menu using HTML lists. So, a list is the main menu and then each element of the list can have another list as a submenu. This Django template will generate that dynamically when you are using Mezzanine framework http://mezzanine.jupo.…
{% load i18n future pages_tags %}
{% spaceless %}
{% if page_branch_in_menu %}
{% if branch_level == 0 %}
<ul class="menu">
{% for page in page_branch %}
{% if page.in_menu %}
<li>
<a href="{{ page.get_absolute_url }}">{{ page.title }}</a>
@jose-lpa
jose-lpa / gist:4259581
Last active October 13, 2015 21:38
An (intended to be generic) Python XML client. It can be customized for different types of simple RESTful XML APIs.
from lxml import etree
import requests
class XMLClient(object):
"""
Generic XML client. All the different provider's API implementations must
inherit from it to create its own client implementation.
"""
def __init__(self, username, password, url):