Extracted from http://kse.ninja/AnOpenLoveLetterToReact.pdf
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
import sqlalchemy as sa | |
from sqlalchemy.ext.declarative import declarative_base | |
Base = declarative_base(cls=FolderDB) | |
@implementer(IOpiniones) | |
class Opinion(Base): | |
__tablename__ = 'opiniones' | |
id_opinion = sa.Column( |
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
""" | |
This is just a proof of concept after reading this thread on waitress github issues | |
https://github.com/Pylons/waitress/issues/180 | |
Running zope on an aiohttp app: | |
python3.7 -m venv zope4 | |
source zope4/bin/activate | |
cd zope4 | |
pip install Zope==4.0b8 -c https://zopefoundation.github.io/Zope/releases/4.0b8/constraints.txt | |
bin/mkwsgiinstance -d . |
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 plone.rest.zcml import serviceDirective | |
class service(_base_decorator): | |
def __call__(self, klass): | |
global context | |
method = self.config.get('method', 'GET') | |
accept = self.config.get('accept', u"application/json") | |
permission = self.config.pop('permission', 'zope2.View') | |
for_ = self.config.pop("for_", Interface) | |
serviceDirective( |
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
import re | |
import requests | |
_nonce = r'&nonce=([a-f0-9\-]+)' | |
class Balancer(object): | |
def __init__(self, url, balancer="myzopelb"): |
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
""" Some snippets I'm collecting throught sqlalchemy docs """ | |
class User(Base): | |
__tablename__ = 'user' | |
id = Column(Integer, primary_key=True) | |
def _get_addresses(self): | |
return object_session(self).query(Address).with_parent(self).filter(...).all() | |
addresses = property(_get_addresses) |
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
def getSize(obj): | |
"""Calculate the size as cheap as possible | |
""" | |
# Try the cheap variants first. | |
# Actually the checks ensure the code never fails but beeing sure | |
# is better. | |
try: | |
# check if to return zero (length is zero) | |
if len(obj) == 0: | |
return 0 |
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
async def test_websocket_receive_json(loop, aiohttp_client): | |
async def handler(request): | |
ws = web.WebSocketResponse() | |
await ws.prepare(request) | |
data = await ws.receive_json() | |
answer = data['test'] | |
await ws.send_str(answer) |
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
# We want to automatically import all of the warehouse.cli.* modules so that | |
# any commands registered in any of them will be discovered. | |
for _, name, _ in pkgutil.walk_packages(__path__, prefix=__name__ + "."): | |
importlib.import_module(name) |
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
### Keybase proof | |
I hereby claim: | |
* I am jordic on github. | |
* I am jordic (https://keybase.io/jordic) on keybase. | |
* I have a public key ASBddQ4K_dSlQdAH994Gyovq8hUomUTx-g5DKgCcUWUaSQo | |
To claim this, I am signing this object: |