Skip to content

Instantly share code, notes, and snippets.

@celsowhite
celsowhite / csv-to-json.js
Created September 1, 2022 20:08
Convert a csv file to json and save it to a folder.
/*-----------------------
Imports
-----------------------*/
import fs from "fs";
import glob from "glob";
import csv from "csvtojson";
/*-----------------------
Script
-----------------------*/
@celsowhite
celsowhite / keen-arrow-nav.js
Last active July 27, 2022 13:40
Keen slider nav plugins.
/*----------------------------
Keen Arrow Nav
---
Plugin for Keen sliders to configure arrow navigation.
----------------------------*/
export default function keenArrowNav(slider) {
// Elements
const container = slider.container.closest('.keen-slider__container');
const arrows = container.querySelectorAll('.keen-slider__arrow');
{
"id": 32608807518292,
"properties": {
"_version": 3,
"_Style": "fpg1001",
"_isTrackInventory": false,
"_trackInventoryOptions": [
],
"_price_additional": 3000,
<template>
<div class="character-screen__vertical-wave">
<svg
viewBox="0 0 202 1449"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
>
<g
id="Page-1"
<div class="hero__marquee marquee">
<div class="marquee__text">
<!-- HTML Markup -->
</div>
<div class="marquee__text">
<!-- HTML Markup -->
</div>
<div class="marquee__text">
<!-- HTML Markup -->
</div>
@celsowhite
celsowhite / leaky-bucket-simulator.js
Created March 1, 2022 12:02
Simulate a leaky bucket to understand how many calls and requests can be made in a certain amount of time without going beyond capacity.
let callCount = 0;
let bucketCount = 0;
// Bucket Settings
const bucketCapacity = 8;
const leakRate = 2;
const leakTime = 1000;
// Call Settings
const callAmount = 5;
/*------------------------
Libraries
------------------------*/
const axios = require("axios");
const fs = require("fs");
const FormData = require("form-data");
/*------------------------
Download the file.
Good article on how to download a file and send with form data - https://maximorlov.com/send-a-file-with-axios-in-nodejs/
@celsowhite
celsowhite / promise-all-map.js
Created September 14, 2021 16:59
Example of using a map function to process async requests in parallel.
async function printFiles () {
const files = await getFilePaths();
await Promise.all(files.map(async (file) => {
const contents = await fs.readFile(file, 'utf8')
console.log(contents)
}));
}
function createSticker(sticker, xPosition = 100, yPosition = 100) {
fetch(sticker.svg)
.then(res => res.text())
.then(svg => {
// Body Creation
// Save a blank array of vertex sets.
const vertexSets = [];
// Use the dom parser to parse our svg.
@celsowhite
celsowhite / calculate-container-margin.js
Created February 9, 2021 15:57
Calculate and set the container margin as a css variable. Helpful when breaking elements out of their container while maintaining alignment.
/*-------------------------
Calculate Container Margin
-------------------------*/
document.addEventListener('DOMContentLoaded', event => {
let root = document.documentElement;
// Calculate Container Margin
function calculateContainerMargin() {
const container = document.querySelector('.container');