Skip to content

Instantly share code, notes, and snippets.

@laalaguer
laalaguer / signature.js
Created January 13, 2020 07:10
Compound signature from user and sponsor
// Fetch the sponsor signature.
const sponsorSignature = await getSponosrSignature(
'0x'+originAddress.toString('hex'),
txBody
)
// Compose a combined signature of user + sponsor.
const sig = Buffer.concat([
originSignature,
Buffer.from(sponsorSignature, 'hex')
@laalaguer
laalaguer / user.js
Created January 13, 2020 07:22
User's side Snippet
/**
* Attempt to commit a transaction to a contract.
*
* With a hefty wallet as "sponsor" + an empty wallet as "sender".
*
*/
const fetch = require("node-fetch");
const cry = require('thor-devkit/dist/cry')
const Transaction = require('thor-devkit/dist/transaction').Transaction
@laalaguer
laalaguer / block_random.py
Created March 30, 2020 10:33
The random possibilites
import random
foo = random.SystemRandom()
threshold = 8
at_least = 5
bingo = 0
experiment_times = 100000
@laalaguer
laalaguer / possibility.py
Last active March 31, 2020 04:11
# In 100 numbers, # Have x numbers, that are <= y, # The possibly.
# Python3
# In 100 numbers,
# Exactly has (n) numbers, that are <= value
# The possibility.
def f(n, value):
a = 1 - value/100
b = value/100
# Numbers that are > 8
@laalaguer
laalaguer / count.py
Last active July 15, 2020 06:36
count the code, comments, empty lines in the project
# Python 3 Script
# Count the "real" code lines (exclude empty lines, and comments) in a project.
# Languages supported: Python, JavaScript, C, C++, Java, C#, etc....
# Analyse:
# A source code file contains code, and comments.
# Single line comments are easy. Just // or #
# Multi-line comments are begin usually with /*, and ends with */, this is
# accomplished with a stack, maybe. /* // */ counts as a single block of comments.
@laalaguer
laalaguer / VeChainRandom.sol
Last active February 26, 2022 11:35
Random Number Generation on VeChain
pragma solidity >=0.5.3 <=0.6.4;
contract Extension {
function blake2b256(bytes memory data) public view returns(bytes32);
function blockID(uint num) public view returns(bytes32);
function blockTotalScore(uint num) public view returns(uint64);
function blockTime(uint num) public view returns(uint);
function blockSigner(uint num) public view returns(address);
function totalSupply() public view returns(uint256);
function txProvedWork() public view returns(uint256);
@laalaguer
laalaguer / Crowd.sol
Last active January 12, 2022 10:29
Crowd contract allows users to participate in a crowd funding in a limited time frame.
pragma solidity >=0.5.3 <=0.6.4;
// Crowd contract allows users
// to participate in a crowd funding in a limited time frame.
// Owner of the contract can decide:
// 1. Stop time of this round of crowd funding (using block.number).
// 2. If allow a user to deposit multiple times.
// 3. To which address withdraw the funds collected.
@laalaguer
laalaguer / over_transfer_vtho.py
Created August 24, 2021 03:40
Over Transfer VTHO using transfer() method
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())
# 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}
@laalaguer
laalaguer / abstract-python.py
Created September 28, 2021 05:39
Python3 Interface and Abstract class
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):