Skip to content

Instantly share code, notes, and snippets.

@webdeb
webdeb / ustore.py
Last active January 30, 2024 08:54
Simple json file storage with jsonpath access
import os
import json
import uasyncio as asyncio
class Store:
is_loading = False
is_saving_scheduled = False
data = None
@webdeb
webdeb / useCloudDB.ts
Last active March 31, 2024 14:46
useCloudDB for TG
import { useCloudStorage } from "@tma.js/sdk-react"
import { useEffect, useState } from "react"
type OP = 'addItem' | 'getAll' | 'purge'
const createKeys = (length: number, idxKey: Function): string[] => Array.from({ length: length }).map((_, idx: number) => idxKey(idx))
export const useCloudDB = (tableName: string, threshold: number) => {
const cs = useCloudStorage()
const [busy, setBusy] = useState(false)
const [threshReached, setThreshReached] = useState(false)
import { BitBuilder, BitReader, Cell, beginCell } from "@ton/ton";
const OFFCHAIN_CONTENT_PREFIX = 0x01;
export function encodeOffChainContent(content: string) {
let data = Buffer.from(content);
let offChainPrefix = Buffer.from([OFFCHAIN_CONTENT_PREFIX]);
data = Buffer.concat([offChainPrefix, data]);
return makeSnakeCell(data);
}