Skip to content

Instantly share code, notes, and snippets.

View Ronserruya's full-sized avatar
🎮
https://www.youtube.com/watch?v=dQw4w9WgXcQ

Ron Serruya Ronserruya

🎮
https://www.youtube.com/watch?v=dQw4w9WgXcQ
View GitHub Profile
@Ronserruya
Ronserruya / pretty.py
Created June 27, 2021 14:08
pretty validation error
import re
import json
from pydantic import BaseModel, ValidationError, validator, conint
from typing import List, Literal
class Person(BaseModel):
age: conint(ge=0, le=120)
name: str
{"timestamp": 1624283464.7776241, "codes": {"\ud83d\ude00": "grinning face", "\ud83d\ude03": "grinning face with big eyes", "\ud83d\ude04": "grinning face with smiling eyes", "\ud83d\ude01": "beaming face with smiling eyes", "\ud83d\ude06": "grinning squinting face", "\ud83d\ude05": "grinning face with sweat", "\ud83e\udd23": "rolling on the floor laughing", "\ud83d\ude02": "face with tears of joy", "\ud83d\ude42": "slightly smiling face", "\ud83d\ude43": "upside-down face", "\ud83d\ude09": "winking face", "\ud83d\ude0a": "smiling face with smiling eyes", "\ud83d\ude07": "smiling face with halo", "\ud83e\udd70": "smiling face with hearts", "\ud83d\ude0d": "smiling face with heart-eyes", "\ud83e\udd29": "star-struck", "\ud83d\ude18": "face blowing a kiss", "\ud83d\ude17": "kissing face", "\u263a\ufe0f": "smiling face", "\u263a": "smiling face", "\ud83d\ude1a": "kissing face with closed eyes", "\ud83d\ude19": "kissing face with smiling eyes", "\ud83e\udd72": "smiling face with tear", "\ud83d\ude0b": "face savor
@Ronserruya
Ronserruya / middleware.py
Created April 13, 2020 09:51
Access starlette response in middleware
class JsonResponseMiddleware(BaseHTTPMiddleware):
# BaseHTTPMiddleware returns a streaming response that can't be consumed in the middleware
# Instead we consume it here and create a JsonResponse that can be consumed multiple times
async def call_next(self, request: Request) -> Response:
loop = asyncio.get_event_loop()
queue = asyncio.Queue() # type: asyncio.Queue
scope = request.scope
@Ronserruya
Ronserruya / update.py
Created December 3, 2019 14:04
Python merge dicts without overwriting inner values
def update_key(key, value, d: dict):
if key not in d:
d[key] = value
else:
if isinstance(value, dict):
for k, v in value.items():
update_key(k, v, d[key])
else:
raise RuntimeError('Trying to overwrite existing value')
import clashroyale, asyncio
async def top(client):
p = await client.get_top_players()
return p
async def main():
token = "my token"
@Ronserruya
Ronserruya / blabla.cs
Created May 23, 2019 13:50
unity callbacks
Restore(
onSuccess: (KinAccount restoredAccount) =>
{
Debug.Log("Success");
},
onFailure: (KinException ex) =>
{
Debug.LogError(ex);
},
onCancel: () =>
swagger: "2.0"
info:
description: "Micro service to invoke common kin stuff using the kin-python-sdk."
version: "1.0.0"
title: "Kin Python Microservice"
license:
name: "MIT"
url: "https://opensource.org/licenses/MIT"
schemes:
- "https"
swagger: "2.0"
info:
description: "Micro service to invoke common kin stuff using the kin-python-sdk."
version: "1.0.0"
title: "Kin Python Microservice"
license:
name: "MIT"
url: "https://opensource.org/licenses/MIT"
schemes:
- "https"
swagger: "2.0"
info:
description: "Micro service to invoke common kin stuff using the kin-python-sdk."
version: "1.0.0"
title: "Kin Python Microservice"
license:
name: "MIT"
url: "https://opensource.org/licenses/MIT"
schemes:
- "https"