Skip to content

Instantly share code, notes, and snippets.

@stonegao
stonegao / generate_blocks.sh
Created February 12, 2023 04:34 — forked from System-Glitch/generate_blocks.sh
Tutorial for bitcoin regtest
# Script to generate a new block every minute
# Put this script at the root of your unpacked folder
#!/bin/bash
echo "Generating a block every minute. Press [CTRL+C] to stop.."
address=`./bin/bitcoin-cli getnewaddress`
while :
do

The correct way, install homebrew on apple m1.

# We'll be installing Homebrew in the /opt directory.
cd /opt

# Create a directory for Homebrew. This requires root permissions.
sudo mkdir homebrew

# Make us the owner of the directory so that we no longer require root permissions.
sudo chown -R $(whoami) /opt/homebrew
@stonegao
stonegao / prng.js
Created December 27, 2022 08:09 — forked from blixt/prng.js
A very simple, seedable JavaScript PRNG. NOTE: Please read comments on why this is not a good choice.
// NOTICE 2020-04-18
// Please see the comments below about why this is not a great PRNG.
// Read summary by @bryc here:
// https://github.com/bryc/code/blob/master/jshash/PRNGs.md
// Have a look at js-arbit which uses Alea:
// https://github.com/blixt/js-arbit
/**
@stonegao
stonegao / how-to-start-colima-automatically-on-macos.md
Created December 19, 2022 11:33 — forked from fardjad/how-to-start-colima-automatically-on-macos.md
[How to start Colima automatically on macOS] Instructions for starting Colima automatically on macOS similar to Docker Desktop #macos #colima #docker

Steps

  1. Allow colima start to run without password:
cat <<-EOF | sudo tee /private/etc/sudoers.d/colima
%admin ALL=NOPASSWD: /bin/rm -rf /var/run/docker.sock
%admin ALL=NOPASSWD: /bin/ln -s $HOME/.colima/docker.sock /var/run/docker.sock
EOF
@stonegao
stonegao / osx_uninstall_mysql_install_mariadb_homebrew.md
Created September 3, 2022 12:39 — forked from brandonsimpson/osx_uninstall_mysql_install_mariadb_homebrew.md
OSX How To: Uninstall native MySQL and install MariaDB via Homebrew

OSX How To: Uninstall native MySQL and install MariaDB via Homebrew

This is a short overview on how to completely remove any old mysql server installs in OSX and upgrade to MariaDB without conflicts. Things can get a bit weird when you have various old installs of MySQL server floating around, and utilizing homebrew to install and upgrade MariaDB as a drop in replacement for MySQL has worked well, especially if you're used to managing MySQL installs via yum in linux.

First: Backup Your Data!

Backup all of your current databases with mysqldump

This isn't a tutorial on backups, and there are many ways to do it. You should know how to backup your data anyway. For this example, we'll do a full backup of our InnoDB databases.

@stonegao
stonegao / eventFilterWithPagination.js
Created August 29, 2022 11:10 — forked from wschwab/eventFilterWithPagination.js
an attempt at implementing some kind of pagination to an Ethereum event filter
const eventFilterv5WithPagination = (contractAddress, erc20abi, _provider, numberOfResponses) => {
// creating the interface of the ABI
const iface = new ethers.utils.Interface(erc20abi.abi);
// intialize array for the logs
let logs = [];
// get latest block number
const latest = await provider.getBlockNumber();
// intialize a counter for which block we're scraping starting at the most recent block
let blockNumberIndex = latest;
// SPDX-License-Identifier: CC0
pragma solidity ^0.8.0;
// author @koeppelmann
// Detector Factory allows to deploy new CensorshipDetector
// Each CensorshipDetector monitors wether a specific address is being cencored on Ethereum
// Each CensorshipDetector must be funded with ETH (anyone can send ETH to the CensorshipDetector)
// Once funded anyone can call the "withdrawal" in the "CensorshipDetector" every 1h and it will pay a small bounty to tx.origin (100k * basefee)
// During this transaction the "CensorshipDetector" will send 1 wei to the address that is endangered of being cencored.
// CensorshipDetector will log the coinbase (validator address) (those are NOT censoring) and the number of blocks that has passed.
@stonegao
stonegao / dydxFlashLoanTemplate.sol
Created May 25, 2022 03:17 — forked from cryptoscopia/dydxFlashLoanTemplate.sol
A single-file simplest possible template for a contract that obtains a flash loan from dydx, does things, and pays it back.
// SPDX-License-Identifier: AGPL-3.0-or-later
// The ABI encoder is necessary, but older Solidity versions should work
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
// These definitions are taken from across multiple dydx contracts, and are
// limited to just the bare minimum necessary to make flash loans work.
library Types {
enum AssetDenomination { Wei, Par }
import { BigNumber, providers, Wallet, Contract } from "ethers";
import { FlashbotsBundleProvider, FlashbotsBundleResolution, FlashbotsBundleTransaction, SimulationResponseSuccess } from "@flashbots/ethers-provider-bundle";
import { Provider } from "@ethersproject/abstract-provider";
import { Console } from "console";
import { send } from "process";
import * as fs from "fs"
import { connect } from "http2";
const MWEI = 10n ** 6n
const GWEI = 10n ** 9n
@stonegao
stonegao / DydxFlashloanBase.sol
Created April 30, 2022 22:58 — forked from gh639/DydxFlashloanBase.sol
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.12+commit.27d51765.js&optimize=false&runs=200&gist=
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import { IERC20 } from "./Interfaces.sol";
import { SafeMath,SafeERC20 } from "./Libraries.sol";
import "./ISoloMargin.sol";
contract DydxFlashloanBase {
using SafeMath for uint256;