leonelgalan's notebooks

  • URL Validation - /leonelgalan/url-validation
    Last edited 16 days ago
    const endpoint = require('@runkit/runkit/json-endpoint/1.0.0'); const request = require('request'); // const axios = require('axios'); // const queryString = require('query-string'); // const atob = require('atob') // const MAX_REDIRECTS = 10; // const landing_regex = /https:\/\/web\.epifany\.com\/([^?\/]*)($|\?(.*))/; // const new_regex = /https:\/\/web\.epifany\.com\/([^\/]*)\/new#(.*)/; // const canes = 'http://app.response.canesmail.com/e/er?s=1468279136&lid=2723&elqTrackId=8B1D9A6D3B2CD8F0E7AEEE69AFD7D82B&email=Leonel.Galan%40Epifany.com&elq=c02e58c3c834487ab97662998bc28363&elqaid=2282&elqat=1' // const duke = 'http://goduke.com/footballfeedback' // const dukeWrong = 'https://urldefense.proofpoint.com/v2/url\?u\=http-3A__goduke.acemlnb.com_lt.php-3Fs-3D313c189602ad6985a8816e1931b97d5b-26i-3D1849A3660A914A17982\&d\=DwMFaQ\&c\=imBPVzF25OnBgGmVOlcsiEgHoG1i6YHLR0Sj_gZ4adc\&r\=P4B0SZAhb9snWi2h_Qd2gg\&m\=po6Qcgy9jaSCmJE4dJO9KbNs3Q4ulltWUB2KEv15YCw\&s\=d7KWdSCaSnnJarXRTu8wqofj2ViAunqIj1TrPgR_pGA\&e\='; // const url = dukeWrong; // const redirectUrl = async (url) => { // const result = await axios.request({ url, method: 'GET', maxRedirects: 0 }).then(_ => undefined).catch((error) => { // if (error.response.status === 301 || error.response.status === 302) { // return error.response.headers.location; // } // }); // return result; // }; // const foo = async bar => { // const urls = [request.query.url] // let newMatch = undefined; // let landingMatch = undefined; // let newUrl = request.query.url // let i = 1; // do { // newUrl = await redirectUrl(newUrl); // urls.push(newUrl) // let match = newUrl.match(landing_regex); // if (match !== null) { // landingMatch = match; // } // newMatch = newUrl.match(new_regex); // // console.log(`URL #${i}: ${newUrl}`); // i++; // } while (!newMatch && i < MAX_REDIRECTS); // const landingParams = landingMatch && queryString.parse(landingMatch[3]); // const newParams = newMatch && queryString.parse(newMatch[2]); // const result = { // landing: landingParams !== undefined, // urls, // email: { // requested: landingParams && landingParams['email'], // served: newParams && atob(newParams['id']), // }, // major: { // requested: landingParams && landingParams['major'], // served: newParams && atob(newParams['major']), // }, // type: { // requested: landingParams && landingParams['type'], // served: newParams && atob(newParams['type']), // }, // }; // return result; // // return {incomingData}; // }; endpoint(module.exports, async function(request) { return { test: 'OK' }; });
  • Tinycolor's monochromatic palette - /leonelgalan/tinycolor-monochromatic-palette
    Last edited 8 months ago
    const _ = require("lodash") const tinycolor = require("tinycolor2"); const color = 'blue'; const number = 10 const offset = Math.round(number / 2); const monochromaticByLuminance = (color, steps) => { const hsl = color.toHsl(); const { s, h } = hsl; let { l } = hsl; const modification = 1 / steps; const ret = []; _.times(steps, () => { ret.push(tinycolor({ h, s, l })); l = (l + modification) % 1; }); return ret; }; _(monochromaticByLuminance(tinycolor(color), number)) .sortBy(color => color.toHsl().l) .reverse() .map((color, index) => { const hsl = color.toHsl(); const { s, l } = hsl; let { h } = color.toHsl(); h = (h + 6 * index - (number / 2)) % 255; //console.log({h, l, color: tinycolor({ h, s, l }).toHexString()}); return tinycolor({ h, s, l }).toHexString(); }).value();
  • Name to Color - /leonelgalan/name-to-color
    Last edited 2 years ago
    const tinycolor = require("tinycolor2") const stringHash = require("string-hash"); const faker = require('faker'); const _ = require('lodash'); const baseColor = tinycolor('#25bcca'); const hsv = baseColor.toHsv(); _.times(40, () => { const name = faker.name.findName(); const hash = stringHash(name); const h = 175 + (hash % 155); const color = tinycolor({ h, s: 82 + (hash % 10), v: 83 + (hash % 10) }); const initial = name[0].toUpperCase(); return({h, initial, color: color.toHexString(), name}); });