Skip to content

Instantly share code, notes, and snippets.

View prrao87's full-sized avatar

Prashanth Rao prrao87

View GitHub Profile
@prrao87
prrao87 / httpx-hackernews-async-example.py
Created February 22, 2023 03:45 — forked from danielmichaels/httpx-hackernews-async-example.py
A short realworld example of how to use HTTPX's AsyncClient in a sync class.
"""
HackerNews module.
"""
import logging
import asyncio
from operator import itemgetter
import httpx
@osanseviero
osanseviero / extension.py
Created August 24, 2021 12:39
Question generation chrome extension
""" Chrome Manifest file: https://developer.chrome.com/docs/extensions/mv3/getstarted/
{
"manifest_version": 3,
"name": "Hugging Face Question Generator",
"version": "1.0",
"description": "Generate questions based on selected text",
"permissions": [
"contextMenus",
"storage",
"tabs",
@jeremychone
jeremychone / rust-xp-02-postgresql-sqlx.rs
Created May 11, 2021 05:48
Rust to PostgreSQL with SQLX | Rust By Example
#![allow(unused)] // silence unused warnings while exploring (to comment out)
use sqlx::postgres::{PgPoolOptions, PgRow};
use sqlx::{FromRow, Row};
// Youtube episode: https://youtu.be/VuVOyUbFSI0
// region: Section
// Start postgresql server docker image:
@prrao87
prrao87 / googleColabHold.js
Last active March 25, 2024 07:14
Prevent google colab from disconnecting on chrome (right mouse click -> inspect -> console tab -> insert code)
function ConnectButton(){
console.log("Connect pushed");
document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click()
}
setInterval(ConnectButton,60000);
@prrao87
prrao87 / install_jupyter_venv.sh
Created March 10, 2021 21:30
Commands to manage and install virtual environment for Jupyter Notebook
# Install python ipykernel with environment name
python -m ipykernel install --user --name=<my_env_name>
# List or uninstall existing virtual envs for Jupyter
jupyter kernelspec list
jupyter kernelspec uninstall <my_env_name>
@prrao87
prrao87 / .zshrc
Last active December 21, 2023 20:19 — forked from ines/.zshrc
Command to activate / create Python virtual environmment
# Do not use the alias `python3`
# For this to work properly, explicitly specify the python version as necessary on your system
function venv {
default_envdir=".venv"
envdir=${1:-$default_envdir}
if [ ! -d $envdir ]; then
python3.12 -m venv $envdir
python3.12 -m pip install ruff
echo -e "\x1b[38;5;2m✔ Created virtualenv $envdir\x1b[0m"
@anand2312
anand2312 / pymongo-to-motor.md
Last active May 24, 2024 09:15
pymongo vs Motor

pymongo vs Motor

Motor is an async Python driver for MongoDB.

When should I use Motor?

You should use Motor when you're trying to interact with a MongoDB database in an asynchronous context. When you're making something that needs to be asynchronous (like a web server, or most commonly from what I've seen here, Discord bots), you also want all the database calls to be done asynchronously. But pymongo is synchronous, i.e it is blocking, and will block the execution of your asynchronous program for the time that it is talking to the database.

Okay, How do I switch now?!

Thankfully for us, switching from pymongo to Motor isn't too hard, and won't need you to change much code. This process can be roughly summarized as:

Step 1: Install Motor, and import it

Installing can be done with pip - pip install motor

@danielmichaels
danielmichaels / httpx-hackernews-async-example.py
Created July 5, 2020 10:27
A short realworld example of how to use HTTPX's AsyncClient in a sync class.
"""
HackerNews module.
"""
import logging
import asyncio
from operator import itemgetter
import httpx
@ines
ines / .zshrc
Last active February 28, 2021 19:42
Command to activate / create Python virtual environmment
function venv {
default_envdir=".env"
envdir=${1:-$default_envdir}
if [ ! -d $envdir ]; then
python -m venv $envdir
pip install ipython black flake8
echo -e "\x1b[38;5;2m✔ Created virtualenv $envdir\x1b[0m"
fi
source $envdir/bin/activate