Skip to content

Instantly share code, notes, and snippets.

@chatch
chatch / melt-all.sh
Last active March 27, 2024 07:27
Melt monthly CSVs
#!bin/sh
for file in `ls readings/*Heat*.csv`; do python melt-monthly-csv.py $file readings-melted/`basename $file`; done
for file in `ls readings/*Power*.csv`; do python melt-monthly-csv.py $file readings-melted/`basename $file`; done
for file in `ls readings/*PV*.csv`; do python melt-monthly-csv.py $file readings-melted/`basename $file`; done
@chatch
chatch / EmitLargeEvent.sol
Created November 4, 2020 04:24
Measure gas from emitting large or a lot of events
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.7.0;
import "hardhat/console.sol";
contract EmitLargeEvent {
event CustomHistorySimple (
bytes32 indexed id,
@chatch
chatch / mocha-nested-hooks.js
Created October 26, 2020 12:19
Demonstrate the order of before/beforeEach with nested tests
describe("An afterEach hook", function () {
afterEach(function () {
console.log("afterEach run!");
});
before(function () {
console.log("before TOP");
});
beforeEach(function () {
@chatch
chatch / evm-cost-store-string.js
Created September 28, 2020 04:06
Calculate EVM gas cost of storing a given string
const STORE_WORD_COST = 20000
const WORD_BYTES = 32
const ONE_ETH = 1000000000000000000
const ONE_GWEI = 1000000000
// Calculate EVM gas cost for storing the given string
const storeStringGasCost = str => Math.ceil(Buffer.from(str).length / WORD_BYTES) * STORE_WORD_COST
// Calculate ETH cost for storing the given string at given GWEI gas price
const storeStringEthCost = (str, gasPriceGwei) => storeStringGasCost(str) * gasPriceGwei * ONE_GWEI / ONE_ETH
@chatch
chatch / HatchNFT.sol
Created September 14, 2020 09:19
Basic ERC721 (non enumerable - demonstrates ownership still shows on Etherscan, Metamask after custom token added)
pragma solidity 0.6.2;
// import "https://github.com/0xcert/ethereum-erc721/src/contracts/tokens/nf-token-enumerable.sol";
import "https://github.com/0xcert/ethereum-erc721/src/contracts/tokens/nf-token-metadata.sol";
import "https://github.com/0xcert/ethereum-erc721/src/contracts/ownership/ownable.sol";
/**
* @dev This is an example contract implementation of NFToken with metadata extension.
*/
contract HatchNFT is
@chatch
chatch / CreateSalted.sol
Created September 4, 2020 03:58
From solidity readthedocs - example of Create2 and computing the predicted address
// SPDX-License-Identifier: GPL-3.0
pragma solidity >0.6.11 <0.8.0;
contract D {
uint public x;
constructor(uint a) {
x = a;
}
}
@chatch
chatch / LinkToken.sol
Created October 21, 2019 16:21
LinkToken.sol upgraded to Solidity 0.5.0
// File: link_token/contracts/token/linkERC20Basic.sol
pragma solidity >= 0.5.8;
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
@chatch
chatch / USDCKovan.sol
Created October 10, 2019 14:23
USDC token contract for testing on Kovan - paste it into remix
pragma solidity ^0.5.0;
import "github.com/OpenZeppelin/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import "github.com/OpenZeppelin/openzeppelin-contracts/contracts/token/ERC20/ERC20Detailed.sol";
import "github.com/OpenZeppelin/openzeppelin-contracts/contracts/token/ERC20/ERC20Mintable.sol";
contract USDCKovan is ERC20, ERC20Detailed, ERC20Mintable {
string NAME = "USDCKovan";
@chatch
chatch / stellar-xdr-object.txt
Last active January 3, 2019 23:26
stellar-base xdr export - dump all the types
{
"Value": {
"_maxLength": 4294967295
},
"Uint32": {
"MAX_VALUE": 4294967295,
"MIN_VALUE": 0
},
"Hash": {
"_length": 32,
@chatch
chatch / ledger-000e007f.json
Created January 1, 2019 03:19
stellar-archivist dumpxdr ledger json
{
"Hash": [
67,
117,
103,
112,
93,
120,
39,
118,