Skip to content

Instantly share code, notes, and snippets.

View iamkevingreen's full-sized avatar
💭
🍝 🍝 🍝 🍝 🍝 🍝

Kevin Green iamkevingreen

💭
🍝 🍝 🍝 🍝 🍝 🍝
View GitHub Profile
/*------------------------
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/
@mikehwagz
mikehwagz / analytics.js
Last active January 31, 2021 02:12
basic gtm pattern + enhanced commerce
const BRAND_NAME = 'Lorem Ipsum'
export function gtmProduct(product, variant) {
return {
name: product.title,
id: variant.sku,
price: parseFloat(variant.price),
variant: variant.title,
brand: BRAND_NAME,
category: 'All',
<template>
<div class="m:fix m:fill m:f aic whiskey__wrap">
<div class="scroll-element m:nowrap wct m:f aic pt130 m:pt0" ref="scrollElement">
<ul class="whiskey l y m:f aic">
<li
v-for="(item, i) in page.whiskey_listing"
:key="`${item.uid}-${i}`"
class="rel y mb90 m:mb0"
>
<n-link
@mikehwagz
mikehwagz / .eleventy.js
Created September 24, 2020 16:19
blur-up image picoapp component in a 11ty sanity setup
// just the shortcodes you'll need in eleventy config
const cx = require('nanoclass')
const imageUrlBuilder = require('@sanity/image-url')
const sanityClient = require('./util/sanityClient')
const builder = imageUrlBuilder(sanityClient)
function urlFor(image, width, height) {
if (width) {
if (height) {
return builder
/* Get 12 most recent instagram thumbnails from a public account
* resolution = 0 - 4
* 0 => 150
* 1 => 240
* 2 => 320
* 3 => 480
* 4 => 640
*/
export default function(username, resolution = 4) {
return fetch(`https://www.instagram.com/${username}/?__a=1`)
import React, { useState, useEffect, useContext } from "react";
import { Checkout } from "shopify-storefront-api-typings";
import Client from "shopify-buy";
const SHOPIFY_CHECKOUT_STORAGE_KEY = "shopify_checkout_id";
const storefrontAccessToken = process.env.GASTBY_SHOPIFY_ACCESS_TOKEN as string;
const client = Client.buildClient({
storefrontAccessToken,
@marcio0
marcio0 / FilteredReference.js
Last active September 26, 2022 10:29
filtered reference field on sanity
import React from "react";
import PropTypes from "prop-types";
import { has } from "lodash";
import PatchEvent, { set, unset } from "part:@sanity/form-builder/patch-event";
import ReferenceInput from "@sanity/form-builder/lib/inputs/ReferenceInput";
import { withDocument } from "part:@sanity/form-builder";
import { map } from "rxjs/operators";
import client from "part:@sanity/base/client";
import { createWeightedSearch } from "../../utils/search";
import { observeForPreview } from "part:@sanity/base/preview";
@kmelve
kmelve / BlockEditor.js
Created September 14, 2019 11:56
Custom portable text / block editor for Sanity with markdown paste and stats
import React, { Component, Fragment } from 'react'
import { BlockEditor } from 'part:@sanity/form-builder'
import Switch from 'part:@sanity/components/toggles/switch'
import css from './BlockEditor.module.css'
import { handlePaste } from './handlePaste'
export default class CustomEditor extends Component {
state = {
customPaste: false
}
/*
home.js
--
This script takes the JSON data from the home page for posts and tweets and
randomly displays them into a randomly selected template which is then
Variables from Home HTML:
@dan-dr
dan-dr / index.js
Created March 28, 2019 21:23
Sanity Backup to Dropbox on webtask.io
const sanity = require('@sanity/client')
const fs = require('fs')
const EOL = require('os').EOL
const flatMap = require('lodash.flatmap')
const { subDays, isBefore } = require('date-fns')
const sanityExport = require('@sanity/export')
/**
* @param context {WebtaskContext}
*/