This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' Python script to find the earliest block that an account has code. | |
python3 find.py [node_url] [address] | |
''' | |
import sys | |
from typing import Union | |
from thor_requests.connect import Connect | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt | |
class Uniswap: | |
def __init__(self, xs): | |
self.xs = xs | |
self.lastK = sqrt(xs[0] * xs[1]) | |
def swap(self, i, dx): | |
d = self.xs[0] * self.xs[1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Speed up. | |
cache = {} | |
def f(n): | |
# Speed up. | |
if cache.get(n) != None: | |
return cache[n] | |
if n == 1: | |
print('n==1, directly return 1') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# No speed up. | |
def f(n): | |
if n == 1: | |
print('n==1, directly return 1') | |
return 1 | |
p = [] # Storage for temp results. | |
for i in range(1, n): # i in [1, n) | |
temp = 1 + max(i-1, f(n-i)) | |
p.append(temp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PathFinder { | |
constructor(pairs) { | |
this.graph = new Map() | |
pairs.forEach((item) => { | |
if (!this.graph.has(item[0])) { | |
this.graph.set(item[0], new Array()) | |
} | |
if (!this.graph.has(item[1])) { | |
this.graph.set(item[1], new Array()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DotPath { | |
constructor(a, b) { | |
this.storage = [a, b] | |
} | |
hasDot(dot) { | |
switch (dot) { | |
case this.storage[0]: | |
return true | |
case this.storage[1]: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import abc | |
class A(abc.ABC): | |
@abc.abstractmethod | |
def foo(self): | |
print("abstract foo()") | |
class B(A): | |
def foo(self, who:str): # Note: function signature is different | |
print("hello", who) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import abc | |
class MyInterface(abc.ABC): # Same as class MyInterface(metaclass=abc.ABCMeta) | |
def __init__(self, age: int): | |
print('MyInterface: init') | |
self.age = age | |
@abc.abstractmethod | |
def load_data(self, name: str): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CPU temperature | |
read temperature < /sys/class/thermal/thermal_zone0/temp | |
printf "CPU:\t%s °C\n" $(($temperature/1000)) | |
# Memory pressure | |
memtotal=0 | |
memfree=0 | |
while read -r name value unit; do | |
if [ "${name}" == "MemTotal:" ]; then | |
memtotal=${value} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from thor_requests.connect import Connect | |
from thor_requests.wallet import Wallet | |
connector = Connect("https://sync-testnet.vechain.org") | |
# wallet address: 0x7567d83b7b8d80addcb281a71d54fc7b3364ffed | |
_wallet = Wallet.fromPrivateKey(bytes.fromhex("dce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65")) | |
# View the vtho this wallet has (in Wei): | |
vtho_balance = connector.get_vtho_balance(_wallet.getAddress()) |
NewerOlder