Skip to content

Instantly share code, notes, and snippets.

View joaosouz4dev's full-sized avatar
🚀
Focusing production

João Victor Souza joaosouz4dev

🚀
Focusing production
View GitHub Profile
@joaosouz4dev
joaosouz4dev / gist:d9bcce6f45f1af0aa3b337db847ec09d
Last active February 17, 2023 05:34
Javascript Cash Withdrawal like Cash Machine
// function in javascript that performs a withdrawal based on the balance and an array of banknotes available, for example, I need to withdraw 5 reais, and there are notes of 5 notes of 10, 4 notes of 20, 3 of 50, 5 of 100, so it would not have value of 5 reais, and if I withdraw 550 I discount it on the bills and I always do it in the best way possible
function cashWithdrawal(value, availableNotes) {
let notes = [];
let availableNotesOriginal = structuredClone(availableNotes);
// array com os valores de todas as notas disponíveis
const allNotesValues = Object.keys(availableNotes).map((note) => Number(note)).sort((a, b) => b - a);
for (const subsetNotes of subsets(allNotesValues, 0, 2)) {
let remainingValue = value;
for (const noteValue of subsetNotes) {
// quantas notas desse valor eu preciso?
@joaosouz4dev
joaosouz4dev / proxy.js
Created September 22, 2021 20:56
proxy server node js - change ip request
import express from "express";
import httpProxy from "http-proxy";
const proxy = httpProxy.createProxyServer({
changeOrigin: true,
});
const app = express();
function buildAuthHeader(user, pass) {
return "Basic " + Buffer.from(user + ":" + pass).toString("base64");
@joaosouz4dev
joaosouz4dev / localization.html
Last active September 22, 2021 20:59
Capturando localização com javascript por IP e API de Localização
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input name="laInicioMapa" id="laInicioMapa" value="-23.526217">