Skip to content

Instantly share code, notes, and snippets.

View marceloandriolli's full-sized avatar

Marcelo Andriolli marceloandriolli

  • Florianopolis, Brazil
View GitHub Profile
@marceloandriolli
marceloandriolli / poc_sonoff_mini_diy.html
Last active April 28, 2021 15:39
POC - Sonoff mini DIY - API
<!DOCTYPE html>
<html>
<body>
<h1>Testiong Sonoff mini REST API</h1>
<button id="turnON" type="button">Turn ON</button>
</body>
@marceloandriolli
marceloandriolli / code_challenge.py
Last active February 4, 2020 14:16
code challenge
#!/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
"""
@marceloandriolli
marceloandriolli / image_dimension_dynamic_validator.py
Last active August 4, 2021 19:54
Django dynamic Image dimension validator
""""
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)
)
@marceloandriolli
marceloandriolli / gist:71f264d26a921444732fb7574ad0fdb7
Last active December 30, 2019 19:45
Conection docker projects by a specific network
# 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
@marceloandriolli
marceloandriolli / schema_mixin.py
Last active April 23, 2019 17:57
Idea to create a mxin that behave like ModelSerializer but with Marshmallow Schema
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)
@marceloandriolli
marceloandriolli / simpler.py
Last active November 21, 2018 01:06
Simple email template tags
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]*)\}\}|
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]
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))
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']
>>> fruit = 'apple'
>>> fruit is 'apple'
True
>>> fruit == 'apple'
True
>> id(fruit), id('apple')
(140031285906720, 140031285906720)
>>> id(fruit), id('orange')