Skip to content

Instantly share code, notes, and snippets.

View andresmachado's full-sized avatar

Andre Machado andresmachado

View GitHub Profile
[
{
"swagger": "2.0",
"info": {
"title": "TestePermissions API",
"description": "API documentation for TestePermissions App",
"version": "v1",
},
"host": "testepermissions_15043.herokuapp.com",
"schemes": ["https"],
@andresmachado
andresmachado / Portuguese.json
Last active May 16, 2018 22:04
dataTable typo fix
{
"sProcessing": "A processar...",
"sLengthMenu": "Mostrar _MENU_ registros",
"sZeroRecords": "Não foram encontrados resultados",
"sInfo": "Mostrando de _START_ até _END_ de _TOTAL_ registros",
"sInfoEmpty": "Mostrando de 0 até 0 de 0 registeos",
"sInfoFiltered": "(filtrado de _MAX_ registros no total)",
"sInfoPostFix": "",
"sSearch": "Procurar:",
"sUrl": "",
@andresmachado
andresmachado / flat_list.py
Last active February 23, 2018 01:43
List Flatten
import collections
alist = [[1, 2, [3, [5, 6, 7]]], 4]
def flat_list(xs):
for x in xs:
if isinstance(x, str) or not isinstance(x, collections.Iterable):
yield x
else:
yield from flat_list(x)
@andresmachado
andresmachado / import_banks.py
Created April 17, 2017 02:23
Import all active banks in Brazil
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 5 15:50:49 2017
@author: andre
"""
import json
from bs4 import BeautifulSoup
class OccurencesInRadiusDistance(generics.ListAPIView):
"""API endpoint that returns all objects in a radius given a set of coordinates in url_params."""
serializer_class = MyCustomSerializer
permissions_classes = (permissions.IsAuthenticatedOrReadOnly, )
def get_queryset(self):
"""This queryset returns all objects in a specified radius distance. We use PostGIS to create POINT objects and create the query.
How to use postGIS on Django: https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/postgis/
@andresmachado
andresmachado / serializers.py
Created April 1, 2017 02:36
nested_serializer.py
class ItemSerializer(serializers.ModelSerializer):
class Meta:
model = Item
fields = (
'field1',
'field2'
)
class CategorySerializer(serializers.ModelSerializer):
@andresmachado
andresmachado / beautiful_idiomatic_python.md
Created December 27, 2016 23:57 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
num = input("Digite um número inteiro: ")
total = 0
i = 0
while i < len(num):
total += int(num[i])
i += 1
print(total)
def format_result_color(self, obj):
if obj.media == 'A':
color = 'green'
elif obj.media == 'R':
color = 'red'
else:
color = 'orange'
return '<p style="color: {}">{}</p>'.format(color, obj.media)
format_result_color.allow_tags = True
#!/usr/bin/python3
from urllib.request import Request, urlopen
busca = input('O que deseja buscar? :')
headers = {'User-Agent': 'Mozilla/5.0'}
url = Request('http://www.google.com.br/search?q=' + busca, headers=headers)
response = urlopen(url).read()
response = response.decode('utf8')