Skip to content

Instantly share code, notes, and snippets.

View voith's full-sized avatar
👨‍🎓
Building on top of Ethereum

Voith voith

👨‍🎓
Building on top of Ethereum
View GitHub Profile
@voith
voith / marketcap_share.py
Created January 24, 2022 10:02
Crypto MarketCap stats on of 24 Jan 2022
# below is the list of top 100 crypto by marketcap
# The data was fetched from coinmarketcap using the following xpath: `//td[7]`
top_100_crypto_marketcap = [
658219848892, # BTC
280749726821, # ETH
78325902003, # USDT
58926965670, # and so on...
47738008009,
34138378623,
28006007353,
@voith
voith / triangle_pattern.py
Created January 13, 2022 19:24
Triangle pattern using python
# Been a while since I made one of these.
# The last time I made one, I was in college.
def print_triangle(n: int):
for i in range(1, n + 1):
digits = len(str(n))
print((" " * (digits + 1)) * (n - i) , end="")
for j in range(i):
print(" %s" % str(j + 1).rjust(digits, "0"), end="")
for j in range(i - 1):
@voith
voith / eth_tester_pv_key.py
Created September 22, 2021 18:34
Eth-Tester Private Key Workaround
from eth_account import Account
from eth_tester.backends.pyevm.main import get_default_account_keys
acc = Account.from_key(get_default_account_keys()[0])
print(acc.key)
@voith
voith / withdraw.sol
Last active January 13, 2022 19:27
Sample solidity function
pragma solidity ^0.5.16;
contract DummyERC20 is ERC20 {
function withdraw() external {
uint256 amount = balances[msg.sender];
// demo reentracy
require(msg.sender.call.value(amount)());
balances[msg.sender] = 0;
}
pps = [
'1-5 k: kkkkhkkkkkkkkkk',
'5-7 k: blkqhtxfgktdkxzkksk',
'15-16 x: xxxxxxxxxxxxxxlf',
'3-5 j: fjpvj',
'17-20 x: zsxjrxkgxxxxxxxmxgxf',
'5-6 m: swjzmmmlx',
'2-4 v: vqdn',
'8-12 t: thllsbqtgdsf',
'10-17 h: vpbrjcbhnwqhhphxjk',
@voith
voith / evm_add.py
Created October 19, 2020 12:58
Example to add two numbers using the Ethereum virtual Machine.
from eth.vm.forks import (
IstanbulVM,
)
from eth.vm import (
opcode_values
)
from tests.core.opcodes.test_opcodes import (
assemble,
CANONICAL_ADDRESS_B,
[{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}, {
"anonymous": false,
"inputs": [{
"indexed": false,
"internalType": "string",
def get_all_substrings(arr, index, subarr, record):
if index == len(arr):
if len(subarr) != 0:
record.append(''.join(subarr))
else:
get_all_substrings(arr, index + 1, subarr, record)
get_all_substrings(arr, index + 1, subarr + [arr[index]], record)
return record
@voith
voith / grid_dfs.py
Created December 13, 2019 18:22
total number of connected regions in a grid
class Solution(object):
def __init__(self, matrix, row, col):
self.matrix = matrix
self.row = row
self.col = col
def is_safe(self, i, j, visited):
return (
0 <= i < self.row and
@voith
voith / coin_change.py
Last active November 30, 2019 18:52
Findall possible ways €2 can be split using coins 1p, 2p, 5p, 10p, 20p, 50p, €1 (100p) and €2 (200p)
final_target = 200
possibilities = [0] * (final_target + 1)
possibilities[0] = 1
# keeping the coins sorted is the key here
# we want to compute possibilities for lower coins first.
# This helps us to fix one particular coin and
# then find the other possibilites of the change needed
coins = [1, 2, 5, 10, 20, 50, 100, 200]
for coin in coins:
for current_target in range(coin, final_target + 1):