π
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 datetime import timedelta | |
from coredis import Redis | |
redis = Redis.from_url("redis://localhost:6379", decode_responses=True) | |
async def idempotent(key: str, ttl: timedelta | int | None = 60) -> bool: | |
""" | |
Shields code from being run multiple times. | |
""" | |
return bool( |
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 pickle | |
from typing import Any, Set, Type, TypeVar | |
from redis.asyncio import Redis | |
from redis.typing import AbsExpiryT, ExpiryT, KeyT, ResponseT | |
T = TypeVar("T") | |
class TypedRedis(Redis): |
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 datetime import timedelta | |
from redis import Redis | |
def pydempotent(redis: Redis, ttl: timedelta | int | None, key: str): | |
""" | |
Shields a block of code from repeated execution. | |
""" | |
return redis.set(f"pydempotent:{key}", 1, nx=True, ex=ttl) | |
redis = Redis.from_url("redis://localhost:6379") |
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 | |
class AsyncObj: | |
def __init__(self, name): | |
self.name = name | |
async def __aenter__(self): | |
await asyncio.sleep(1) | |
print(f"Hello {self.name}!") | |
return self |
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
services: | |
redis-master: | |
image: redis:latest | |
container_name: redis-master | |
hostname: redis-master | |
ports: | |
- "6379:6379" | |
volumes: | |
- ./data/master:/data | |
command: |
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/sh | |
echo "you've been pwned!" |
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 typing import Generic, TypeVar | |
from pydantic import BaseModel, Field | |
from sqlmodel import Session, func | |
M = TypeVar("M", bound=BaseModel) | |
class QueryResults(BaseModel, Generic[M]): | |
count: int |
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
-- add this line above the servers variable in nvim-lspconfig's setup function: | |
local vue_path = require('mason-registry').get_package('vue-language-server'):get_install_path() .. '/node_modules/@vue/language-server' | |
-- modify your existing LSP plugins like so: | |
local servers = { | |
ts_ls = { | |
init_options = { | |
plugins = { | |
{ | |
name = '@vue/typescript-plugin', | |
location = vue_path, |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.17; | |
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
contract DecentralizedStockWithAMM is ERC20 { | |
uint public reserveToken; | |
uint public reserveEther; | |