This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Load the script from this file into redis, storing its SHA1 hash as an environment variable | |
$ SCRIPT_SHA=$(redis-cli -x script load < gcra.lua) | |
Run the script by addressing its hash, with 1 key (as used by this script) called `myratelimitkey`, | |
with a rate limit of 2 attempts every 1 000 milliseconds (1 second). | |
$ redis-cli EVALSHA $SCRIPT_SHA 1 myratelimitkey 2 1000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from xml.etree import ElementTree as ET | |
from pydantic import BaseModel, Field | |
class XmlElement(BaseModel): | |
tag: str = Field(alias="#") | |
attributes: dict[str, str] = Field(alias="@", default_factory=dict) | |
children: list[str | XmlElement] = Field(alias="c", default_factory=list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script which uses the cached zellij if it exists; | |
# otherwise downloads a fresh copy. | |
# Deletes the cached copy every month. | |
set -euo pipefail | |
launchpath="/tmp/zellij/launch" | |
timepath="/tmp/zellij/last_updated" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Copy a directory tree of files over HTTPS. | |
If HTTP basic auth is required, use an environment variable like | |
`HTTP_BASIC_AUTH="myuser:mypassword"`. | |
""" | |
import os | |
import sys | |
from urllib.request import Request, urlopen | |
from base64 import b64encode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from bs4 import BeautifulSoup | |
import urllib | |
path = '/home/tunisia/Desktop/Project Euler/' | |
for probnum in range(1,444): | |
html = BeautifulSoup(urllib.urlopen('http://projecteuler.net/problem=%d' % probnum)) | |
title = html.h2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
from bs4 import BeautifulSoup | |
import urllib | |
path = '/home/tunisia/Projects/rosalind/' | |
html = BeautifulSoup(urllib.urlopen('http://rosalind.info/problems/list-view/')) | |
tr_all = html.find_all('tr') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import asynccontextmanager | |
import asyncio as aio | |
from playwright.async_api import async_playwright | |
class BrowserPool: | |
def __init__(self, n_tabs=10, executable=None) -> None: | |
self.executable = executable | |
self.n_tabs = n_tabs | |
self.tabs_remaining = n_tabs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio as aio | |
from collections import deque | |
from typing import Awaitable, Iterable, TypeVar | |
T = TypeVar("T") | |
class BaseLimit: | |
async def limit(self, awa: Awaitable[T]) -> T: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import datetime as dt | |
from functools import wraps | |
from typing import Union | |
from httpx import AsyncClient | |
# unless you keep a strong reference to a running task, it can be dropped during execution | |
# https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task | |
_background_tasks = set() |
NewerOlder