Skip to content

Instantly share code, notes, and snippets.

View devxpy's full-sized avatar

Dev Aggarwal devxpy

View GitHub Profile
set -ex
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
void main() {
Map<int, String> myIntMap = {5: "hello!"};
print(myIntMap["5"]);
}
@devxpy
devxpy / main.py
Last active August 9, 2020 23:43
Script to run startlette & uvicorn in a way that forcefully exits/kills all pending background tasks automatically. A must have for development!
"""
Tired of seeing this annoying message - "Waiting for background tasks to complete."?
This hack can take care of that for you!
Usage -
$ python main.py
Bonus - easy to attach a debugger now
$ python -m pdb main.py
@devxpy
devxpy / async_vs_threads.py
Last active July 14, 2020 22:05
Python asyncio vs ThreadPoolExecutor - inconsistent results for a purely I/O based task
"""
Instructions -
pip install httpx ipython
ipython -i async_vs_threads.py
%timeit asyncio.run(test_threads())
%timeit asyncio.run(test_async())
"""
@devxpy
devxpy / gist:eb0ed8c45cdfe61ca2bb99c98d11ab85
Created July 13, 2020 17:15
Poorna swaraj - by openai gpt3
Sentiments of a broken nation
Separated by religions and the hesitation
Vote banks, industries and corporations
Filthy pockets of the rich and famous
At the cost of poverty and desperation
Facing death and struggling daily
Without having a definite solution
Death and problems has no religion
Respect your neighbour from another nation
Fill the hearts with humanity
void main() {
List<int> x = createList();
}
List<int> createList() {
return ["1", "2", "3", "4", "5"];
}
void main() {
List<int> x = createList();
}
createList() {
return ["1", "2", "3", "4", "5"];
}
#
# Adapted from https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html#capture-video-from-camera
#
import numpy as np
import cv2
caps = [cv2.VideoCapture(i) for i in range(2)] # open 2 camera feeds
while(True):
var start = DateTime.now()
var db = await appSync.getCacheDatabase();
var pages = appSync.paginate(
...,
priority: CachePriority.cache, // Try cache first, then network
cache: db,
);
@devxpy
devxpy / djang_async_crud.py
Last active April 26, 2020 11:49
Django Async CRUD - Basic CRUD operations with Django ORM in an async context
import typing
from django.db import models
from channels.db import database_sync_to_async
M = typing.TypeVar("M", bound=models.Model)
class AsyncCrud: