Skip to content

Instantly share code, notes, and snippets.

View jordic's full-sized avatar
🐛
python

Jordi Collell jordic

🐛
python
  • https://tmpo.io
  • Barcelona, ES
View GitHub Profile
@jordic
jordic / guillotina_alchemy.py
Created April 11, 2019 11:58
guillotina_alchemy.py
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(
@jordic
jordic / app.py
Created January 13, 2019 13:38
Zope on an aiohttp server
"""
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 .
@jordic
jordic / configure.py
Created November 5, 2018 05:59
configure
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(
@jordic
jordic / balancer.py
Created October 31, 2018 04:59
Apache LB controller python
import re
import requests
_nonce = r'&nonce=([a-f0-9\-]+)'
class Balancer(object):
def __init__(self, url, balancer="myzopelb"):
@jordic
jordic / snippets.py
Last active October 18, 2018 09:39
snippets sqlalchemy
""" 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)
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
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)
# 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)
### 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:
@jordic
jordic / react.md
Last active March 4, 2017 21:04
React reading and resources