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
View jprq-proxy.js
// 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 August 9, 2022 17:53
Currencies list with emoji flags. Same as https://gist.github.com/avaleriani/2ce5d24f905825ce0e2f8489c9fda4c3 but in json.
View currencies.json
{
"currencies": [
{
"symbol": "€",
"name": "Euro",
"symbol_native": "€",
"code": "EUR",
"emoji": "🇪🇺"
},
{
@avaleriani
avaleriani / currencies.js
Last active January 21, 2024 16:16
Currencies list with emojis (XOF, XCD and XAF have representatives flag emojis)
View currencies.js
export default [
{
"symbol": "€",
"name": "Euro",
"symbol_native": "€",
"code": "EUR",
"emoji": "🇪🇺"
},
{
"symbol": "$",
View gist:62edb971ba700e8b7f5474fa8ed09428
//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
View flatten.js
//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