Nginx
tags: Linux
tags: Linux
tags: Nginx source: https://serverfault.com/a/923254 server { # ... location / { # If "Websocket" is in Upgrade header, then @websocket will take effect, # otherwise @ will take effect. try_files /nonexistent @$http_upgrade; } location @websocket { # websocket related stuff } location @ { # web related stuff } }
参考 https://github.com/RobbieXie/2020DecorationNote Ideas 在马桶旁边要留一个插座,用于智能马桶垫; 厨房油烟机机一个光滑斜面可以在餐厅坐着看锅里的情况; 全屋六类线预留 AP 和插座,最好能扩大弱电箱能放进去个 NAS; 面向扫地机器人装修;
tags: Ethereum Knowning Layer 2 Chain Rollup(or bundle) transactions off-chain to reduce fee and scale capacity, such as Bitcoin Lightning. Two layer 2 rollups Optimistic Rollups Zero-Knowledge Rollups Record on-chain state by writing calldata to L1(Ethereum), which more cheaper than change state on L1 chain. Fees Some layer 2 chain like Optimism should plus l1 fee when executing transaction on layer 1.1 Many Ethereum applications display estimated fees to users by multiplying the gas price by the gas limit. However, as discussed earlier, users on Optimism are charged both an L2 execution fee and an L1 data fee. As a result, you should display the sum of both of these fees to give users the most accurate estimate of the total cost of a transaction. ...
tags: Go Elem() Returns Value type T struct { } t := &T{} v := reflect.New(reflect.TypeOf(t)).Elem() // type of v is `T` Interface() Returns Pointer type T struct { } t := &T{} v := reflect.New(reflect.TypeOf(t)).Interface() // type of v is `&T`
tags: Solana 101: Create an Escrow dApp
tags: Solana 101: Create an Escrow dApp 连接钱包 安装 Phantom 钱包; 使用 @solana/wallet-adapter 连接钱包。官方提供了 React 相关的实现,Vue 可以通过社区提供的库:https://github.com/lorisleiva/solana-wallets-vue。 npm install solana-wallets-vue @solana/wallet-adapter-wallets 创建 SPL Token 安装依赖 npm install --save @solana/spl-token 创建代币 通过 Token Program 创建 Token,Solana 通过其特有的账号机制,通过创建一个账号并将 Owner 设置为一个统一的 Token Program 即可发行一种代币。1 发行代币 要持有代币必须创建一个对应的 Associated Token Account(ATA),也就是要接收一个代币首先要检查有没有对应代币的 ATA,没有则创建,然后给对应的 ATA 转移代币。 代币转帐 燃烧代币 SPL Token 交互:授权 Program 转帐 Libraries: spl_associated_token_account Steps: Delegate token to Program – in frontend. Create a Associated Token Account for Program to hold token. Q: How to avoid duplicated initialization? A: data size of account. Program: Transfer token from wallet to Program USDT ↩︎ ...
tags: Solana 101: Create an Escrow dApp
tags: Solana 101: Create an Escrow dApp 链上数据存储 账号所有权 账号可以通过 Metadata 指定一个 Program 作为拥有者(Owner); Program 作为拥有者可以: 修改账号数据; 可以使用该 PDA 进行签名。 PDA(Program Derived Address) 1 使用 PDA 进行合约状态链上存储。 PDA 只有一个类似公钥的地址,但是没有对应的私钥; 链下生成:通过 PublicKey.findProgramAddress 生成 PDA,seeds 用于生成多个 PDA; 链上创建:将 PDA 作为账号传递给 Program 进行链上创建:填充足够的 lamports 用于支付租金、开辟空间、指定 program 作为 Owner。 创建一个计数器 部署智能合约; 生成一个 PDA 并进行链上创建; 增加计数器; 其他账号获取 PDA,并增加计数器; 使用 Anchor 重写计数器 安装 Anchor 安装 Yarn 安装 avm cargo install --git https://github.com/project-serum/anchor avm --locked --force 使用 avm 安装 anchor avm install latest avm use latest 创建 anchor 项目 anchor init hello-anchor anchor 项目结构 Understanding Program Derived Addresses ↩︎ ...
tags: Solana 101: Create an Escrow dApp Account UTXO Unspend Transaction Output. EVM Accounts1 EOA(Externally-owned acount) - 用户用私钥控制的账号; 合约账号(Contract account) - 代码控制的账号,用于部署智能合约代码。 账号模型通过用户地址为用户开辟一块单独的存储,简单的理解就是用公私钥导出的唯一地址作为主键存储在节点的存储系统里(RocksDB); 这样只要将链上转账或者智能合约产生的结果或副作用存储在账号下面即可。 Solana Account Model Accounts2 账号用于提供给智能合约(Program)跨交易存储状态,类似文件系统; 包含元数据(metadata)说明谁有权限访问这些状态; Solana 独特的创新:账号伴有生命周期,也就是对应的私钥并不完全拥有一个账号,而是从链上租借(rent)了一个账号,并支付对应的租金,当租借过期且没有足够的余额(lamports)支付租金的情况下,账号下的数据将被链回收; 一笔交易里可以参与的账号类型有: Signers 一笔交易可以包含一个或多个签名者,表示授权此笔交易(多签机制); Read-only 交易里对该账号只读; Executable 其账号可以作为智能合约进行调用(将其账号对应的公钥地址作为 program id); Programs or Smart Contract3 账号被标记为 Executable 可以部署代码(Program)作为智能合约。两种类型的智能合约: Native Programs – 区块链系统提供的标准库; On Chain Programs – 用户开发部署到链上的智能合约。 同时智能合约可以控制多个其他账号,并且只能修改它所拥有的账号数据,但是可以读取其他账号的数据。 Solana 的 Program 可以被更新。 搭建开发环境 命令行钱包 sh -c "$(curl -sSfL https://release.solana.com/stable/install)" 连接到测试节点 solana config set --url https://api.testnet.solana.com 官方文档是连接到本地节点,这里不太推荐,因为使用测试节点可以结合链浏览器比较直观的观测结果。 ...
tags: Solana 101: Create an Escrow dApp 聊聊区块链 一个完整的区块链系统生态: 主币:进行 gas 费结算:BitCoin / ETH / TRX 等等 节点服务(JSONRPC 2.0):提供数据查询、广播交易,交易广播(P2P -> 挖矿节点); 交易验证:挣取 gas 费,出块奖励(挖矿); PoW(Proof of Work):通过算力证明提供交易验证(出块);sha256(nonce + body) -> sha256 import hashlib from typing import Tuple raw_block = b'block data' dificulty = 5 def proof_my_work(dificulty, raw_block) -> Tuple[int, str]: nonce = 1 while True: body = bytes(nonce) + raw_block h = hashlib.sha256(body) hex_value = h.hexdigest() if hex_value[:dificulty] == '0' * dificulty: return nonce, hex_value nonce += 1 proof_my_work(dificulty, raw_block) PoS(Proof of Stake):通过质押主币提供交易验证,一旦被发现作弊则扣除质押的主币; 链浏览器:通过 Web UI 进行链上数据查询; 钱包 == 私钥:资产证明,交易授权,公钥导出地址,私钥则是证明拥有该地址; 智能合约(Smart Contract):对资产进行编程; 代币(Tokens):基于智能合约实现,Fungible Tokens(ERC20 / TRC20) 和 Non-Fungible Tokens (ERC721) dApp:通过桥接钱包和链上智能合约实现一定的链上操作; 从智能合约来看各个区块链生态之间的区别 主要是虚拟机的区别,为了执行智能合约,区块链系统需要虚拟机来执行代码,目前主流的虚拟机包括: ...
tags: Solana
tags: Python _ = ( 255, lambda V ,B,c :c and Y(V*V+B,B, c -1)if(abs(V)<6)else ( 2+c-4*abs(V)**-0.4)/i ) ;v, x=1500,1000;C=range(v*x );import struct;P=struct.pack;M,\ j ='<QIIHHHH',open('M.bmp','wb').write for X in j('BM'+P(M,v*x*3+26,26,12,v,x,1,24))or C: i ,Y=_;j(P('BBB',*(lambda T:(T*80+T**9 *i-950*T **99,T*70-880*T**18+701* T **9 ,T*i**(1-T**45*2)))(sum( [ Y(0,(A%3/3.+X%v+(X/v+ A/3/3.-x/2)/1j)*2.5 /x -2.7,i)**2 for \ A in C [:9]]) /9) ) ) It generates a Mandelbrot like the code likes:
tags: GTK GTK_DEBUG=interactive my-gtk-app
tags: Cheatsheet, macOS Retrieve Bundle ID osascript -e 'id of app "/usr/local/MacGPG2/libexec/pinentry-mac.app"' osascript -e 'id of app "Finder"'
tags: PostgresQL, Cheatsheet Create User and Role Docs: Examples of Create Role CREATE ROLE whoami WITH LOGIN PASSWORD 'P@ssw0rd'; Create Database Docs: Examples of Create Database CREATE DATABASE sales OWNER whoami;
tags: GPG, GnuPG Agent,Cheatsheet Stop GPG Agent gpg-connect-agent killagent /bye obsolete option “write-env-file” - it has no effect set -gx GPG_TTY (tty) set -gx SSH_AUTH_SOCK (gpgconf --list-dirs agent-ssh-socket) gpgconf --launch gpg-agent
tags: DeFi, Blockchain, Uniswap, Uniswap V3 I need derive price from decentralized exchanges, and I have finished some research about Uniswap v3. It’s brand new for me, and after that I want to share some ideas about DeFi, and I think it would be helpful for you to understand Uniswap and some other decentralized exchanges. DeFi from Scratch We exchange stuffs very often, and we can exchange tokens in a centralized exchange. For example, Alice owns some ETH, and Bob owns some DAI. Now, Alice want to swap some ETH for DAI, and Bob want to swap some DAI for ETH. How could they do? ...
tags: Uniswap V3 source: Shao, 田少谷. “Uniswap v3 Features Explained in Depth.” Taipei Ethereum Meetup (blog), July 20, 2021. https://medium.com/taipei-ethereum-meetup/uniswap-v3-features-explained-in-depth-178cfe45f223. Tick is a price range Each tick is a price range with upper bound and lower bound. Tick price from index: \(p(i) = 1.0001 ^ i\) 1.0001 ** 138162 # 999_998 Tick index from price: \(log_{1.0001}p\) import math math.log(1000_000, base=1.0001) # 138162.01321981344
tags: Uniswap The Graph: Uniswap V3 Subgraph
tags: Blockchain
tags: Blockchain,Ethereum,DeFi
tags: Blockchain,Ethereum source: “Graphical Guide to Understanding Uniswap - EthHub.” Accessed August 23, 2022. https://docs.ethhub.io/guides/graphical-guide-for-understanding-uniswap/. ERC20 tokens are the most common type of token built on top of Ethereum. They are fungible in nature, meaning that there isn’t a distinction between individual tokens. For example, if I have 100 metal marbles in my hand that are all the same size and color, it doesn’t matter which one I give you. In the same way, if I have 100 of the same ERC20 token, it doesn’t matter which one I give you. This contrasts with ERC721 tokens which are non-fungible tokens (NFTs) such as cryptokitties. ...
tags: Makefile source: Davis-Hansson, Jacob. “Your Makefiles Are Wrong.” Jacob Davis-Hansson on Tech, December 15, 2019. https://tech.davis-hansson.com/p/make/. Best Makefile Defaults # Always use bash as the shell. SHELL := bash # Enable bash strict mode. .SHELLFLAGS := -eu -o pipefail -c ## Change some Defaults of Make. # Ensures each Make recipe is ran as one single shell session, # rather than one new shell per line. .ONESHELL: # Delete it's target file if a Make rule fails. .DELETE_ON_ERROR: MAKEFLAGS += --warn-undefined-variables MAKEFLAGS += --no-builtin-rules # Always use GNU Make. ifeq ($(origin .RECIPEPREFIX), undefined) $(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later) endif # Use '>' to instead of tab. .RECIPEPREFIX = >
tags: Online Tools website: https://www.castfeedvalidator.com/
tags: Solana, Solana 101: 1. Develop Model Account: a Memory region The solana term for a memory region is “account”. Some programs own thousands of independent accounts. Programs own accounts, aka the owner of accounts. Transactions and Accounts You can make a program read and write data by sending transactions. Programs provide endpoints that can be called via transactions (In reality it’s a bit more complex than that but frameworks like Anchor abstract away this complexity). A function signature usually takes the following arguments: ...
tags: Solana, Solana 101: 1. Develop Model Program Owns Accounts And each memory region has a program that manages it (sometimes called the “owner”). How to Communicate with Solana Programs? Off-chain This means your programs aren’t on-chain program, you can submit transactions with instructions to the network, it could be done via the JSON RPC API or any SDK built on top this API. On-chain TODO
tags: Rust source: Johnston, Dylan R. “Formally Verifying Rust’s Opaque Types,” August 1, 2022. https://dylanj.xyz/posts/rust-coq-opaque-types/. Prelude trait ToString { fn to_string(&self) -> String; } Static Dispatch fn yell<S: ToString>(stringable: S) { println!(stringable.to_string().to_uppercase()) } Dynamic Dispatch fn yell(stringable: &dyn ToString) { println!(stringable.to_string().to_uppercase()) } impl Trait fn yell(stringable: impl ToString) { println!(stringable.to_string().to_uppercase()) }
tags: Flutter,GUI,macOS souce: https://github.com/flutter/flutter/issues/73122 To solve this problem we should specify MACOSX_DEPLOYMENT_TARGET: I would imagine that there is Apple documentation on managing build settings in Xcode, but I don’t have a link offhand. There’s no Flutter-specific documentation of the process, if that’s what you mean; it isn’t any different in a Flutter macOS application as it would be any other macOS application. If you don’t want to use Xcode, you can change MACOSX_DEPLOYMENT_TARGET directly in Runner.xcodeproj/project.pbxproj. ...
macOS Press Command + Shift + Control + D to enter debug mod. Then you can open url in brower: Help -> Debug -> 「浏览器 webview 相关-系统浏览器打开网页」
tags: GUI
tags: Rust,Flutter,iOS source: “Using Dummy Headers - Flutter_rust_bridge.” Accessed July 25, 2022. http://cjycode.com/flutter_rust_bridge/integrate/ios_headers.html. Recently, I met a problem that the iOS app didn’t work properly in release mode. After a little searching, I found it’s a Flutter app and invoked a Rust function by FFI. The inital call were not invoked during app startup, and it should be. I finally resolved the problem by following: https://github.com/fzyzcjy/flutter_rust_bridge/issues/496 http://cjycode.com/flutter_rust_bridge/integrate/ios_headers.html In short: Xcode will strip the unused symbols in release mode, and won’t realize the FFI invocation; So we need add some dummy invocations to the AppDelegate.swift to make sure it have been used. Next, add this line to ios/Runner/Runner-Bridging-Header.h: ...
tags: Tools
tags: openssl This problem is caused about the ca certs are different between client and server.
tags: Move,Starcoin Web3 StarTrek Bedrock – Object-capability model In my words, Move is kind of a Resource-Oriented Programming language. The resource is represented by struct in Move, aka object in other programming language. By the way, the resource in Move is the struct which cannot be copied and cannot be dropped1. Distinct from other programming language, objects are stored in memory, resource in Move can store to the chain’s global storage. ...
tags: How to Write,Online Tools source: https://brevity500.com/
tags: Assembly source: https://github.com/hackclub/some-assembly-required What do we mean by an abstraction? Well, an abstraction is a layer above something else that makes that thing easier to do.
tags: Starcoin Web3 StarTrek,Move When I start learning Move and looking at the stdlib starcoin-framework and starcoin-framework-commons. Then I realized there are must some magic during the block execution in runtime. To roll the world, the runtime should provide some built in types and call some function in the stdlib. How does StarcoinVM Validate Transactions? As a miner, it’s responsible for executing block, it follows: Received some transactions from P2P network: EventHandler of PeerTransactionsMessage. ...
tags: Starcoin Web3 StarTrek Start node with console: $ ./target/debug/starcoin -d ~/.starcoin -n dev console In console type: starcoin% dev log level debug Note: starcoin% is the prompt. Then we can see debug log in ~/.starcoin/dev/starcoin.log.
tags: Move,Starcoin Web3 StarTrek source: Blackshear, Sam, Evan Cheng, David L Dill, Victor Gao, Ben Maurer, Todd Nowacki, Alistair Pott, et al. “Move: A Language With Programmable Resources,” n.d., 26.
tags: Starcoin Web3 StarTrek,Blockchain,Smart contracts
tags: Starcoin Web3 StarTrek,Account-Model Blockchain Systems We can create an account by wallet like MetaMask or StarMask, but I’m curious about how an account is created on the blockchain system. As a wallet has been embedded in the starcoin node, we can use it to create an account as follow: $ ./target/debug/starcoin -d ~/.starcoin -n dev account create -p my-pass { "ok": { "address": "0x2f1aeb63bd30d8eb841d6a941c5d6df3", "is_default": false, "is_readonly": false, "public_key": "0x91f79bdd9ced49332bf85b751d02339e05aff047c386d0c14b380d8519d2fb4b", "receipt_identifier": "stc1p9udwkcaaxrvwhpqad22pchtd7vy2276p" } } As above we can see our account has been created, and the address is: 0x2f1aeb63bd30d8eb841d6a941c5d6df3. We’ll find some files are created, if we check our local directory at ~/.starcoin/dev: ...
tags: Career,How To Get Rich (without getting lucky) source: Frontera. “Luck Surface Area: How to Get Lucky In Life,” May 31, 2022. https://fronterablog.com/luck-surface-area/. 5 ways to expand your luck surface area: Do & Tell, don’t miss the “telling” part. Follow your curiosity Talk to new peopli Build a personal brand Take luck as a skill
tags: libp2p,Starcoin Web3 StarTrek source: https://docs.rs/libp2p/0.45.1/libp2p/tutorials/index.html Ping: Four necessary traits Identity: PeerId and corresponding Keypair Transport: send and receive bytes on the network. NetworkBehaviour: decode or encode the bytes from the Transport. Swarm: drives both a Transport and a NetworkBehaviour forward. use futures::StreamExt; use libp2p::ping::{Ping, PingConfig}; use libp2p::{identity, Multiaddr, PeerId, Swarm}; use std::error::Error; #[async_std::main] async fn main() -> Result<(), Box<dyn Error>> { // First we need to create a network identity. let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); println!("Local peer id: {:?}", local_peer_id); // Then construct a transport: defines how to send bytes on the network. let transport = libp2p::development_transport(local_key).await?; // NetworkBehaviour defines what bytes to send on the network. let behaviour = Ping::new(PingConfig::new().with_keep_alive(true)); // Swarm connects transport and behaviour together: // // 1. Passing commands from NetworkBehaviour to the Transport. // 2. As well ass events from the Transport to the NetworkBehaviour. let mut swarm = Swarm::new(transport, behaviour, local_peer_id); swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?; if let Some(addr) = std::env::args().nth(1) { let remote: Multiaddr = addr.parse()?; swarm.dial(remote)?; println!("Dialed {}", addr); } loop { match swarm.select_next_some().await { libp2p::swarm::SwarmEvent::NewListenAddr { listener_id: _, address, } => println!("Listening on {:?}", address), libp2p::swarm::SwarmEvent::Behaviour(event) => println!("{:?}", event), _ => {} } } Ok(()) }
tags: P2P,libp2p,Starcoin Web3 StarTrek
tags: P2P,Starcoin Web3 StarTrek,Network source: https://docs.libp2p.io/ A set of protocols for peer identity, discover, routing, transport and more. Peer-to-peer network Peers or nodes communicate with oen another directly, it’s different from the client-server architecture. libp2p Solved Transport abstract data transmission and receipt to adapte many protocols, include the future protocols. Identity use public key cryptography as the basis of peer identity, with this: It gives each peer a globally unique “name”, in the form of a PeerId. PeerId allows anyone to retreve the public key for the identified peer, which enables secure communication between peers. Security libp2p supports “upgrading” a connection provided by a transport into a securely encrypted channel. Currently support; ...
tags: Starcoin Web3 StarTrek,Blockchain