Skip to content

Instantly share code, notes, and snippets.

View yeus's full-sized avatar

Thomas Meschede yeus

View GitHub Profile
@Vova-SH
Vova-SH / install_ha_2022_7_5.sh
Created July 24, 2022 14:14
Shell script for install HomeAssistant on Termux
pkg update
apt-get update
pkg upgrade
pkg install openssh
pkg install python nano make rust libcrypt libffi libjpeg-turbo binutils
pkg install mosquitto termux-api
python -m venv hass
@yeus
yeus / rate_limiter.py
Last active December 2, 2021 19:25
async rate limiting function using token bucket algorithm
"""
author: Thomas Meschede
license: MIT
"""
def rate_limit_burst(max_calls: float, interval: float):
"""
Rate-limits the decorated function locally, for one process. Using Token Bucket algorithm.
max_calls: maximum number of calls of function in interval
import { Component, defineAsyncComponent, defineComponent, h } from 'vue'
export function hydrateNever(componentOrFactory: Component): Component {
return makeHydrationBlocker(componentOrFactory, {
beforeCreate() {
this.never = true
},
})
}
@alyssais
alyssais / default.nix
Created January 22, 2019 11:32
Nix expression for building a reveal.js presentation using pandoc.
{ pkgs ? import (builtins.fetchTarball {
# nixpkgs-unstable 2019-01-22
url = https://github.com/NixOS/nixpkgs/archive/a5de41088031e6d3d4f799ef3964317a74e72169.tar.gz;
sha256 = "0ycsai65dbcwmns36a0pkxpsgpl86q273c27ag80nijfb1w88201";
}) {}
, revealjs ? pkgs.fetchFromGitHub {
owner = "hakimel";
repo = "reveal.js";
rev = "3.7.0";
@txomon
txomon / ratelimit.py
Created August 12, 2018 21:24
Rate limit python asyncio
import asyncio
import collections
async def ratelimit(*, max_request, in_interval):
slots = collections.deque()
while True:
slots.append(time() + in_interval)
yield
while len(slots) >= max_request:
left = slots[0] - time()
@fpt
fpt / pykka_periodic.py
Created November 28, 2014 04:43
Pykka: periodic timer
#!/usr/bin/env python
# coding:utf-8
import pykka
import threading
import signal
import time
import sys
@ctokheim
ctokheim / cython_tricks.md
Last active March 4, 2024 23:27
cython tricks

Cython

Cython has two major benefits:

  1. Making python code faster, particularly things that can't be done in scipy/numpy
  2. Wrapping/interfacing with C/C++ code

Cython gains most of it's benefit from statically typing arguments. However, statically typing is not required, in fact, regular python code is valid cython (but don't expect much of a speed up). By incrementally adding more type information, the code can speed up by several factors. This gist just provides a very basic usage of cython.

//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Created: 2010/12/05
// Updated: 2018/09/12
// License: MIT
//
// Copyright (c) 2010-2018 Diego Perini (http://www.iport.it)
//