Skip to content

Instantly share code, notes, and snippets.

View juanpprieto's full-sized avatar

Juan P. Prieto juanpprieto

View GitHub Profile
@phawk
phawk / install.js
Created August 23, 2019 16:17
Shopify install lambda
exports.handler = async (event, context) => {
const shop = event.queryStringParameters.shop
const redirectUri = event.queryStringParameters.redirect
const apiKey = process.env.SHOPIFY_API_KEY
const scopes="read_content,write_content,read_products,read_themes,write_themes"
if (shop) {
const installUrl = 'https://' + shop +
'/admin/oauth/authorize?client_id=' + apiKey +
'&scope=' + scopes +
@phawk
phawk / getToken.js
Created August 23, 2019 16:19
Shopify exchange OAuth code for token and create user account
const crypto = require("crypto")
const querystring = require("querystring")
const fetch = require("isomorphic-fetch")
const Account = require("./models/account")
exports.handler = async (event, context) => {
const { shop, hmac, code, timestamp } = event.queryStringParameters
const apiKey = process.env.SHOPIFY_API_KEY
const apiSecret = process.env.SHOPIFY_API_SECRET
@phawk
phawk / authentication.js
Created August 23, 2019 16:53
Lambda HoC for authenticating requests with dynamoDB
const Account = require("../models/account")
module.exports = (handler) => async (event, context) => {
let auth = event.headers.authorization
auth = auth.replace(/^Basic\s/, "")
auth = Buffer.from(auth, 'base64').toString()
const [id, token] = auth.split(":")
const account = await Account.get({ id })
@DavidWells
DavidWells / netlify-plugins.md
Last active January 2, 2022 01:49
Netlify Plugin Spec

Simple plugin

Here is a simple plugin with no config and it runs on a single lifecycle event postBuild

// Plugin code
@drovani
drovani / auth0-rule-shopify-multipass.js
Last active September 25, 2024 00:24
Auth0 Rule to Generate a Multipass token and redirect the user back to the Shopify store
function (user, context, callback) {
if (context.clientMetadata && context.clientMetadata.shopify_domain && context.clientMetadata.shopify_multipass_secret)
{
const RULE_NAME = 'shopify-multipasstoken';
const CLIENTNAME = context.clientName;
console.log(`${RULE_NAME} started by ${CLIENTNAME}`);
const now = (new Date()).toISOString();
let shopifyToken = {
email: user.email,
@Haraldson
Haraldson / usage.js
Last active March 11, 2023 13:53
Lodash useDebounce React Hook
import React, { useState, useEffect } from 'react'
import { useDebounce } from './use-debounce'
const MySearchComponent = props => {
const [search, setSearch, {
signal,
debouncing
}] = useDebounce('')
const [results, setResults] = useState([])
@ehpc
ehpc / ramda-promises-compose.js
Last active August 22, 2024 02:04
How to compose promises with Ramda
// Custom promise-based compose
const composeWithPromise = (...args) =>
R.composeWith((f, val) => {
if (val && val.then) {
return val.then(f);
}
if (Array.isArray(val) && val.length && val[0] && val[0].then) {
return Promise.all(val).then(f);
}
return f(val);
@spro
spro / next-ssr-recoil.js
Last active January 7, 2024 16:22
Attempt at SSR with Recoil - setting initial atom values with Next.js getServerSideProps
import {useEffect} from 'react'
import {RecoilRoot, useRecoilState, atom} from 'recoil'
// User data
const user1 = {username: 'joe', bio: "You will never see me, unless of course this example is totally broken."}
const user2 = {username: 'bob', bio: "I am the one true user."}
const user3 = {username: 'fred', bio: "Just kidding, make way for the new guy."}
// Recoil atom to store user. The default user is user1, but it will be
// original code: https://github.com/AnthumChris/fetch-progress-indicators
const element = document.getElementById('progress');
fetch('url')
.then(response => {
if (!response.ok) {
throw Error(response.status+' '+response.statusText)
}
@sindresorhus
sindresorhus / esm-package.md
Last active June 7, 2025 05:45
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.