Skip to content

Instantly share code, notes, and snippets.

View alanrsoares's full-sized avatar

Alan Soares alanrsoares

View GitHub Profile
@alanrsoares
alanrsoares / multiplication.js
Created June 26, 2019 10:41
Multiplication with no multiplication, using range reduce
const isInt = n => parseInt(n) === n;
const toPrecisionN = precision => n =>
Number((n).toPrecision(precision));
function multiplyInt(a, b) {
const iterable = [...new Array(Math.abs(Math.floor(a)))];
return iterable.reduce(
acc => a < 0
? acc - b
@alanrsoares
alanrsoares / multiplication.js
Last active June 27, 2019 00:06
Multiplication with no multiplication, using range reduce
const isInt = n => parseInt(n) === n;
const toPrecisionN = precision => value =>
Number(value.toPrecision(precision));
function multiplyInt(a, b) {
const iterable = [...Array(Math.abs(Math.floor(a)))];
return iterable.reduce(
acc => a < 0
@alanrsoares
alanrsoares / HSLGenerator.js
Last active September 2, 2020 00:49
HSL color generator with bilinear interpolation
class HSLGenerator {
constructor(hueLength = 100, options = { lightness: 0.6, saturation: 1 }) {
this.hueIncrement = 360 / Math.sqrt(hueLength ** 2 * 2);
this.saturation = options.saturation * 100;
this.lightness = options.lightness * 100;
this.cache = {};
}
getColor(y, x) {
const cacheKey = [y, x].join("-");
import { css } from "styled-components";
/**
* Represents an RGB color as a string in the format `rgb(${number},${number},${number})`
* or as a tuple of numbers `[number, number, number]`.
*/
type RGB = `rgb(${number},${number},${number})` | [number, number, number];
/**
* Props for the `ring` mixin.
@alanrsoares
alanrsoares / download-svgrepo-collection.ts
Created May 27, 2025 02:30
Download entire svg collections from svgrepo.com
import { writeFile, mkdir } from "fs/promises";
import { join } from "path";
import { load } from "cheerio"; // install with `bun add cheerio`
const COLLECTION_URLS = [
"https://www.svgrepo.com/collection/finance-6/",
"https://www.svgrepo.com/collection/finance-6/2",
];
const OUTPUT_DIR = "./public/vectors";