This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// merge the two arrays: left and right | |
function merge(left, right) { | |
let resultArray = [], | |
leftIndex = 0, | |
rightIndex = 0; | |
// concatenate values into the resultArray in order | |
while (leftIndex < left.length && rightIndex < right.length) { | |
if (left[leftIndex] < right[rightIndex]) { | |
resultArray.push(left[leftIndex]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NextRequest, NextResponse } from "next/server"; | |
import { Redis } from "@upstash/redis"; | |
export const config = { | |
runtime: "edge", | |
}; | |
if ( | |
!process.env.UPSTASH_REDIS_REST_URL || | |
!process.env.UPSTASH_REDIS_REST_TOKEN | |
) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier:OPEN | |
pragma solidity ^0.8.18; | |
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | |
import "@openzeppelin/contracts/utils/math/Math.sol"; | |
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | |
import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol"; | |
library SafeMath { | |
function add(uint256 x, uint256 y) internal pure returns (uint256 z) { |
Using newer compiler versions and the optimizer gives gas optimizations and additional safety checks for free!
The advantages of versions 0.8.*
over <0.8.0
are:
- Safemath by default from
0.8.0
(can be more gas efficient than some library based safemath). - Low level inliner from
0.8.2
, leads to cheaper runtime gas. Especially relevant when the contract has small functions. For
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fizzbuzz | |
import "strconv" | |
func Fizzbuzz(n int) string { | |
var name string = "" | |
if n%3 == 0 { | |
name = "Fizz" |