Skip to content

Instantly share code, notes, and snippets.

View avaleriani's full-sized avatar
🎯
Focusing

Agu Valeriani avaleriani

🎯
Focusing
View GitHub Profile
@avaleriani
avaleriani / jprq-proxy.js
Last active January 10, 2021 20:29
Jprq cloudfare worker proxy
// We support the GET, POST, HEAD, and OPTIONS methods from any origin,
// and allow any header on requests. These headers must be present
// on all responses to all CORS preflight requests. In practice, this means
// all responses to OPTIONS requests.
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS",
"Access-Control-Max-Age": "86400",
}
@avaleriani
avaleriani / currencies.json
Last active April 14, 2024 09:00
Currencies list with emoji flags. Same as https://gist.github.com/avaleriani/2ce5d24f905825ce0e2f8489c9fda4c3 but in json.
{
"currencies": [
{
"symbol": "€",
"name": "Euro",
"symbol_native": "€",
"code": "EUR",
"emoji": "🇪🇺"
},
{
@avaleriani
avaleriani / currencies.js
Last active March 2, 2024 11:48
Currencies list with emojis (XOF, XCD and XAF have representatives flag emojis)
export default [
{
"symbol": "€",
"name": "Euro",
"symbol_native": "€",
"code": "EUR",
"emoji": "🇪🇺"
},
{
"symbol": "$",
//31.01.2000
// startDateOfContract = parameter
//customerAgeWhenContractEnd = parameter
//return end date of the contract = 1 day before the start date at the moment that the customer has the age he picked.
const calculateEndDateOfContract = (customerBirthDate, startDateOfContract, customerAgeWhenContractEnd) => {
customerBirthDate = splitDate(customerBirthDate);
startDateOfContract = splitDate(startDateOfContract);
let endContractDate = new Date(customerBirthDate.year + customerAgeWhenContractEnd, startDateOfContract.month - 1, startDateOfContract.day - 1);
@avaleriani
avaleriani / flatten.js
Created April 13, 2016 22:18
Convert nested array into a flat one
//ES6
var flatten = {
makeFlat : function(arr) {
var res = [];
for (var i = 0; i < arr.length; i++) {
if (arr[i] instanceof Array) { //if the current position is an array then we keep looking for a value.
res.push.apply(res, this.makeFlat(arr[i])); //recursively calls makeFlat and concatenates with res.
} else {
res.push(arr[i]); //when is not an array, directly concatenate the value