Skip to content

Instantly share code, notes, and snippets.

View duartefdias's full-sized avatar

Duarte Dias duartefdias

View GitHub Profile
// Process signed message
router.post('/:user/signature', (req, res) => {
// Get user from db
db.get('SELECT * FROM users WHERE address = ?', [req.params.user], (err, row) => {
if (err) {
console.error(err.message);
return res.status(500).send(err.message);
}
if (row) {
const msg = `Nonce: ${row.nonce}`;
function checkIfWalletConnected() {
if (window.ethereum.request({ method: 'eth_accounts' }).then(function (accounts) {
if (accounts.length > 0) {
connected = true;
buyerAddress = accounts[0];
} else {
connected = false;
}
})
) {
function connectWallet() {
if (window.ethereum) {
console.log('MetaMask is installed');
window.web3 = new Web3(window.ethereum);
window.ethereum.send('eth_requestAccounts').then(function() {
// Get account address
window.ethereum.request({ method: 'eth_accounts' })
.then(function(accounts) {
if (accounts.length > 0) {
buyerAddress = accounts[0];
function makePaymentRequest(buyerAddress, sellerAddress, itemPriceInWei) {
// Start wallet payment process
window.ethereum.request({ method: 'eth_sendTransaction', params: [{ from: buyerAddress, to: sellerAddress, value: itemPriceInWei }] })
.then(response => {
console.log(response);
return true;
})
.catch(error => {
console.log(error);
return false;
<template>
<div class="m-4 max-w-lg rounded overflow-hidden shadow-lg bg-white">
<div class="p-4 max-w-xl" v-if="!connected" :key="updateModal">
<h2 class="text-xl pb-9">Select one of the bellow options to perform a cryptocurrency transation via the ethereum test network.</h2>
<div class="flex space-x-4">
<button @click="checkWalletConnected" class="py-2 px-8 rounded button-custom flex"><img src="@/assets/logos/metamask-logo.png" class="w-6 mr-3" alt=""> Metamask</button>
<button class="py-2 px-8 rounded button-custom disabled-custom flex"><img src="@/assets/logos/coinbase-logo.svg" class="w-6 mr-3" alt=""> Coinbase wallet</button>
</div>
</div>
@duartefdias
duartefdias / gist:3d8ebaed70cd5da41431df7b604d8505
Created December 19, 2024 10:54
Convert excel file into csv keeping formulas (for use with LLMs)
import openpyxl
import csv
def excel_to_csv_with_formulas(excel_path, csv_path, sheet_index=None):
"""
Convert Excel file to CSV, preserving formulas.
Args:
excel_path: Path to input Excel file
csv_path: Path to output CSV file
sheet_index: Optional index of specific sheet to convert (0-based).