This file contains 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 | |
from fastapi import FastAPI, Depends | |
from starlette.websockets import WebSocket | |
import redis.asyncio as redis | |
app = FastAPI() | |
redis_connection_pool = redis.ConnectionPool( | |
host='...', |
This file contains 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 time | |
import aiohttp | |
import requests | |
from typing import List, Callable | |
def get_user_info(user_id: int) -> dict | None: | |
response = requests.get(f"http://127.0.0.1:8000/user/{user_id}").json() | |
if 'ok' not in response or not response['ok']: |
This file contains 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
package main | |
import ( | |
"context" | |
"fmt" | |
"github.com/redis/go-redis/v9" | |
"log" | |
"time" | |
) |
This file contains 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
package main | |
import ( | |
"context" | |
"errors" | |
"fmt" | |
"github.com/redis/go-redis/v9" | |
"sync" | |
"time" | |
) |
This file contains 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
redis.replicate_commands() | |
local rate_limit_key = KEYS[1] | |
local burst = ARGV[1] | |
local emission_interval = tonumber(ARGV[2]) | |
-- calculating time using this idea (https://github.com/rwz/redis-gcra/blob/master/vendor/perform_gcra_ratelimit.lua) | |
local jan_1_2017 = 1483228800 | |
local now = redis.call("TIME") | |
now = (now[1] - jan_1_2017) + (now[2] / 1000000) |
This file contains 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
//go:embed gcra.lua | |
var gcraScript string | |
type RateLimit struct { | |
rdb *redis.Client | |
prefix string | |
gcra *redis.Script | |
timeout time.Duration | |
} |
This file contains 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
func Render(c echo.Context, comp templ.Component) error { | |
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML) | |
return comp.Render(c.Request().Context(), c.Response().Writer) | |
} |
This file contains 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
/* | |
create a file and name it: food | |
meat kebab 5 | |
meat stake 5 | |
meat ice-cream 0 | |
meat baklava 0 | |
meat tea 0 | |
meat coffee 0 | |
meat burger 4 | |
meat hot-dog 2 |
This file contains 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
func validateInitData(inputData, botToken string) (bool, error) { | |
initData, err := url.ParseQuery(inputData) | |
if err != nil { | |
logrus.WithError(err).Errorln("couldn't parse web app input data") | |
return false, err | |
} | |
dataCheckString := make([]string, 0, len(initData)) | |
for k, v := range initData { | |
if k == "hash" { |