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
<!DOCTYPE html> | |
<html> | |
<body> | |
<h1>Testiong Sonoff mini REST API</h1> | |
<button id="turnON" type="button">Turn ON</button> | |
</body> |
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/env python3 | |
def count_digits(n, digit): | |
"""Return the number of times digit appears in the squares of the sequence 1..n. | |
Example: | |
count_digits(10, 1) = 4 | |
# 1, 2, 3, 4, ..., 9, 10 --> 1, 4, 9, 16, ..., 81, 100 | |
""" |
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
"""" | |
When you wanna validate dynamically different image size in Django forms and model forms | |
"""" | |
# settings.py | |
DEFAULT_THUMBNAILS_DIMENSION = ( | |
os.getenv('THUMBNAIL_WIDTH_PX', 300), os.getenv('THUMBNAIL_HEIGHT_PX', 300) | |
) |
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
# Setup to development testing without touch CMS API: | |
# /triller_cms/settings/base.py | |
TRILLER_CMS_OLD_API_URL = 'https://development-social.triller.co/v1.5/' | |
#TRILLER_CMS_API_URL = 'http://api.staging.triller.co/v1.5/cms-api' | |
TRILLER_CMS_API_URL = '' | |
# triller_cms/settings/development.py | |
#TRILLER_CMS_API_URL = os.getenv('CMS_API_URL', 'https://development-social.triller.co/v1.5/cms-api') | |
# triller_cms/settings/docker.py |
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 ModelSchemaMixin: | |
model = None | |
def create(self, validated_data): | |
if not model: | |
raise serializers.ValidationError('There is no model defined.') | |
return self.model.objects.create(**validated_data) |
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 string import Template | |
class DefaultTemplateTag(Template): | |
delimiter = '{{' | |
pattern = ''' | |
\{\{(?: | |
(?P<escaped>\{\{)| | |
(?P<named>[_a-z][_a-z0-9]*)\}\}| | |
(?P<braced>[_a-z][_a-z0-9]*)\}\}| |
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 openpyxl import load_workbook | |
wb = load_workbook(filename='ic5.xlsx', read_only=True) | |
ws = wb.get_sheet_by_name('Sheet1') | |
def iter_rows(ws): | |
for row in ws.iter_rows(): | |
yield[cell.value for cell in 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
class PersonTestCase(TestCase): | |
def test_should_return_attributes(self): | |
fields = ('first_name', 'last_name', 'age') | |
for field in fields: | |
with self.subTest(): | |
self.assertTrue(hasattr(Person, field)) |
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
2018-06-14 21:04:37 [scrapy.utils.log] INFO: Scrapy 1.5.0 started (bot: celesc) | |
2018-06-14 21:04:37 [scrapy.utils.log] INFO: Versions: lxml 4.2.1.0, libxml2 2.9.8, cssselect 1.0.3, parsel 1.4.0, w3lib 1.19.0, Twisted 18.4.0, Python 2.7.12 (default, Jun 13 2018, 21:52:00) - [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)], pyOpenSSL 18.0.0 (OpenSSL 1.1.0h 27 Mar 2018), cryptography 2.2.2, Platform Darwin-17.5.0-x86_64-i386-64bit | |
2018-06-14 21:04:37 [py.warnings] WARNING: /Users/marcelorsa/.pyenv/versions/pague_verde_bots/lib/python2.7/site-packages/scrapy/utils/deprecate.py:156: ScrapyDeprecationWarning: `scrapy.telnet.TelnetConsole` class is deprecated, use `scrapy.extensions.telnet.TelnetConsole` instead | |
ScrapyDeprecationWarning) | |
2018-06-14 21:04:37 [scrapy.middleware] INFO: Enabled extensions: | |
['scrapy.extensions.corestats.CoreStats', | |
'scrapy.extensions.feedexport.FeedExporter', | |
'scrapy.extensions.memusage.MemoryUsage', | |
'scrapy.extensions.logstats.LogStats'] |
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
>>> fruit = 'apple' | |
>>> fruit is 'apple' | |
True | |
>>> fruit == 'apple' | |
True | |
>> id(fruit), id('apple') | |
(140031285906720, 140031285906720) | |
>>> id(fruit), id('orange') |
NewerOlder