Skip to content

Instantly share code, notes, and snippets.

@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 / drop_nginx.conf
Created October 8, 2015 06:23
Drop connection to nginx server with unknown server_name
server {
listen 80;
return 444;
}

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 / 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"
@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 / download_http.py
Last active February 10, 2017 21:11
A Django download HTTP response class that forces download in the browser.
from django.http import HttpResposne
import os
class DownloadResponse(HttpResponse):
"""
A download HTTP response class that forces download in the browser or redirects to URL given for file.
Args:

Keybase proof

I hereby claim:

  • I am henocdz on github.
  • I am henocdz (https://keybase.io/henocdz) on keybase.
  • I have a public key whose fingerprint is 9C96 DF24 FE61 35E6 2417 5AD4 43F4 8594 1C29 ADD7

To claim this, I am signing this object:

@henocdz
henocdz / app.jsx
Last active October 25, 2017 02:37
React Router v4 "Static Routes"
import React from 'react'
import ReactDOM from 'react-dom'
import { createBrowserHistory } from 'history'
import { ConnectedRouter } from 'react-router-redux'
// Global Styles
import 'styles/app.less'
// Routes config
@henocdz
henocdz / fibos.py
Created October 25, 2017 02:38
Fibos
def get_input(cast, text=''):
"""Request user for input and tries to cast input to cast function provided
Args:
cast (function): cast function to use
text (string): text to print so user can know what to type in!
Returns:
casted user input
"""
try:
return cast(input(text))