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
| not_found = -1 | |
| import unittest | |
| class TestBinS(unittest.TestCase): | |
| def test_empty(self): | |
| lst = [] | |
| key = 0 | |
| self.assertEquals(binsearch(lst, 0,), -1) | |
| """def test_equal(self): | |
| lst = [0, 0, 0, 0] |
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
| from django.test import TestCase | |
| from django.test.client import Client | |
| from django.contrib.auth.models import User | |
| class TestViews(TestCase): | |
| def setUp(self): | |
| self.test_user = User.objects.create_user(username="test", | |
| password="test", | |
| email="[email protected]") |
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
| In [17]: class A(object): | |
| ....: pass | |
| ....: | |
| In [18]: aa = A() | |
| In [19]: aa.__name__ | |
| --------------------------------------------------------------------------- | |
| AttributeError Traceback (most recent call last) | |
| <ipython-input-19-f5dbf2ef814f> in <module>() |
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 threading | |
| #define a global variable | |
| some_var = 0 | |
| class IncrementThread(threading.Thread): | |
| def run(self): | |
| #we want to read a global variable | |
| #and then increment it | |
| global some_var |
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
| from fabric.api import run, env, cd | |
| from fabric.colors import green | |
| from fabric.context_managers import prefix | |
| import time | |
| env.hosts = ['<your_ip>'] | |
| env.user = '<user_on_server>' | |
| def pull_code(): |
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
| #application.py | |
| from wsgiref.simple_server import make_server | |
| # This is the "Application side" of WSGI | |
| def application(environ, start_response): | |
| response_body = "Hello" | |
| status = "200 OK" | |
| response_headers = [("Content-Length", str(len(response_body)))] | |
| start_response(status, response_headers) |
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
| #application.py | |
| from wsgiref.simple_server import make_server | |
| # This is the "Application side" of WSGI | |
| def application(environ, start_response): | |
| path = environ.get('PATH_INFO') | |
| if path == '/': | |
| response_body = 'Index' | |
| 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
| django-admin.py startproject polls | |
| python manage.py migrate | |
| python manage.py runserver | |
| http://localhost:8000/admin/auth/user/ | |
| python manage.py startapp poll |
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
| # polls/models.py | |
| class Question(models.Model): | |
| question_text = models.CharField(max_length=200) | |
| pub_date = models.DateTimeField('date published') | |
| def __str__(self): | |
| return self.question_text | |
| def was_published_recently(self): | |
| now = timezone.now() |
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
| from rest_framework import serializers | |
| from polls.models import Question | |
| class QuestionSerializer(serializers.ModelSerializer): | |
| class Meta | |
| model = Question | |
| exclude = () |
OlderNewer