Skip to content

Instantly share code, notes, and snippets.

@dakom
dakom / route.rs
Created February 14, 2023 16:54
rust frontend page routing example w/ pure web_sys
use wasm_bindgen::JsValue;
use web_sys::{window, Url};
#[derive(Debug, Clone, PartialEq)]
pub enum Route {
Home,
Profile {
// optional user id
// None means "me"
user_id: Option<String>
@dakom
dakom / cosmwasm_vm_gas_profile.rs
Last active November 17, 2022 15:34
cosmwasm vm gas profiling
// EXAMPLE:
// let contract_1 = Contract::new("contract_1", contract_1::msg::InstantiateMsg{});
// let (gas_used, resp) = contract_1.execute(contract_1::msg::ExecuteMsg::Foo{inner_msg_data: "bar"});
// println!("computational gas used: {}", gas);
// println!("execution response: {:?}", resp);
//
// storage actions can also be calculated by estimating as follows:
@dakom
dakom / terra.ts
Last active April 2, 2022 19:54
Terra helpers
import {AccAddress, Coins, Wallet, CreateTxOptions, MsgStoreCode, MsgInstantiateContract, MsgExecuteContract} from "@terra-money/terra.js";
import {TxResult} from '@terra-dev/wallet-types';
// frequency of polling a transaction to see if it's ready
export const DEFAULT_TRANSACTION_INFO_POLL_WAIT:number = 500; //500ms
// amount of time to wait before giving up on transaction finishing
export const DEFAULT_TRANSACTION_INFO_TIMEOUT:number = 1000 * 60 * 5; // 5 mins
// amount of time to wait after uploading, due to localterra weirdness
@dakom
dakom / cosmwasm notes.md
Last active November 19, 2023 08:49
Cosmwasm notes

Wasmd setup

Basic WASMD Setup

after make install (or on apple silicon: LEDGER_ENABLED=false make install)

our chain-id is going to be localwasmd our gas denomination is going to be configured to uwasm staking denomination is the default ustake

the following sortof mimics the explicit steps in https://github.com/CosmWasm/wasmd/blob/main/contrib/local/setup_wasmd.sh

@dakom
dakom / run.sh
Created December 22, 2021 18:09
Re-run some command until clean exit
#!/bin/sh
until cargo +nightly run --bin parse
do
echo "crashed with exit code $?. Respawning.." >&2
sleep 1
done
@dakom
dakom / socat port tunnel.txt
Last active December 22, 2021 18:10
forward ports
this will allow connections to local machines local port to be forwarded to remote_ip and remote port
socat tcp-listen:[LOCAL_PORT],reuseaddr,fork tcp:[REMOTE_IP]:[REMOTE_PORT]
@dakom
dakom / Components Snippets.json
Last active January 19, 2021 15:49
components snippets
{
"ComponentSetup": {
"scope": "javascript,typescript",
"body": [
"import {argsToAttrs} from \"@utils/attributes\";",
"import \"@elements/path/to/$2\";",
"",
"export default {",
"\ttitle: \"\"",
"}",
@dakom
dakom / wasm-async-002.md
Created October 22, 2020 08:08
Rust Async notes from Pauan

(I asked): what's the reason for async requiring its data to be 'static? I want to say it's because of multithreading, that the async runtime is free to move everything between threads... but that doesn't apply with JS...

Pauan answered:

@dakom nothing to do with multithreading all heap allocated things must be 'static, because they outlive the stack references are always on the stack therefore they cannot outlive the stack so if you put something onto the heap... such as by using Box, or Rc...

Bullet points

  • spawn_local will drop its owned data when the future completes. If the future never completes, it's a memory leak.
  • same with future_to_promise (holding/dropping the promise won't help)
  • ideally a Future should be held so that it can be dropped at any point, thereby avoiding leaks even if the future doesn't complete - e.g. keeping things as proper Rust Futures all the way.

Demos

@dakom
dakom / Rust Snippets.md
Created February 12, 2020 13:34
Rust snippets