Skip to content

Instantly share code, notes, and snippets.

Avatar

Juan Cruz Martinez bajcmartinez

View GitHub Profile
@bajcmartinez
bajcmartinez / app.py
Created Oct 12, 2021
Object tracking with python
View app.py
import cv2
import sys
(major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')
if __name__ == '__main__' :
# Set up tracker.
# Instead of CSRT, you can also use
@bajcmartinez
bajcmartinez / app.py
Last active Sep 23, 2021
Build Secure APIs with Flask and Auth0
View app.py
import json
from six.moves.urllib.request import urlopen
from functools import wraps
from flask import Flask, request, jsonify, _request_ctx_stack
from flask_cors import cross_origin
from jose import jwt
AUTH0_DOMAIN = 'AUTH0-DOMAIN'
API_IDENTIFIER = 'API-IDENTIFIER'
@bajcmartinez
bajcmartinez / smart_contract.sol
Last active Sep 27, 2021
Access a Smart Contract from your web application
View smart_contract.sol
pragma solidity ^0.6.6;
contract CoolNumberContract {
uint public coolNumber = 10;
function setCoolNumber(uint _coolNumber) public {
coolNumber = _coolNumber;
}
}
@bajcmartinez
bajcmartinez / erc20-token-sample.sol
Last active Oct 16, 2021
Necessary code to generate an ERC20 Token
View erc20-token-sample.sol
pragma solidity ^0.4.24;
// ----------------------------------------------------------------------------
// Sample token contract
//
// Symbol : LCST
// Name : LCS Token
// Total supply : 100000
// Decimals : 2
// Owner Account : 0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe
@bajcmartinez
bajcmartinez / replace_blockchain.py
Created May 18, 2020
From Zero to Blockchain in Python - Part 1 - Replace Blockchain
View replace_blockchain.py
def validate_chain(self, chain_to_validate):
"""
Verifies if a given chain is valid
:param chain_to_validate: <[Block]>
:return: <bool> True if the chain is valid
"""
# First validate both genesis blocks
if chain_to_validate[0].hash_block() != self.__chain[0].hash_block():
return False
@bajcmartinez
bajcmartinez / add_blocks.py
Created May 18, 2020
From Zero to Blockchain in Python - Part 1 - Add Blocks
View add_blocks.py
def add_block(self, block):
"""
Creates a new block and passes it to the chain
:param block: <Block> Block to add to the chain
:return: <bool> True if the block is added to the chain, False if not.
"""
if self.validate_block(block, self.last_block):
self.__chain.append(block)
@bajcmartinez
bajcmartinez / mine.py
Created May 18, 2020
From Zero to Blockchain in Python - Part 1 - Mine
View mine.py
def mine(self, reward_address):
"""
Mines a new block into the chain
:param reward_address: <str> address where the reward coin will be transferred to
:return: result of the mining attempt and the new block
"""
last_block = self.last_block
index = last_block.index + 1
previous_hash = last_block.hash
@bajcmartinez
bajcmartinez / validate_proof_of_work.py
Created May 18, 2020
From Zero to Blockchain in Python - Part 1 - PoW
View validate_proof_of_work.py
@staticmethod
def validate_proof_of_work(last_nonce, last_hash, nonce):
"""
Validates the nonce
:param last_nonce: <int> Nonce of the last block
:param nonce: <int> Current nonce to be validated
:param last_hash: <str> Hash of the last block
:return: <bool> True if correct, False if not.
"""
@bajcmartinez
bajcmartinez / constructor.py
Created May 18, 2020
From Zero to Blockchain in Python - Part 1 - Constructor
View constructor.py
def __init__(self):
self.__current_transactions = []
self.__chain = []
# Create genesis block
self.create_genesis()
def create_genesis(self):
"""
Creates the Genesis block and passes it to the chain
@bajcmartinez
bajcmartinez / create_transaction.py
Created May 18, 2020
From Zero to Blockchain in Python - Part 1 - Create Transaction
View create_transaction.py
def create_transaction(self, sender, recipient, amount):
"""
Creates a new transaction to go into the next block
:param sender: <str> sender address
:param recipient: <str> recipient address
:param amount: <float> amount
:return: <Transaction> generated transaction
"""
transaction = Transaction(sender, recipient, amount)