Skip to content

Instantly share code, notes, and snippets.

View gustavofonseca's full-sized avatar

Gustavo Fonseca gustavofonseca

  • São Paulo, Brazil
View GitHub Profile
@gustavofonseca
gustavofonseca / descritores0.py
Created December 11, 2011 05:21
descritores somente leitura
#!/usr/bin/env python
# coding:utf-8
"""
>>> livro = Livro('Eram os deuses astronautas?', 'Erich von Daniken')
>>> livro.autor_individual
'DANIKEN, Erich von'
>>> livro2 = Livro('O menino maluquinho', 'Ziraldo')
Traceback (most recent call last):
...
@gustavofonseca
gustavofonseca / descritores1.py
Created December 11, 2011 05:23
descritores leitura e escrita
#!/usr/bin/env python
# coding:utf-8
"""
>>> livro = Livro('Eram os deuses astronautas?', 'Erich von Daniken')
>>> livro.autor_individual
'DANIKEN, Erich von'
>>> livro2 = Livro('O menino maluquinho', 'Ziraldo')
Traceback (most recent call last):
...
@gustavofonseca
gustavofonseca / descritores2.py
Created December 11, 2011 05:24
descritores leitura e escrita sem passar o nome do atributo
#!/usr/bin/env python
# coding:utf-8
"""
>>> livro = Livro('Eram os deuses astronautas?', 'Erich von Daniken')
>>> livro.autor_individual
'DANIKEN, Erich von'
>>> livro2 = Livro('O menino maluquinho', 'Ziraldo')
Traceback (most recent call last):
...
@gustavofonseca
gustavofonseca / lala.py
Created March 6, 2012 20:59
Refatoração do template tag de paginação (somente o metodo render)
def render(self, context):
object_record = self.object_record.resolve(context)
if object_record.paginator.count > settings.PAGINATION__ITEMS_PER_PAGE:
class_li_previous = 'disabled' if not object_record.has_previous() else ''
class_li_next = 'disabled' if not object_record.has_next() else ''
html_pages = []
for page in object_record.paginator.page_range:
class_li_page = 'active' if object_record.number == page else ''
@gustavofonseca
gustavofonseca / mini-models.py
Created April 23, 2012 22:25
django caching machine no scielo manager
import caching.base
class AppCustomManager(models.Manager):
"""
Domain specific model managers.
"""
def available(self, availability=None):
"""
Filter the queryset based on its availability.
!ID 0
!v100!ABCD. Arquivos Brasileiros de Cirurgia Digestiva (São Paulo)
!v400!0102-6720
!v035!PRINT
!v935!
!v150!ABCD, arq. bras. cir. dig.
!v151!ABCD, arq. bras. cir. dig
!v610!
!v440!medicina
!v440!cirurgia
@gustavofonseca
gustavofonseca / gist:3144295
Created July 19, 2012 14:25
Comportamento não esperado do método setdefault de dicionários python
_memo = {}
data = {'user': 'gus'}
def get_from_other_resource(field):
print 'other resource - [%s]' % (field)
return data[field]
print 'Imprimindo o valor da var _memo. A funcao get_from_other_resource sera invocada:'
print _memo.setdefault('user', get_from_other_resource('user'))
@gustavofonseca
gustavofonseca / pub_books.py
Created August 27, 2012 13:20
listagens do books em csv
# coding:utf-8
import couchdbkit
BASE_URL = 'http://books.scielo.org/id/%s'
server = couchdbkit.Server(uri='http://192.168.1.12:5984/')
db = server['scielobooks_1a']
print 'sbid|title|url'
@gustavofonseca
gustavofonseca / ghsummary.py
Created December 20, 2012 16:07
Script that shows all pull-requests from all repos of an organization waiting for revision.
#!/usr/bin/env python
# coding: utf-8
"""
Script that shows all pull-requests from all repos of an
organization waiting for revision.
need to pip install prettytable
"""
import urllib2
import json
#!/usr/bin/env python
# coding: utf-8
from __future__ import unicode_literals
import csv
import sys
from collections import OrderedDict
import couchdbkit
BASE_URL = 'http://books.scielo.org/id/%s'