Skip to content

Instantly share code, notes, and snippets.

View squamuglia's full-sized avatar
💭
🌶️

Max Smouha squamuglia

💭
🌶️
View GitHub Profile
@squamuglia
squamuglia / mayple-code-samples.liquid
Created January 6, 2023 15:11
Mayple Code Samples
# Product Variant Metafields
namespace: mayple_inventory
key: is_available
# Product Page Sample Sold Out Message
{%- if product.selected_or_first_available_variant.metafields.mayple_inventory.is_available != true and localization.country.iso_code != 'US' -%}
{{ 'products.product.sold_out' | t }}
{%- elsif product.selected_or_first_available_variant.available -%}
{{ 'products.product.add_to_cart' | t }}
{%- else -%}
@squamuglia
squamuglia / README.md
Last active November 7, 2022 22:22
External API Documentation

External API

Order JSON schema
{
  createdAt: DateTime, // ISO 8601
  orderId: string,
  lineItems: [
    {
import fetch from "node-fetch"
import sanityClient from "@sanity/client"
import * as fs from "fs"
import { fetchAPI } from "./fetchApi"
import gql from "graphql-tag"
const API_URL = "[add yours here]"
export async function fetchAPI(query, { variables = null } = {}) {
const QUERY = typeof query === "string" ? query : query?.loc.source.body
import fs from "fs";
const convertNDJSONtoJSON =
(ndjsonPath: string, jsonOutputPath: string) => async () => {
const data = await new Promise((res, rej) => {
const dataNDJSON: any[] = [];
const stream = fs.createReadStream(ndjsonPath).pipe(ndjson.parse());
stream.on("data", (obj: any) => dataNDJSON.push(obj));
stream.on("end", () => res(dataNDJSON));
import fs from "fs";
const readFileToString = (path: string): Promise<string | undefined> =>
new Promise((res, rej) =>
fs.readFile(path, (err, data) => {
if (err) return rej(err);
res(data?.toString());
}),
);
@squamuglia
squamuglia / FastifyApp.ts
Last active May 29, 2020 19:55
A fastify app for handling multipart form data
import fastify,{ FastifyInstance } from "fastify";
import cors from "fastify-cors";
import multipart from "fastify-multipart";
import { FastifyInstance } from "fastify";
import cloudinary from "cloudinary";
import { Server, IncomingMessage, ServerResponse } from "http";
const server: FastifyInstance<
Server,
IncomingMessage,
import React, { useState } from 'react';
import axios from 'axios';
export default () => {
const [image, setImage] = useState(null);
const [error, setError] = useState(null);
const onSubmit = async (e) => {
e.preventDefault();
@squamuglia
squamuglia / queryFontSizes.js
Last active February 9, 2021 17:57
A little js util for designer to find all the breakpoints and fontsizes on a website.
/**
* Get all of the tags and their fontsize,
* as well as the breakpoints for a given site
*/
function run() {
// Tags to check, add any tags you like to the list
const tags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'input', 'a'];
// An object to store our fontsizes in
const dict = {};