Skip to content

Instantly share code, notes, and snippets.

View yuvalherziger's full-sized avatar
🍉

Yuval yuvalherziger

🍉
View GitHub Profile
@yuvalherziger
yuvalherziger / aiohttp test coverage badge
Last active August 3, 2022 07:29
aiohttp-catcher coverage badge
aiohttp test coverage badge
@yuvalherziger
yuvalherziger / awaitables.py
Last active January 11, 2022 07:32
awaitables.py
from aiohttp.web import Request
from aiohttp_catcher import catch, Catcher
async def message(exc: MyException, request: Request):
return "This isn't allowed"
async def fields(exc: MyException, req: Request):
return {
"method": req.method,
"error_type": exc.some_error_class_attribute
@yuvalherziger
yuvalherziger / canned_scenarios.py
Created January 6, 2022 19:15
canned scenarios
from aiohttp import web
from aiohttp_catcher import Catcher
from aiohttp_catcher.canned import AIOHTTP_SCENARIOS
async def main():
# Add a catcher:
catcher = Catcher()
# Register aiohttp web errors:
await catcher.add_scenario(*AIOHTTP_SCENARIOS)
@yuvalherziger
yuvalherziger / app.py
Last active January 6, 2022 19:18
app.py
from aiohttp import web
from aiohttp_catcher import catch, Catcher
async def divide(request):
quotient = int(request.query.get("x")) / int(request.query.get("y"))
return web.json_response(data={"quotient": quotient})
msg = "Zero division makes zero sense"
async def main():
@yuvalherziger
yuvalherziger / user.py
Created January 6, 2022 16:43
Sample aiohttp handler
@routes.get("/user/{username}")
async def get_user(request: web.Request):
username = request.match_info.get("username")
if username not in USER_DB:
return web.json_response(
data={"message": "User not found"},
status=404
)
return web.json_response(data=USER_DB.get(username))
@yuvalherziger
yuvalherziger / CustomCompleter.js
Last active November 28, 2023 23:53
Sample Ace Editor custom completer
// fetch ace's language tools module:
var langTools = ace.require('ace/ext/language_tools');
// data stub:
var sqlTables = [
{ name: 'users', description: 'Users in the system' },
{ name: 'userGroups', description: 'User groups to which users belong' },
{ name: 'customers', description: 'Customer entries' },
{ name: 'companies', description: 'Legal entities of customers' },
{ name: 'loginLog', description: 'Log entries for user log-ins' },