Skip to content

Instantly share code, notes, and snippets.

🐛
python

Jordi Collell jordic

🐛
python
Block or report user

Report or block jordic

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
View snippets.jsx
const MyFunctionnalComponent: React.FC = props => {
useEffect(() => {
// Using an IIFE
(async function anyNameFunction() {
await loadContent();
})();
}, []);
return <div></div>;
View gist:1239ba7681db41e045dfd6473e6708a8
docker run --rm -e 'TESTING=jenkins' -e 'DATABASE=postgres' -v /var/run/docker.sock:/var/run/docker.sock checkout:PR-173.1 'py.test checkout/tests/ -x -s -v'
Traceback (most recent call last):
File "/usr/local/bin/py.test", line 10, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 61, in main
config = _prepareconfig(args, plugins)
File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 182, in _prepareconfig
config = get_config()
File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 156, in get_config
pluginmanager.import_plugin(spec)
@jordic
jordic / main.js
Last active Jul 7, 2019
order of exec
View main.js
const out = () => console.log("Hola 2")
const out2 = () => console.log("Hola 4")
console.log("Hola 1")
out()
console.log("Hola 3")
Promise.resolve().then(out2)
console.log("Hola 5")
View fibonacci.py
import asyncio
async def fibonacci(n: int, c: asyncio.Queue):
i, x, y = 0, 0, 1
while(i < n):
print(f"produccing {i}")
await c.put(x)
x, y = y, x + y
@jordic
jordic / registry.py
Created Apr 24, 2019
async zope registry
View registry.py
##############################################################################
#
# Copyright (c) 2006 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
View snippets.py
_, pending = await asyncio.wait(
[handler_task, receiver_task], return_when=asyncio.FIRST_COMPLETED,
)
await _cancel_tasks(pending)
@jordic
jordic / guillotina_alchemy.py
Created Apr 11, 2019
guillotina_alchemy.py
View 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 Jan 13, 2019
Zope on an aiohttp server
View app.py
"""
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 .
View configure.py
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 Oct 31, 2018
Apache LB controller python
View balancer.py
import re
import requests
_nonce = r'&nonce=([a-f0-9\-]+)'
class Balancer(object):
def __init__(self, url, balancer="myzopelb"):
You can’t perform that action at this time.