Skip to content

Instantly share code, notes, and snippets.

View Vectorized's full-sized avatar
🎡

Vectorized Vectorized

🎡
View GitHub Profile
@Vectorized
Vectorized / attribute_list.py
Last active September 29, 2015 16:34
Python add/set attributes to list (or any built-in classes)
class L(list):
"""
A subclass of list that can accept additional attributes.
Should be able to be used just like a regular list.
The problem:
a = [1, 2, 4, 8]
a.x = "Hey!" # AttributeError: 'list' object has no attribute 'x'
The solution:
@Vectorized
Vectorized / ERC721A.sol
Last active September 27, 2024 08:56
ERC721A Burnable (with configurable start index)
// SPDX-License-Identifier: MIT
// Creator: Chiru Labs
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol';
import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol';
import '@openzeppelin/contracts/utils/Address.sol';
@Vectorized
Vectorized / ERC721A.sol
Last active February 7, 2022 08:35
ERC721A (adjustable start index)
// SPDX-License-Identifier: MIT
// Creator: Chiru Labs
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol';
import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol';
import '@openzeppelin/contracts/utils/Address.sol';
@Vectorized
Vectorized / ERC721A.sol
Created February 23, 2022 15:07
ERC721A Re-entrant safe
// SPDX-License-Identifier: MIT
// Creator: Chiru Labs
pragma solidity ^0.8.4;
import '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol';
import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol';
import '@openzeppelin/contracts/utils/Address.sol';
@Vectorized
Vectorized / ToStringExamples.sol
Last active May 18, 2022 06:16
Solidity uint256 to string (base10)
// SPDX-License-Identifier: MIT
// Author: vectorized.eth
pragma solidity ^0.8.0;
pragma abicoder v2;
contract ToStringExamples {
constructor() {}
function toStringOriginal(uint256 value) public pure returns (string memory) {
@Vectorized
Vectorized / YulSnippets.sol
Last active April 29, 2023 21:55
Solidity Yul Assembly Snippets
// SPDX-License-Identifier: MIT
// Author: vectorized.eth
pragma solidity ^0.8.0;
pragma abicoder v2;
// DISCLAIMER:
// This is experimental software and is provided on an "as is" and "as available" basis.
// We do not give any warranties and will not be liable for any loss incurred through any use of this codebase.
library Base64 {
@Vectorized
Vectorized / Summary.md
Last active July 12, 2022 10:04
Vyper vs Solidity Gas Benchmarks

Vyper vs Solidity Gas Benchmarks

Summary

EDCSA.recover(bytes32 hash, bytes calldata signature)

Solidity: 26869
Vyper: 27729

Note that the Solidity version has the added functionality:

@Vectorized
Vectorized / LibString.sol
Last active June 16, 2023 08:51
Solidity String Replace
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
library LibString {
function replace(
string memory subject,
string memory search,
string memory replacement
) internal pure returns (string memory result) {
assembly {
@Vectorized
Vectorized / MappingTester.sol
Created June 22, 2022 17:09
Mapping Gas Tests
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;
import "@openzeppelin/contracts/utils/structs/BitMaps.sol";
contract MappingTester {
using BitMaps for BitMaps.BitMap;
mapping(uint256 => bool) public map;
mapping(address => bool) public addrMap;