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 CountAndSay: | |
def say(self, word): | |
numbers = {1:"one", 2:"two", 3:"three"} | |
say = "" | |
while len(word) > 0: | |
it = iter(word) | |
letter = it.next() | |
if letter is not " ": | |
say += numbers[word.count(letter)] + " " + letter + " " | |
word = word.replace(letter, "") |
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 Array | |
def sum | |
sum = 0 | |
self.each do |s| | |
sum += s | |
end | |
sum | |
end | |
end |
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
xml_str = """<root> | |
<row><total>39</total><id_pais>BR </id_pais><id_estado>PE </id_estado> | |
<cidade>NADA</cidade><cidadetrad>NADA</cidadetrad><faturamento>2041343.61</faturamento> | |
</row> | |
<row><total>39</total><id_pais>BR </id_pais><id_estado>CE </id_estado><cidade>NADA</cidade> | |
<cidadetrad>NADA</cidadetrad><faturamento>2041343.61</faturamento> | |
</row> | |
<row><total>39</total><id_pais>BR </id_pais><id_estado>SC </id_estado><cidade>NADA</cidade> | |
<cidadetrad>NADA</cidadetrad><faturamento>2041343.61</faturamento> | |
</row> |
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
from argparse import ArgumentParser | |
parser = ArgumentParser(description="Process some integers") | |
parser.add_argument('integers', metavar='N', type=int, nargs='+', | |
help="an integer for the accumulator") | |
parser.add_argument('--sum', dest='accumulate', action='store_const', | |
const=sum, default=max, | |
help='sum the integers (default find the max)') |
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 httplib | |
conn = httplib.HTTPConnection("www.google.com") | |
conn.request('GET', '/') | |
response = conn.getresponse() | |
response.status # 302 |
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
from django.views.generic import CreateView | |
from library.forms import BookForm | |
class CreateBook(CreateView): | |
template_name = 'create_form.html' | |
success_url = '/books/' | |
form_class = BookForm |
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
#views.py | |
from django.views.generic import UpdateView | |
class UpdateBook(UpdateView): | |
model = Book | |
form_class = BookForm | |
template_name = 'create_form.html' | |
success_url = '/books/' |
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
from unittest import TestCase | |
from my_app.signals import foo_bar | |
class SignalsTestCase(TestCase): | |
def dummy_listener(self, sender, **kwargs): | |
self.times += 1 | |
def test_deve_chamar_o_signal_foo_bar(self): |
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
from django.test.client import RequestFactory | |
from django.utils.unittest import TestCase | |
from myapp.views import my_view | |
class MyViewTestCase(TestCase): | |
def test_my_view_should_return_200_status_code(self): | |
request = RequestFactory().get('url_for_the_view') |
OlderNewer