Skip to content

Instantly share code, notes, and snippets.

View joshuaiz's full-sized avatar
💭
it iz what it iz

Joshua Michaels joshuaiz

💭
it iz what it iz
View GitHub Profile
function regReplaceWithComponent(
text: string,
exp: RegExp,
fn: (match: string, index: number) => JSXElement
) {
const matches = Array.from(text.matchAll(exp));
const items: JSXElement[] = [];
for (let index = 0; index < matches.length; index++) {
const match = matches[index];
@jeffquach
jeffquach / Shopify verify theme support
Last active January 3, 2023 00:30
Sample code: https://shopify.dev/apps/online-store/verify-support contains bugs. The code should be checking `templateJSONFiles.length > 0` but doesn't. The gist also doesn't not use Shopify's node library and HTTP requests are made to Shopify's REST API using node-fetch, but any HTTP library can be used instead
const fetch = require('node-fetch');
try {
// Specify the name of the template the app will integrate with
const APP_BLOCK_TEMPLATES = ['product', 'collection'];
const getOptions = { method: 'GET', headers: { 'X-Shopify-Access-Token': accessToken } };
// Get published theme
const themeResponse = await fetch(`https://${shop}/admin/api/${API_VERSION}/themes.json`, getOptions);
this.checkError(themeResponse, 'ThemeFetchFailure');
@lexthor
lexthor / Download-Shopify-CDN-Assets.md
Last active April 30, 2024 01:16 — forked from ridem/Download-Shopify-CDN-Assets.md
Download all Shopify CDN assets from a store

Instructions

  1. Go to your Shopify admin/settings/files page
  2. Open your browser Dev tools, go to the console
  3. Paste the content of the console_download_list.js file, and press enter
  4. Your browser will automatically fetch each page and download the list with the links of all the files on the CDN.
  5. Using your preffered code editor, edit the HTML file by adding each link in img tag.
  6. Open the HTML file you just edit in a browser then right click-save as. It will download the HTML file again along with all the images in the location you specify.
@scottopolis
scottopolis / zip-clean-alias.sh
Last active May 28, 2020 20:27
ZSH alias to zip current folder, remove git and DS Store files, and show in finder
# put this in your .zshrc file, change path to store zip, restart terminal
# run command `releasezip my-files-1.0`, which would create a zip at ../my-files-1.0.zip
# change output path (../) to whatever you want, for example Users/Me/Plugins/Releases/$1.zip
releasezip() {
zip -r ../$1.zip . -x '*.git*' --exclude=\*.DS_Store\*
open ../
}
@jayhill90
jayhill90 / launch.json
Created April 17, 2020 17:34
XDebug Configuration file for VSCode and Local by Flywheel
{
// Set your VSCode Workspace root to the root folder of your Local site.
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
@joshuacerbito
joshuacerbito / useScroll.js
Last active January 8, 2024 13:44
Custom React hook for listening to scroll events
/**
* useScroll React custom hook
* Usage:
* const { scrollX, scrollY, scrollDirection } = useScroll();
*/
import { useState, useEffect } from "react";
export function useScroll() {
const [lastScrollTop, setLastScrollTop] = useState(0);
@ahmadawais
ahmadawais / flywheel-local-xdebug-vscode.md
Last active November 23, 2023 16:55
Debug WordPress with Visual Studio Code | VSCode WordPress Debug Setup | WordPress xDebug Setup for Local by FlyWheel with VSCode | Part of the VSCode Learning Course → https://VSCode.pro

VSCode WordPress Debugging Setup: WordPress Xdebug Setup for Local by FlyWheel with VSCode


Consider supporting my work by purchasing the course this tutorial is a part of i.e. VSCode Power User

🚅 TL;DR

  • Make sure your Local by FlyWheel WordPress install is a custom install
@shopifypartners
shopifypartners / a-beginners-guide-to-sass-part-3-interpolation.liquid.scss
Last active February 13, 2023 08:04 — forked from stewartknapman/style.liquid.scss
A Beginner's Guide to Sass with Shopify — Part 3: Sass interpolation, Workflow and Object Oriented CSS - https://www.shopify.com/partners/blog/a-beginners-guide-to-sass-with-shopify-part-3
// Escaping Liquid in SCSS.
//
// Expected output:
// a{
// color: {{ settings.link-color }};
// }
a{
color: #{'{{ settings.link-color }}'};
}
@jherax
jherax / filterArray.js
Last active February 23, 2024 12:59
Filters an array of objects with multiple match-criteria.
/**
* Filters an array of objects using custom predicates.
*
* @param {Array} array: the array to filter
* @param {Object} filters: an object with the filter criteria
* @return {Array}
*/
function filterArray(array, filters) {
const filterKeys = Object.keys(filters);
return array.filter(item => {
@benwells
benwells / reduce-example.js
Created May 12, 2016 13:40
Using Array.reduce to sum a property in an array of objects
var accounts = [
{ name: 'James Brown', msgCount: 123 },
{ name: 'Stevie Wonder', msgCount: 22 },
{ name: 'Sly Stone', msgCount: 16 },
{ name: 'Otis Redding', msgCount: 300 } // Otis has the most messages
];
// get sum of msgCount prop across all objects in array
var msgTotal = accounts.reduce(function(prev, cur) {
return prev + cur.msgCount;