Skip to content

Instantly share code, notes, and snippets.

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);
}
@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)
@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 / levels.py
Last active June 10, 2023 13:20
Simple Inputs ladder on single ADC pin.
import uasyncio as asyncio
from machine import ADC
import time
class Levels:
_last_level = None
debounce_ms = 200
none_level = 65000
callbacks = {}
@webdeb
webdeb / useLazyQuery.js
Created May 31, 2022 17:36
useLazyQuery for Blitz.js
import { useState } from "react"
import { useQuery } from "blitz"
const useLazyQuery = (resolver, inputArg, options = {}) => {
const [enabled, setEnabled] = useState(false)
const [result, extras] = useQuery(resolver, inputArg, {
...options,
enabled,
suspense: false,
onSettled: () => setEnabled(false),
@webdeb
webdeb / Mailgun.ts
Created November 5, 2020 23:51
Simple deno mailgun client
export default class MailgunClient {
apiKey: string;
domain: string;
defaults?: {
from?: string;
subject?: string;
};
constructor(apiKey: string, domain: string, defaults?: Record<string, any>) {
this.apiKey = apiKey;
@webdeb
webdeb / Hasura Keycloak.md
Last active October 29, 2022 19:03
Basic Keycloak Script Mapper to provide Hasura claims

Steps to provide Hasura Claims in Keycloak generated JWT

  1. Create your realm / client
  2. Inside client configuration go to "Mappers"
  3. Click on "Create"
  4. Name it "hasura"
  5. Choose Mapper Type "Script Mapper"
  6. Add following script to demonstrate how it works
@webdeb
webdeb / IndexFallbackPlug.ex
Created May 7, 2018 01:59
Simple plug to just fallback to the index.html file
defmodule Karta.Web.ReactPlug do
import Plug.Conn
def init(options), do: options
def call(conn, _opts) do
conn
|> put_resp_header("content-type", "text/html; charset=utf-8")
|> Plug.Conn.send_file(200, Application.app_dir(:karta_web, "priv/static/index.html"))
end
# Requires Erlang/OTP 19.0. Invoke as:
#
# iex --erl "-proto_dist Elixir.Epmdless -start_epmd false -epmd_module Elixir.Epmdless_epmd_client" --name frobozz3
# A module containing the function that determines the port number
# based on a node name.
defmodule Epmdless do
def dist_port(name) when is_atom(name) do
dist_port Atom.to_string name
end
самый простой способ зайти по ssh на продакшен и у бинарника которым запускаешь проект выполнить attach_console
[12:45]
или есть сложней способ, сделать тунелирование портов с продакшена
их список можно увидеть запустив команду
`epmd -names`
`ssh -N remote_hose -L port1_from_command_above:localhost:port1_from_command_above -L port2_from_command_above:localhost:port2_from_command_above`
запустить свою локальную версию продакшен проекта с таким же значением куки как и продакшен, и вуаля ты можешь видеть все что происходит на продакшене
например запустить observer (edited)