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 / README.md
Last active December 16, 2015 10:30
Django (1.6) functional tests (selenium + manage.py runserver)

Django functional testing

Django manage.py custom command for functional testing.

Fisrtly, the command starts the django sever via python manage.py runserver and secondly, it runs some Selenium tests.

Use:

@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
@pvieytes
pvieytes / .emacs
Created January 23, 2012 15:46
archivo de configuración de emacs
;;to-line short-cut key
(global-set-key "\C-l" 'goto-line)
;;M-g-g does the same
;; Wheel mouse + Control change buffer we are looking at
(defun next-buffer ()
"Go to the buffer which is at the end of the buffer-list.
This is the symmetric of burry-buffer."
(interactive)
(switch-to-buffer (nth (- (length (buffer-list)) 1) (buffer-list))))
@pvieytes
pvieytes / read_tweets.py
Created May 18, 2011 07:16
Parsing Twitter's user time with Python
import Tweet
import simplejson
import urllib2
def read_tweets(user, num_tweets):
tweets = []
url = "http://api.twitter.com/1/statuses/user_timeline.json?\
screen_name=%s&count=%s&include_rts=true" % (user, num_tweets)
file = urllib2.urlopen(url)