Skip to content

Instantly share code, notes, and snippets.

View bajcmartinez's full-sized avatar

Juan Cruz Martinez bajcmartinez

View GitHub Profile
@bajcmartinez
bajcmartinez / app.py
Last active January 6, 2024 06:21
Build Secure APIs with Flask and Auth0
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 / erc20-token-sample.sol
Last active October 13, 2023 22:58
Necessary code to generate an ERC20 Token
pragma solidity ^0.4.24;
// ----------------------------------------------------------------------------
// Sample token contract
//
// Symbol : LCST
// Name : LCS Token
// Total supply : 100000
// Decimals : 2
// Owner Account : 0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe
@bajcmartinez
bajcmartinez / app.py
Created October 12, 2021 08:19
Object tracking with python
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 / smart_contract.sol
Last active January 5, 2023 19:16
Access a Smart Contract from your web application
pragma solidity ^0.6.6;
contract CoolNumberContract {
uint public coolNumber = 10;
function setCoolNumber(uint _coolNumber) public {
coolNumber = _coolNumber;
}
}
@bajcmartinez
bajcmartinez / mine.py
Created May 18, 2020 19:17
From Zero to Blockchain in Python - Part 1 - Mine
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 / transaction.py
Created May 18, 2020 18:49
From Zero to Blockchain in Python - Part 1 - Transaction
import time
class Transaction:
def __init__(self, sender, recipient, amount):
"""
Creates a new transaction
:param sender: <str> sender account
:param recipient: <str> recipient account
@bajcmartinez
bajcmartinez / replace_blockchain.py
Created May 18, 2020 19:22
From Zero to Blockchain in Python - Part 1 - Replace Blockchain
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 19:19
From Zero to Blockchain in Python - Part 1 - Add Blocks
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 / validate_proof_of_work.py
Created May 18, 2020 19:13
From Zero to Blockchain in Python - Part 1 - PoW
@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 19:08
From Zero to Blockchain in Python - Part 1 - Constructor
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