Skip to content

Instantly share code, notes, and snippets.

/*------------------------
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 / scroll-direction-indicator.js
Created November 30, 2020 13:27
Detect scroll direction using gsap.
import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
function initScrollDirectionIndicator() {
// GSAP Plugins
gsap.registerPlugin(ScrollTrigger);
/*----------------------------
Elements
----------------------------*/
@celsowhite
celsowhite / otto-code-reference.liquid
Last active September 23, 2023 18:11
Otto Code Reference
{%- comment -%}
Otto Metafield Data
---
Reference for integrating Otto into a theme.
{%- endcomment -%}
{% comment %}
Placement Name
---
The placement name is the name provided in the app. Given a placement name, you can reference all of it's data in metafields.
@celsowhite
celsowhite / otto.liquid
Last active July 24, 2023 18:25
Otto snippet for generating a scheduled image placement.
{% comment %}
Data
---
otto_placement_name: Pass this to the snippet. The name is provided in the Otto app.
{% endcomment %}
{% liquid
assign otto_image_metafield = shop.metafields.otto-components[otto_placement_name].value
assign otto_image_file = shop.metafields.otto-files[otto_placement_name].value
assign otto_mobile_image_file_name = otto_placement_name | append: "-mobile"
@celsowhite
celsowhite / modal.html
Last active July 24, 2023 17:10
Javascript Modal Starter Code - Enable multiple modals on the same page with a single script.
<a class="modal-trigger" data-modal="recap-video-modal">Recap Video</a>
<div class="modal recap-video-modal">
<div class="modal__transparent-layer modal-close"></div>
<div class="modal__content">
<p>Some content to go in the modal.</p>
</div>
<span class="close-icon modal-close"></span>
</div>
@celsowhite
celsowhite / get-elem-coords.js
Created March 21, 2023 16:55
Get the coordinates of an element relative to the top of the page.
export default function getElemCoords(elem) {
var box = elem.getBoundingClientRect();
var body = document.body;
var docEl = document.documentElement;
var scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;
var scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;
var clientTop = docEl.clientTop || body.clientTop || 0;
export default function randomIntFromInterval(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
const delay = (ms) => new Promise((r) => setTimeout(r, ms));
export default delay;
{% comment %}
Template used sitewide for each time a product is displayed.
This template handles the product/variant images, showing product information and variants.
At the bottom of the html is a script that dynamically show price and updates the selected variant ID.
The script for adding the product to the cart is in scripts.js.
{% endcomment %}
@celsowhite
celsowhite / json-to-csv.js
Last active September 23, 2022 13:54
Given a json file or json data output it's contents to a csv.
/*-----------------------
Imports
-----------------------*/
import fs from "fs";
import csv from "csvtojson";
import path from "path";
import { fileURLToPath } from "url";
import { stringify } from "csv";
/*-----------------------