Skip to content

Instantly share code, notes, and snippets.

import streamlit as st
import aiohttp
import asyncio
async def fetch(session, url):
try:
async with session.get(url) as response:
result = await response.json()
return result
@bgromov
bgromov / pandas-query.md
Last active November 3, 2022 10:10
Pandas: DataFrame.query() for complex data types

Pandas: DataFrame.query() for complex data types

Consider the following pandas DataFrame:

df = pd.DataFrame([[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]], [[0, 1, 2]]], columns=['a'])
 a
@mcarilli
mcarilli / gradient_accumulation.py
Last active June 30, 2023 12:21
Minimal example of gradient accumulation, allreducing only on step() iterations and interacting properly with torch.cuda.amp
# For single-node, run this script via
# python -m torch.distributed.launch --nproc_per_node=<ngpus this node> example.py
#
# For multinode, see https://pytorch.org/docs/stable/distributed.html#launch-utility
#
# Example showing native mixed precision tools
# (torch.cuda.amp.GradScaler and torch.cuda.amp.autocast)
# used along with native DistributedDataParallel to perform
# gradient accumulation with allreduces only when stepping.
#
@the-data-pro
the-data-pro / 01_multi_select_widget_readme.md
Last active November 22, 2024 14:07 — forked from pbugnion/01_multi_select_widget_readme.md
Multiple checkbox selection with searching with ipywidgets

Multiple selection with checkboxes and search field

This gist is forked from pbugnion's great work on building a searchable multi-checkbox using ipywidgets. You can find that work in this gist.

This version adds compatability with Jupyter Widgets' interactive_output() function, and also makes it easier to see which elements were selected by sorting them to the top. It also makes a few small changes to enable this to work in Jupyter Lab.

Image of dropdown

Usage

@jarodsmk
jarodsmk / orient.py
Created September 23, 2019 11:51
Correct text-image orientation with Python/Tesseract/OpenCV
import cv2
import pytesseract
import urllib
import numpy as np
import re
# Installs: https://www.learnopencv.com/deep-learning-based-text-recognition-ocr-using-tesseract-and-opencv/
if __name__ == '__main__':
@borekb
borekb / README.md
Last active September 15, 2025 09:48
How to link to headings in GitHub issues and pull requests

How to link to headings in GitHub issues and pull requests

If you have an issue comment / PR description on GitHub, it doesn't automatically get anchors / IDs that you could link to:

Screenshot 2019-07-11 at 13

What I like to do is to add a visible # character like this:

Screenshot 2019-07-11 at 13 42 21

@SMotaal
SMotaal / GH - Markup - RST.rst
Last active October 21, 2025 00:27
ReStructuredText Examples

Header 1

Subtitle

Example text.

@twolodzko
twolodzko / ALS Matrix Factorization in Spark.ipynb
Last active July 1, 2023 23:33
Using ALS Matrix Factorization for Making Recommendations in Spark
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@LyleScott
LyleScott / rotate_2d_point.py
Last active March 17, 2025 00:47
Rotate X,Y (2D) coordinates around a point or origin in Python
"""
Lyle Scott, III // [email protected]
Multiple ways to rotate a 2D point around the origin / a point.
Timer benchmark results @ https://gist.github.com/LyleScott/d17e9d314fbe6fc29767d8c5c029c362
"""
from __future__ import print_function
import math
@pierrejoubert73
pierrejoubert73 / markdown-details-collapsible.md
Last active November 5, 2025 16:18
How to add a collapsible section in markdown.

How to add a collapsible section in markdown

1. Example

Click me

Heading

  1. Foo
  2. Bar
    • Baz
  • Qux