Skip to content

Instantly share code, notes, and snippets.

@alexisljn
alexisljn / log-event-values-during-test.ts
Created December 21, 2022 08:22
Log events values during hardhat test
import {ContractTransaction, ContractReceipt} from "ethers";
let tx: ContractTransaction = await contract.calledFunc();
let receipt: ContractReceipt = await tx.wait();
const events = receipt.events!.filter((x) => {return x.event == "EventName"});
console.log(events[0].args);
@alexisljn
alexisljn / reentrency-attack.sol
Created August 2, 2022 10:08
Reentrency in Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
/*
EtherStore is a contract where you can deposit and withdraw ETH.
This contract is vulnerable to re-entrancy attack.
Let's see why.
1. Deploy EtherStore
2. Deposit 1 Ether each from Account 1 (Alice) and Account 2 (Bob) into EtherStore
@alexisljn
alexisljn / hex-to-uint-uint-to-hex-string.sol
Created June 22, 2022 08:54
This gist shows how to convert bytes input into an uint output. Then we can retrieve the bytes input by converting the uint value into an hexadecimal string
//SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
import "@openzeppelin/contracts/utils/Strings.sol";
contract Test {
uint256 public value;
@alexisljn
alexisljn / d-app-docker-compose.yml
Created June 13, 2022 14:04
Starter docker compose for Ethereum Dapp
version: "3.8"
services:
hardhat:
image: node:16
container_name: hardhat
working_dir: /home/node/app
volumes:
- ./:/home/node/app
ports:
- PHP
- Symfony var-dumper : le var-dumper de Symfony, utile pour debug
- https://github.com/symfony/var-dumper
- https://packagist.org/packages/symfony/var-dumper
- Javascript
- Turbolinks : Accélère le chargement des pages en chargeant les pages en ajax
- https://github.com/turbolinks/turbolinks
- Vidéo Grafikart : https://www.youtube.com/watch?v=CjZnG_X85ww
- Tui Editor : Editeur WYSIWYG Markdown
@alexisljn
alexisljn / ebauche-permission.php
Created August 30, 2021 12:46
Ebauche permissions
<?php
// Il faut ET la permission 1 (OU la permission 2 ET la permission 4)
// ET la permission 3
$permissions = [
'and' => [
'permission' => [
'name' => $permission1,
'or' => [
@alexisljn
alexisljn / binary-mask.php
Last active December 21, 2022 08:28
Use of binary mask to create basis of a permissions system
<?php
$permA = 1;
$permB = 2;
$permC = 4;
$permD = 8;
$permE = 16;
$permF = 32;
// Malgré le '|' c'est un set de permissions
package {
'apache2':
ensure => present,
#name => 'apache2',
#provider => apt
}
package {
'php7.3':
ensure => present
@alexisljn
alexisljn / timeleft.js
Last active March 27, 2021 14:21
timeleft from SetTimeout in NodeJS
const timeout = setTimeout(() => {
console.log("executé après 5 sec")
},5000)
setTimeout(() => {
console.log(Math.ceil((timeout._idleStart + timeout._idleTimeout)/1000 - process.uptime()));
}, 3000)
@alexisljn
alexisljn / gitkeep-all-empty-folders
Created March 2, 2020 08:16
Create .gitkeep file in empty folders
find . -type d -empty -not -path "./.git/*" -exec touch {}/.gitkeep \;