Skip to content

Instantly share code, notes, and snippets.

View pldespaigne's full-sized avatar
👾

pldespaigne pldespaigne

👾
View GitHub Profile
@pldespaigne
pldespaigne / eth-tx-hash.ts
Last active March 30, 2024 22:05
Ethereum Tx Hash
import { encode } from '@ethereumjs/rlp';
import { ecrecover } from '@ethereumjs/util';
import { keccak256 } from 'ethereum-cryptography/keccak';
// tx: 0xb00b758da7b97dbeedd1ef62592b2c1427c70ca042dc51a63f3a39d8d31ebbcc
const chainId = 0x1n;
const nonce = 0x3n;
const maxPriorityFeePerGas = 0xf4240n;
const maxFeePerGas = 0x73323c225n;
const gasLimit = 0xdd9cn;
@pldespaigne
pldespaigne / atkin.js
Last active August 30, 2019 11:05
Js implementation of the Sieve of Atkin to find the n first prime number (https://en.wikipedia.org/wiki/Sieve_of_Atkin)
function atkin(MAX) {
const SQRT_MAX = Math.floor(Math.sqrt(MAX) + 1);
const array = new Array(MAX).fill(false);
for (let x = 1; x < SQRT_MAX; x++) {
for (let y = 1; y < SQRT_MAX; y++) {
let k = 4 * x * x + y * y;
if ((k < MAX) && ((k % 12 === 1) || (k % 12 === 5))) {
array[k] = !array[k];
}
@pldespaigne
pldespaigne / Factory.sol
Created May 21, 2019 14:56
Ethereum CREATE2 Factory contract
// create2 playground by @pldespaigne
// based on contract written by @miguelmota & @ricmoo
pragma solidity >0.4.99 <0.6.0;
contract Factory {
event Deployed(address addr, uint256 salt);
function deploy(bytes memory code, uint256 salt) public returns(address) {
address addr;