Skip to content

Instantly share code, notes, and snippets.

Avatar
🍃
Waiting for autumn

Wang Dàpéng wong2

🍃
Waiting for autumn
View GitHub Profile
View simulation.ts
import { Chain, Common } from "@nomicfoundation/ethereumjs-common";
import { TransactionFactory } from "@nomicfoundation/ethereumjs-tx";
import { VM } from "@nomicfoundation/ethereumjs-vm";
import { ForkBlockchain } from "hardhat/internal/hardhat-network/provider/fork/ForkBlockchain";
import { ForkStateManager } from "hardhat/internal/hardhat-network/provider/fork/ForkStateManager";
import { makeForkClient } from "hardhat/internal/hardhat-network/provider/utils/makeForkClient";
const JSON_RPC_URL = "https://rpc.ankr.com/eth";
async function simulateTx(signedTx: string) {
@wong2
wong2 / SocialRecoveryAccount.sol
Last active August 26, 2022 04:00
Minimum social recovery wallet implementation on zkSync https://vitalik.ca/general/2021/01/11/recovery.html
View SocialRecoveryAccount.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@matterlabs/zksync-contracts/l2/system-contracts/interfaces/IAccountAbstraction.sol";
import "@matterlabs/zksync-contracts/l2/system-contracts/TransactionHelper.sol";
import "@matterlabs/zksync-contracts/l2/system-contracts/Constants.sol";
import "@openzeppelin/contracts/interfaces/IERC1271.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
View opensea.js
import HDWalletProvider from "@truffle/hdwallet-provider";
import { OpenSeaPort, Network } from "opensea-js";
import { PRIVATE_KEY } from "./consts.mjs";
const provider = new HDWalletProvider({
privateKeys: [PRIVATE_KEY],
providerOrUrl: "https://rpc.ankr.com/eth",
});
provider.engine.on("error", (err) => {
View output.json
{
"contracts": {
"@openzeppelin/contracts/access/Ownable.sol": {
"Ownable": {
"storageLayout": {
"storage": [
{
"astId": 7,
"contract": "@openzeppelin/contracts/access/Ownable.sol:Ownable",
"label": "_owner",
View build-metamask-snaps.md

How to build MetaMask extension with Snaps enabled

  1. Clone the source code from https://github.com/MetaMask/metamask-extension
  2. Switch to snaps branch
  3. yarn setup
  4. Copy the .metamaskrc.dist file to .metamaskrc and replace the INFURA_PROJECT_ID value with your own.
  5. yarn run build prod --build-type flask
  6. The build should be located at directory dist.
View hn-points.js
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
function jsonResponse(o) {
return new Response(JSON.stringify(o), {
headers: {
"content-type": "application/json;charset=UTF-8",
'Access-Control-Allow-Origin': '*',
}
View xx.txt
[0:0.000,0:25.520] 突击检查环节,你在小宇宙是什么,担当小宇宙声音最好听的是谁小宇宙最近一次团建干了什么吃饭吧,好久没有看见了下周团建一直吃饭吃了什么,本帮菜应该是又是本帮菜。
[0:25.520,0:50.240] 不是就就上次吃了一次霸王餐,那你们确实很久没有团建了,赶紧去听我上次播客我又给你们推荐团建餐厅,你们有去唱歌吗,你刚刚应该说你们有去唱歌麦霸是谁鸡丝勉强可以算吧,基斯喜欢唱什么歌。
[0:50.760,0:52.960] 呃,祭司可能。
[0:52.980,1:21.020] 能唱的歌这歌录非常广,但是他上一次去KTV的时候,他唱的是说唱没有唱500吗,他挣500很厉害,是500可能就属于他的优势项目,他可能觉得唱的太多了,没意思,他上次也唱了,但是她呃,上次主要挑战的是杨和苏的那个一首歌啊,那他下次可以再这个录音系在多唱唱可以啊,他的声音非常适合唱500这种。
[1:21.020,1:52.240] Feel的歌非非常非常的合适,那唱说唱说唱,嗯,你自己找机会去听吧,好吧,呵呵hello,我是羊,你刚才听到的是一段来自几个办公室的对话,我和我的同事小宇宙的产品经理大核桃在一个普通的工作日,晚上我们聊聊播客,当然也聊了聊小宇宙,这里其实就是说到就是很多人想做博客,但是不知道从什么开始。
[1:52.580,2:6.420] 呃,怎么说呢,就是说大家传统上的一个定位就觉得好节目,可能是呃,日坛大内那样的OK,没错,我觉得这没错,但是你要想开始这一步的话,你就是可以从你最擅长呃。
[2:6.660,2:28.780] 最有把握的事情开始,比如说你就是可能先聊一聊你身边的小事聊聊你现在的想法,那么你通过这样的一个过程,你就可以知道啊,你其实你其实更想讲的东西是什么,你其实更擅长的东西是什么,然后你就能找到说你真正的想做一个更好的节目的时候你要去做什么,这个其实就是我们当时做的零七的一个初衷。
[2:28.780,2:46.140] 你不用说为第零七一开始就为第零七设定一个非常宏大的目标,说我要做一个日坛公园,我举例啊,我要做一个日坛公园,然后用非常高规格的方式来对待他,你要写逐字稿,你要呃拉人来聊,然后搞得自己压力很大。
[2:46.240,3:4.700] 然后把它露出来,其实不是的,我们是希望说你反而可以用一种非常低成本的方式先去尝试那么呃,你可以在这里面你可以你可
@wong2
wong2 / node-canvas-fill-text-max-width.js
Created August 21, 2019 06:12
node canvas auto wrap text by max width
View node-canvas-fill-text-max-width.js
function fillText(ctx, text, x, y, maxWidth, spacing = 0){
const lines = text.split('\n')
let lineHeight = 0
for (const line of lines) {
if (!line) {
y += lineHeight
continue
}
let s = ''
for (const char of line) {
View batch.js
async function runBatch(client, command, keys, ...args) {
let batch = client.batch()
for (let key of keys) {
batch[command](key, ...args)
}
return batch.execAsync()
}
View show_git_tree.py
import re
import zlib
def show_git_tree(sha1):
path = '.git/objects/%s/%s' % (sha1[:2], sha1[2:])
with open(path) as fp:
content = zlib.decompress(fp.read())
header, body = content.split('\0', 1)
for line in re.findall('(\d+) (.*?)\0(.{20})', body, re.MULTILINE):
print line[0], line[1], line[2].encode('hex')