Skip to content

Instantly share code, notes, and snippets.

@ewrvp7lv7
ewrvp7lv7 / brure_hash.rs
Created June 28, 2023 14:00
Finding appropriate hashes
use std::io::{stdout, Write};
use sha3::{Keccak256, Digest};
fn main() {
let mut stdout = stdout();
let samples: [u32; 4] = [0xbeced095, 0x42a7b7dd, 0x45e010b9, 0xa86c339e];
//let samples: [u32; 4] = [0x6ca54da2, 0xfe07a987, 0x45e010b9, 0x036b6384];
let mut res: [u64; 4] = [0, 0, 0, 0];
@ewrvp7lv7
ewrvp7lv7 / ContractFabric.sol
Last active March 5, 2023 07:36
Create2 creates Create SCs
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SC0 {
address public creare2owner;
uint256 public smth;
constructor(address _addr) {
creare2owner = _addr;
}
@ewrvp7lv7
ewrvp7lv7 / min.md
Last active February 13, 2022 10:58
Ethereum gas optimization task

Etherium gas optimization task by the min function.

pragma solidity ^0.8.0;
contract MinContract {
    function min(uint256 a, uint256 b) public pure returns (uint256) {
        return a < b ? a : b;
    }
}
@ewrvp7lv7
ewrvp7lv7 / challenge.md
Created November 21, 2021 09:52
Inspecting hash of nested struct

Challenge and my solution

At the first stage,

hash benchmark was checked. As expected, shortest 16-bit md5 was faster.

Please, pay attention here: BenchmarkHash_md5-4 2345684 512.6 ns/op1

6356d331afbb33be325cabba0e49a332
BenchmarkHash_md5-4 2345684 512.6 ns/op

Footnotes

  1. Nanoseconds per one operation

@ewrvp7lv7
ewrvp7lv7 / random.md
Last active November 20, 2021 15:54
Dont use rand.Intn(int)!

Don't use Pseudorandom number generator rand.Intn(int)!

Each time you set the same seed, you get the same sequence. stackoverflow

package main

import (
	"encoding/gob"
	"fmt"
@ewrvp7lv7
ewrvp7lv7 / main.go
Last active November 14, 2021 15:06
All combinations of uniq symbols
package module
import (
"fmt"
"strings"
)
func main() {
str := "fgfwfhh"
@ewrvp7lv7
ewrvp7lv7 / main.go
Last active November 13, 2021 17:59
Slice external and internal
package main
import "fmt"
//Pass slice through the function
//function have own slise wich have common part with external slice
//but! if inner slice change own size, external slise isn't changed
func main() {
arr := make([]byte, 16)
fmt.Println("hello01", len(arr), arr) //hello01 16 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
cutArrSize(arr)