A Pen by Andre Machado on CodePen.
A Pen by Andre Machado on CodePen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def count_words(text_file): | |
file = open(textfile,'r+') | |
word_list = {} | |
for word in file.read().split(): | |
if word not in word_list: | |
word_list[word] = 1 | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TenantFormMixin(object): | |
def get_context_data(self, *args, **kwargs): | |
context = super(TenantFormMixin, self).get_context_data(**kwargs) | |
context['tenant_form'] = TenantForm(prefix='tenant') | |
return context | |
def create_tenant_form(self, request, *args, **kwargs): | |
estate = get_object_or_404(Property, pk=self.kwargs['estate_id']) | |
self.tenant_form = TenantForm(self.request.POST, prefix='tenant') | |
if self.tenant_form.is_valid(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num = input("Digite um número inteiro: ") | |
total = 0 | |
i = 0 | |
while i < len(num): | |
total += int(num[i]) | |
i += 1 | |
print(total) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ItemSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Item | |
fields = ( | |
'field1', | |
'field2' | |
) | |
class CategorySerializer(serializers.ModelSerializer): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | |
OlderNewer