Skip to content

Instantly share code, notes, and snippets.

@richardsheridan
richardsheridan / map_concurrently_in_subthread_trio.py
Last active January 2, 2023 22:14
map_concurrently_in_subthread_trio
import queue
import random
from functools import partial
from time import sleep, perf_counter
import trio
CONCURRENCY_LIMIT = 8
limiter = trio.CapacityLimiter(CONCURRENCY_LIMIT)
@jordanisaacs
jordanisaacs / sessioncookie.py
Created April 3, 2021 22:13
Basic implementation with example of a FastAPI SessionCookie (compatible with OpenAPI and dependency injection)
from datetime import timedelta, datetime
from typing import Type, Optional, Dict, Any, Tuple
from uuid import uuid4
from abc import ABC, abstractmethod
from fastapi import FastAPI, Request, Depends, HTTPException, Response
from fastapi.security.api_key import APIKeyBase, APIKey, APIKeyIn
from base64 import b64encode, b64decode
from itsdangerous import TimestampSigner
from itsdangerous.exc import BadTimeSignature, SignatureExpired
@nathanrpage97
nathanrpage97 / test_live.py
Created October 13, 2020 15:34
Showcase of the Live feature branch
import inspect
import random
import time
from typing import Dict, List, Tuple
from rich.console import Console, RenderGroup
from rich.live import Live
from rich.panel import Panel
from rich.progress import Progress
from rich.syntax import Syntax
@beardicus
beardicus / .block
Last active March 19, 2024 21:44
Paper.js Vector Erase
license: mit
border: yes
height: 640
@Evgenus
Evgenus / test_flask_sqlalchemy_txns.py
Last active February 27, 2024 12:45
Proper SQLAlchemy transactions example
from contextlib import contextmanager
import threading
from thread import get_ident
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
#!/bin/bash
# file descriptor
# Change 400000 to increase or decrease number of file descriptor
echo "* soft nofile 400000" >> /etc/security/limits.conf
echo "* hard nofile 400000" >> /etc/security/limits.conf
# Changing kernal parameters (modify value if required)
@SandeepThomas
SandeepThomas / datepickerLocaldateDirective.js
Last active March 8, 2021 00:23 — forked from weberste/gist:354a3f0a9ea58e0ea0de
Dates only with Angular-UI Bootstrap datepicker - In Epoch time / Unix time
app.directive('datepickerLocaldate', ['$parse', function ($parse) {
var directive = {
restrict: 'A',
require: ['ngModel'],
link: link
};
return directive;
function link(scope, element, attr, ctrls) {
var ngModelController = ctrls[0];
@ybastide
ybastide / cached_property.py
Created September 10, 2015 13:41
Cached property, also for static properties
class cached_property(object):
"""
Decorator that converts a method with a single self argument into a
property cached on the instance, or a class method into a property
cached on the class.
Adapted from django/utils/functional.py.
"""
def __init__(self, func):
self.func = func
@chenshaoju
chenshaoju / sysctl.conf
Last active September 7, 2023 06:31
sysctl.conf
#
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additonal system variables
# See sysctl.conf (5) for information.
#
#kernel.domainname = example.com
# Uncomment the following to stop low-level messages on console
#kernel.printk = 3 4 1 3
@madjar
madjar / scrapper.py
Last active March 5, 2023 15:02
A example of scrapper using asyncio and aiohttp
import asyncio
import aiohttp
import bs4
import tqdm
@asyncio.coroutine
def get(*args, **kwargs):
response = yield from aiohttp.request('GET', *args, **kwargs)
return (yield from response.read_and_close(decode=True))