This file contains hidden or 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 re | |
ip = "1.2.3.4" | |
ipregex = re.compile("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$") | |
test = ipregex.match(ip) | |
if test: | |
print("Valid") | |
else: | |
print("Not valid") |
This file contains hidden or 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
<ul class="pagination"> | |
{% if page.has_previous %} | |
<li><a href="?page={{ page.previous_page_number }}"><span>«</span></a></li> | |
{% else %} | |
<li class="disabled"><span>«</span></li> | |
{% endif %} | |
{% for i in paginator.page_range %} | |
{% if page.number == i %} | |
<li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li> | |
{% else %} |
This file contains hidden or 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 PublishedManager(models.Manager): | |
def get_queryset(self): | |
return super(PublishedManager, self).get_queryset().filter(status='published') | |
class Post(models.Model): | |
STATUS_CHOICES = ( | |
('draft', 'Draft'), | |
('published', 'Published') | |
) |
This file contains hidden or 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 home(request): | |
values = request.META.items() | |
html = [] | |
for k, v in values: | |
html.append('<tr><td>%s</td><td>%s</td></tr>' % (k, v)) | |
return HttpResponse('<table>%s</table>' % '\n'.join(html)) |
This file contains hidden or 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
""" | |
Regras do FizzBuzz | |
1. Se a posição for multipla de 3: fizz | |
2. Se a posição for multipla de 5: buzz | |
3. Se a posição dor multipla de 3 e 5: fizzbuzz | |
4. Para qualquer outra posição fale o próprio numero. | |
""" | |
from functools import partial |
This file contains hidden or 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
"" | |
Remove os numeros das páginas que estão fora de posição no texto Madame Bovary. | |
""" | |
import re | |
import fileinput | |
for linha in fileinput.input("Madame-Bovary-Gustave-Flaubert.txt", inplace=True): | |
print(re.sub("\d+", "", linha)) | |
NewerOlder