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
"""" | |
Simple example of how to use a @property decorator | |
""" | |
class Hellofy: | |
def __init__(self, name, message): | |
self.name = name | |
self.message = message |
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 timeit | |
def test_fstring(): | |
for string in range(1000): | |
f'{string}' | |
def test_format(): | |
for string in range(1000): |
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
""" | |
Exemple of exceptions and type validation | |
""" | |
class Dog: | |
def __init__(self, name): | |
self.name = name |
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
""" | |
Example do demonstrate Python's Duck Typing | |
In [1]: from collections import Container | |
In [2]: Container.__abstractmethods__ | |
Out[3]: frozenset({'__contains__'}) | |
""" |
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 LongNameDict(dict): | |
def longest_value(self): | |
longest = None | |
for key, value in self.items(): | |
if not longest or len(value) > len(longest): | |
longest = value | |
return longest | |
names = LongNameDict(first='josé', second='schwarzenegger') |
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
""" | |
Simple example to explain how to extend built-in python objects | |
""" | |
class PowerList(list): | |
def search(self, name): | |
results = [] | |
for obj in self: | |
if obj == name: | |
results.append(name) | |
return results |
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
alias manage='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py' | |
alias test='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py test' | |
alias runserver='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py runserver' | |
alias makemigrations='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py makemigrations' | |
alias migrate='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py migrate' | |
alias shell='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py shell' | |
alias shellp='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py shell_plus' |
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 os | |
from django.conf.urls import url, include | |
from django.urls import set_urlconf, resolve, reverse | |
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'eventex.settings') | |
def index(request): pass | |
def auth(request): pass |
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
manage graph_models subscriptions | dot -Tpng -o test.png |
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
$('.btn').click(function () { | |
$('.text').text('loading...'); | |
$.ajax({ | |
type:"GET", | |
url:"https://api.meetup.com/2/cities", | |
success: function (data) { | |
$('.text').html(''); | |
for(var i=0;i < data.results.length;i++){ | |
var place = data.results[i].city | |
$('.text').append('<p>'+place+'</p>'); |