Skip to content

Instantly share code, notes, and snippets.

View acarl005's full-sized avatar
🤯
in awe

Andy acarl005

🤯
in awe
View GitHub Profile
@acarl005
acarl005 / matmul.sql
Last active January 31, 2023 01:10
Matrix multiplication using a Postgres Table
DROP TABLE IF EXISTS matrices;
CREATE TABLE matrices (
matrix_id int NOT NULL, -- unique identifier for each matrix
i int NOT NULL, -- row number
j int NOT NULL, -- column number
val decimal NOT NULL, -- the value in this cell
PRIMARY KEY (matrix_id, i, j)
);
-- insert sparse representation of
@acarl005
acarl005 / parallel_requests.py
Last active August 22, 2018 20:14
How to use Python to perform an async task on a variable number of inputs, using a pool approach to limit concurrency. Kind of similar to Promise.map in Bluebird (JavaScript library).
import trio # async task synchronization library
import asks # async version of `requests`
from inspect import iscoroutinefunction
import requests
async def concurrent_map(inputs, task, conc_limit=1000):
"""
Like `map` except it is async. It runs an async function for each item in an iterable, and returns an array of the outputs in the correct order
args:
inputs - iterable of items which are passed to the async function