Skip to content

Instantly share code, notes, and snippets.

View pvieytes's full-sized avatar

Pablo Vieytes pvieytes

View GitHub Profile
@pvieytes
pvieytes / source.py
Created August 2, 2016 00:48 — forked from mammadori/source.py
Python: "source" a shell script and read variables
from subprocess import Popen, PIPE
from os import environ
def source(script, update=True, clean=True):
"""
Source variables from a shell script
import them in the environment (if update==True)
and report only the script variables (if clean==True)
"""
@pvieytes
pvieytes / fabfile.py
Created December 10, 2015 09:11 — forked from SeanHayes/fabfile.py
Example Fabric fabfile.py. It's a hodgepodge of old scripts and probably isn't best practice (uWSGI ought to have an init script), but it should give you a practical idea of how to use Fabric. This fabfile relies heavily on custom settings from a Django project in order to be more DRY. Includes commands for setting up a fresh Ubuntu Server insta…
# -*- coding: utf-8 -*-
#Copyright (C) 2013 Seán Hayes
import my_project.settings as dj_settings
from fabric.api import local, run, sudo, env, prompt, settings, cd, parallel, execute
from fabric.contrib.files import exists
from fabric.decorators import hosts, roles, runs_once
import json
import logging
import os
@pvieytes
pvieytes / models.py
Created November 19, 2015 20:38 — forked from qingfeng/models.py
Django Image Field UnitTest
from django.db import models
class M1(models.Model):
title = models.CharField(max_length=100)
img1 = models.ImageField(upload_to="static/")
def __unicode__(self):
return self.title
@pvieytes
pvieytes / using_request_post_or_none.py
Last active August 29, 2015 14:26 — forked from pylemon/using_request_post_or_none.py
django: using(request.POST or None) hack in views | advanced forms usage
# simple form usage in view
def my_view(request, template_name='home.html'):
# sticks in a POST or renders an empty form
form = MyForm(request.POST or None)
if form.is_valid():
do_something()
return redirect('/')
return render_to_response(template_name, {'form':form})
# form with files