Skip to content

Instantly share code, notes, and snippets.

View douglasmiranda's full-sized avatar
👽

Douglas Miranda douglasmiranda

👽
  • Earth, Brazil
View GitHub Profile
@douglasmiranda
douglasmiranda / splinter_tutorial.py
Created June 6, 2012 06:27
Tutorial Splinter. Fixing the current tutorial, which is failing
from splinter.browser import Browser
browser = Browser('chrome')
browser.visit('http://google.com')
browser.fill('q', 'splinter - python acceptance testing for web applications')
browser.find_by_name('btnG').first.click()
if browser.is_text_present('splinter.cobrateam.info'):
print "Yes, the official website was found!"
else:
@douglasmiranda
douglasmiranda / gist:2885050
Created June 6, 2012 21:49
Django: Escolher db dinamicamente
"""
Resposta que surgiu nesta discussão: https://groups.google.com/forum/#!topic/django-brasil/3ADhmbltSUU
Então guardei aqui p/ testar em breve.
"""
Model.objects.using(Model.user_db(user)).all() ou
instance.save(using=Model.user_db(user))
from django.views.generic import View
from django.template.response import TemplateResponse
from news.models import Noticia
from videos.models import Video
from datetime import datetime
class HomeView(View):
template_name = 'home/home.html'
@douglasmiranda
douglasmiranda / .htaccess
Created June 18, 2012 17:45
Apache: When we make a Ajax request and get something like: "Origin http://ANY_DOMAIN_HERE is not allowed by Access-Control-Allow-Origin..."
SetEnvIf Origin "^http(s)?://(.+\.)?(http://ANY_DOMAIN_HERE\.com)$" origin_is=$0
Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is
@douglasmiranda
douglasmiranda / forms.py
Created July 17, 2012 17:46
Implementando form de filtro numa ListView (Resposta para um tópico na Django Brasil)
# https://groups.google.com/forum/?fromgroups#!topic/django-brasil/d6gV1V9qrgU
from django.forms import ModelForm
from minha_app.models import MeuModel
class MeuForm(ModelForm):
class Meta:
model = MeuModel
@douglasmiranda
douglasmiranda / gist:3165425
Created July 23, 2012 18:58
Django: construct search with prefixes - code from djang.contrib.admin.views.main
# Apply keyword searches.
def construct_search(field_name):
if field_name.startswith('^'):
return "%s__istartswith" % field_name[1:]
elif field_name.startswith('='):
return "%s__iexact" % field_name[1:]
elif field_name.startswith('@'):
return "%s__search" % field_name[1:]
else:
return "%s__icontains" % field_name
@douglasmiranda
douglasmiranda / gist:3189843
Created July 27, 2012 19:02
Python UnicodeEncodeError: 'ascii' codec can't encode character
# https://groups.google.com/forum/?fromgroups#!topic/django-brasil/TZBXSowifn8
from django.utils.encoding import smart_str, smart_unicode
a = u'\xa1'
print smart_str(a)
@douglasmiranda
douglasmiranda / gist:3193883
Created July 28, 2012 16:16
Creating a semantic breadcrumb using HTML5 microdata
<!-- http://coderwall.com/p/p0nvjw?i=5&p=1&q= -->
<ol class="breadcrumb">
<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="http://www.example.com/" itemprop="url">
<span itemprop="title">Example.com</span>
</a>
</li>
<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="http://www.example.com/news" itemprop="url">
<span itemprop="title">News</span>
@douglasmiranda
douglasmiranda / gist:3254332
Created August 4, 2012 04:05
How to Find and Replace Text in MySQL Database using SQL
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, "find this string", "replace found string with this string");
@douglasmiranda
douglasmiranda / gist:3595499
Created September 2, 2012 07:05
Upgrading Virtualbox on Ubuntu 12
~$ cd /opt/VirtualBox
~$ ls -al
~$ sudo chmod +x uninstall.sh
~$ sudo sh uninstall.sh
# then with 'cd' command move to the directory where is the .deb file, and execute it, example:
~$ cd ~/Downloads
~$ sudo dpkg -i virtualbox-4.1_4.1.20-80170~Ubuntu~precise_amd64.deb