Skip to content

Instantly share code, notes, and snippets.

Avatar
🐛
python

Jordi Collell jordic

🐛
python
View GitHub Profile
@jordic
jordic / index.py
Created Dec 6, 2020
guillotina asgi server side python render with zpt
View index.py
from . import templates
from guillotina.entrypoint import app as guillo
from starlette.applications import Starlette
from starlette.responses import PlainTextResponse
from starlette.responses import JSONResponse
from guillotina.component import get_utility
from guillotina.interfaces import IApplication
from guillotina.utils.content import get_database
from guillotina.utils.content import navigate_to
from guillotina import task_vars
View Dockerfile
FROM python:3.7.3
# based on a git clone from https://github.com/CollectivaT-dev/catotron-cpu
# plus embedding voices.
# also fixed requirements.txt
# -matplotlib==2.1.0
# +numba==0.48
# +matplotlib==3.3.2
# numpy==1.18.0
# inflect==0.2.5
@jordic
jordic / arpc.py
Created Sep 13, 2020
asgi rpc proto
View arpc.py
from functools import partial
from imaplib import Int2AP
from starlette.responses import JSONResponse
from starlette.applications import Starlette
from starlette.routing import Route
import httpx
import json
import pydantic as pd
import random
View models.py
import textwrap
sql = textwrap.dedent("""
SELECT t1.field1,
t2.field2,
t3.field3
FROM table1 t1
INNER JOIN table2 t2 using(id_relation)
WHERE t1.pk = $1
""")
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)