Skip to content

Instantly share code, notes, and snippets.

Marcelo Andriolli marceloandriolli

Block or report user

Report or block marceloandriolli

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@marceloandriolli
marceloandriolli / gist:71f264d26a921444732fb7574ad0fdb7
Last active May 17, 2019
Conection docker projects by a specific network
View gist:71f264d26a921444732fb7574ad0fdb7
# Fisrt create a network
docker network create my-pre-existing-network
CMS:
adding at docker-compose.yml
networks:
- default
networks:
default:
@marceloandriolli
marceloandriolli / schema_mixin.py
Last active Apr 23, 2019
Idea to create a mxin that behave like ModelSerializer but with Marshmallow Schema
View schema_mixin.py
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 Nov 21, 2018
Simple email template tags
View simpler.py
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]*)\}\}|
View convert.py
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]
View test_model_fields.py
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))
View scrapy.log
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']
View Python Ids
>>> fruit = 'apple'
>>> fruit is 'apple'
True
>>> fruit == 'apple'
True
>> id(fruit), id('apple')
(140031285906720, 140031285906720)
>>> id(fruit), id('orange')
@marceloandriolli
marceloandriolli / love6.py
Created Nov 22, 2017
Coding Dojo - Stormtech - 22 de Novembro
View love6.py
# The number 6 is a truly great number. Given two int values, a and b,
# return True if either one is 6. Or if their sum or difference is 6.
# Note: the function abs(num) computes the absolute value of a number.
# love6(6, 4) → True
# love6(4, 5) → False
# love6(1, 5) → True
# love6(7,1)
View list1.py
def match_ends(words):
i = 0
for word in words:
if len(word) >= 2 and word[0] == word[-1]:
i += 1
return i
View string1.py
#!/usr/bin/python -tt
# Copyright 2010 Google Inc.
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
# Google's Python Class
# http://code.google.com/edu/languages/google-python-class/
# Basic string exercises
# Fill in the code for the functions below. main() is already set up
You can’t perform that action at this time.