Skip to content

Instantly share code, notes, and snippets.

View eduardo-matos's full-sized avatar

Eduardo Matos eduardo-matos

View GitHub Profile
from dateutil.relativedelta import relativedelta
from datetime import datetime, timedelta
first_date = datetime(1970, 1, 1)
date_list = [first_date + timedelta(days=x) for x in xrange(0, 1000000)]
forty_weeks = 40 * 7
for date in date_list:
if ((date + relativedelta(months=10)) - date).days == forty_weeks:
print('40 weeks equals 10 months! Starting at {}'.format(date))
@eduardo-matos
eduardo-matos / vim.txt
Last active August 29, 2015 14:06
Studying VIM
=== command mode ===
h - moves left 1 char
j - moves down 1 line
k - moves up 1 line
l - moves right 1 char
w - moves right 1 word
b - mover left 1 word
$ - moves to the end of the line
^ - moves right before the first non-blank character in the line
0 - moves to the beginning of the line
@eduardo-matos
eduardo-matos / a.sh
Created September 1, 2014 23:11
Bash notepad
# kill processes by name
pkill <process name>
# if the above doesn't work, drop an atomic bomb!
ps auxww | grep '<process name>' | awk '{print $2}' | xargs kill -9
@eduardo-matos
eduardo-matos / gist:d37b67aec8271926eb6c
Last active August 29, 2015 14:05
Anotações sobre PostgreSQL
# listar bancos de dados
\list
# passa a usar o banco
\c <banco>
# sair do prompt
\q
# mostrar todas as tabelas
mysqldump -u <user> -p --host=<host> --port=<port> <database> > <filename>.sql
@eduardo-matos
eduardo-matos / test.sh
Last active August 29, 2015 14:05
Teste automático em ambiente Windows e Linux
# Teste em ambiente Windows
cls
python manage.py test %* --settings=app.settings.test
rd /S /q %~dp0\media_tests
# Teste em ambiente Unix
clear
python manage.py test $* --settings=app.settings.test
rm -rf $(dirname $0)/media_test
@eduardo-matos
eduardo-matos / index.html
Created February 14, 2014 09:48
Dojo query with Sizzle selector engine
<script src="/js/dojo.js"
data-dojo-config="'selectorEngine': 'sizzle/sizzle', 'packages': [{'name': 'sizzle', 'location': 'https://rawgithub.com/jquery/sizzle/master/dist/'}]" ></script>
<script src="my.js"></script>
@eduardo-matos
eduardo-matos / base_convert.py
Last active August 29, 2015 13:56
Conversão de bases em Python
from math import floor
BASE62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
def base_convert(src, from_base=10, to_base=16, alphabet=BASE62):
src = str(src)
from_alphabet = alphabet[:from_base]
to_alphabet = alphabet[:to_base]
@eduardo-matos
eduardo-matos / models.py
Last active August 29, 2015 13:56
Gerar valor aleatório para campos
# coding: utf-8
from django.db import models
from django.utils.crypto import get_random_string
from django.utils.translation import ugettext_lazy as _
class Discount(models.Model):
discount = models.FloatField(_('Discount Value'))
code = models.CharField(_("Discount code"), max_length=255, unique=True, default=get_random_string)
@eduardo-matos
eduardo-matos / admin.py
Last active August 29, 2015 13:55
Exibir lista de usuários somente ao fazer uma busca.
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
class UserAdmin(admin.ModelAdmin):
list_display = ('email', 'first_name', 'last_name')
list_filter = ('is_staff', 'is_superuser')
search_fields = ('email',)