Skip to content

Instantly share code, notes, and snippets.

@henocdz
henocdz / iptables.md
Last active December 22, 2015 16:45
Basic IP Tables Config for Nginx, Postgresql and Python/Django servers

GENERAL

Allow connection to SSH port (defaults to 22)

-A INPUT -p tcp --dport 22 -j ACCEPT

-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

Drop all connections by default

@henocdz
henocdz / pgdump.sh
Last active February 16, 2017 06:30
Script for automatic backup of Postgresql DB
DB_USERNAME=''
DB_NAME=''
DB_PASSWORD=''
DB_HOST=''
DATE=`date +%Y%m%d`
TIME=`date +%H%M`
BACKUP_DIR='/some/path/to/dbackups/'
FILENAME="$DATE-$TIME.sql.gz"

Python 3

  1. Introducción ¿qué ha cambiado? ¿por qué Python 3?
  2. Instalación
  3. Tipos de datos
  4. Strings vs. Bytes
  5. Formateo de cadenas (String formatting)
  6. Operadores lógicos
  7. Entrada y salida de datos
  8. Estructuras de control: if-elif-else
@henocdz
henocdz / drop_nginx.conf
Created October 8, 2015 06:23
Drop connection to nginx server with unknown server_name
server {
listen 80;
return 444;
}
@henocdz
henocdz / tasks.py
Last active October 8, 2015 06:22
Django to Production Invoke File (#WIP)
from invoke import task, run
from paramiko import SSHConfig, SSHClient, SSHException, AutoAddPolicy
import logging
import os
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('Paramiko')
@henocdz
henocdz / paramiko_invoke_server.py
Created October 8, 2015 04:06
Connect to a given hostname in a given SSH config file (Invoke + Paramiko)
"""
Used with Invoke to automate tasks
Connect to a given hostname in a given SSH config file
Inpired by: https://gist.github.com/acdha/6064215
"""
from invoke import task, run
from paramiko import SSHConfig, SSHClient, SSHException, AutoAddPolicy
import logging
upstream backend_staging {
server SOME_IP:PORT weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name www.domain.com;
return 301 http://$server_name$request_uri;
}
server {
user nginx;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#!/bin/bash
NAME="project_name"
DJANGODIR="/path/to/django_project"
VIRTUAL_ENV_DIR="/path/to/virtualenv/folder"
VIRTUAL_ENV_FILE=${DJANGODIR}/.env
# SOCKFILE=
ADDRESS=0.0.0.0:8000
USER=sysuser