Skip to content

Instantly share code, notes, and snippets.

View hack3r-0m's full-sized avatar
🎯
Focusing

hack3r-0m

🎯
Focusing
View GitHub Profile
@romaninsh
romaninsh / lambda-vpc-internet-access-cloudformation.yml
Last active December 22, 2021 00:26
CloudFormation template implementing Private network which can be used by Serverless to deploy Lambda into VPCs an maintaining internet access
# Add the following to your existing VPC CF stack
# create 2 subnets, lambdas like to be in multiple subnets
Private1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs ]
CidrBlock: !Ref Private1CIDR
@Strernd
Strernd / parseErc20Transfer.js
Created June 7, 2021 11:09
Parses an ERC20 Transfer from the Ethereum API.
const converter = require("hex2dec");
const Eth = require("ethjs");
const eth = new Eth(new Eth.HttpProvider(process.env.INFURA));
async function getERC20TransferByHash(hash) {
const ethTxData = await eth.getTransactionByHash(hash);
if (ethTxData === null) throw "TX NOT FOUND";
if (
ethTxData.input.length !== 138 ||
ethTxData.input.slice(2, 10) !== "a9059cbb"
@whoisryosuke
whoisryosuke / api-form-submit.js
Created October 3, 2018 17:14
React - Handling forms and submitting POST data to API -- @see: https://reactjs.org/docs/forms.html
class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = { name: '' };
}
handleChange = (event) => {
this.setState({[event.target.name]: event.target.value});
}
@mathben
mathben / archlinux_installation_ux370u_full_disk_encrypted.sh
Last active January 1, 2022 18:38
BASH - Installation Arch Linux on Asus ZenBook UX370U - Full disk single boot
#!/usr/bin/env bash
# French Guide : https://github.com/FredBezies/arch-tuto-installation
# Install ARCH Linux with UEFI
# The official installation guide (https://wiki.archlinux.org/index.php/Installation_Guide) contains a more verbose description.
# Download the archiso image from https://www.archlinux.org/
# Copy to a usb-drive
dd if=archlinux.img of=/dev/sdX bs=16M status=progress && sync # on linux
@tbusser
tbusser / tabs-vs-spaces.md
Created November 11, 2014 10:17
Tabs vs spaces

It is my opinion that tabs are better than spaces, especially when working in a team. Why you aks? When using tabs everyone has the ability to indent the code according to their own preference. If your teams decides on using spaces you also need to agree on how many spaces to use for an indent. Do you pick 2 spaces, 4 spaces or something else? Odds are, someone is not going to be happy with the team's decision.

Using tabs gives everyone the freedom to indent the code to their own liking. Most editors have an option to specify how many columns a tab should indent. This allows each team member to pick the setting they're most comfortable with.

To prevent (Git) diff nightmares just follow these simple steps:

  • Always follow the convention used in the project you're working on. If it is a legacy code base and uses 5 spaces for indenting code, use 5 spaces in the code you add or modify;
  • Have your editor (or Git pre-commit hook) strip all trailing whitespace from your files. Trailing whitespace serves no purpo
pragma solidity ^0.6.0;
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/ChainlinkClient.sol";
// MyContract inherits the ChainlinkClient contract to gain the
// functionality of creating Chainlink requests
contract ChainlinkExample is ChainlinkClient {
// Stores the answer from the Chainlink oracle
uint256 public currentPrice;
address public owner;
set-option -g prefix C-g
unbind-key C-g
bind-key C-g send-prefix
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",*256col*:Tc"
set-option -g status-position bottom
set -g base-index 1
@0xA5DF
0xA5DF / !README.md
Last active August 19, 2022 13:37
Forge calculates gas as if it's all one tx (affecting ops that depend on warm/cold keys/addresses)

Forge calculates gas as if each test is one tx

Sample code

When runing forge test -m testGas --gas-report -vv, it shows the cost of calling x is 261:

╭──────────────────────────────────┬─────────────────┬─────┬────────┬─────┬─────────╮
│ contracts/Gas.sol:Store contract ┆                 ┆     ┆        ┆     ┆         │
╞══════════════════════════════════╪═════════════════╪═════╪════════╪═════╪═════════╡
│ Deployment Cost                  ┆ Deployment Size ┆     ┆        ┆     ┆         │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
function factorial_Yul_For(uint256 x) public pure returns(uint256){
assembly{
let result := 1
for {} iszero(iszero(x)) { x := sub(x, 1)} {
result := mul(result, x)
}
mstore(0,result)
return(0,0x20)
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
library Iterators {
// Function types:
// https://docs.soliditylang.org/en/latest/types.html#function-types
function map(uint256[] memory input, function (uint256) internal pure returns (uint256) f)
internal
pure