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 / index.py
Created December 6, 2020 20:33
guillotina asgi server side python render with zpt
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
@jordic
jordic / Dockerfile
Created October 25, 2020 06:58
CatotronCPU
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 September 13, 2020 19:55
asgi rpc proto
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
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
""")
@jordic
jordic / snippets.jsx
Created December 5, 2019 08:53
React
const MyFunctionnalComponent: React.FC = props => {
useEffect(() => {
// Using an IIFE
(async function anyNameFunction() {
await loadContent();
})();
}, []);
return <div></div>;
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 July 7, 2019 05:26
order of exec
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")
@jordic
jordic / fibonacci.py
Created April 26, 2019 04:47
asyncio
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 April 24, 2019 18:35
async zope registry
##############################################################################
#
# 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
@jordic
jordic / snippets.py
Created April 13, 2019 06:59
snippets
_, pending = await asyncio.wait(
[handler_task, receiver_task], return_when=asyncio.FIRST_COMPLETED,
)
await _cancel_tasks(pending)