Skip to content

Instantly share code, notes, and snippets.

@daltyboy11
daltyboy11 / Incrementer.sol
Last active June 2, 2023 15:29
Toy contract with an internal and external library
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
library IncrementerLibExternal {
function increment(uint256 x) external pure returns (uint256) {
return x + 1;
}
}
@daltyboy11
daltyboy11 / BaseTest.sol
Created December 2, 2022 20:58
Nested Pranking for Foundry Tests
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.12;
pragma experimental ABIEncoderV2;
import "forge-std/Test.sol";
/**
* Base testing contract with nested pranking capabilities.
* @author Dalton Sweeney
@daltyboy11
daltyboy11 / multiple-library-usage-in-solidity.md
Created April 11, 2022 17:20
Multiple library usage in Soliditiy

Something I didn't realize when I first learned about libraries in Solidity is you can apply multiple libraries to the same type. Here's what I mean:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

library SafeMath1 {
    function add(uint x, uint y) internal pure returns (uint) {
        uint z = x + y;
@daltyboy11
daltyboy11 / TryCatch.sol
Created April 11, 2022 16:49
Solidity try/catch demonstration
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
/*
You can only apply a try/catch block to a function called externally. An external
function call is a message call, whereas an internal function call is just a jump.
This snippet shows the same function, f1(), called internally and externally. The
internal call code does not compile.
*/
contract Foo {
@daltyboy11
daltyboy11 / 99-problems.scala
Last active January 7, 2020 19:47
My solutions to 99 scala problems (http://aperiodic.net/phil/scala/s-99/) adapted from Werner Hatt's 99 Prolog Problems
import scala.annotation
import scala.util.Random
// Working with lists
// 1
def findLast[T](l: List[T]): T = l match {
case t :: Nil => t
case t :: tail => findLast(tail)
case Nil => throw new IllegalArgumentException