Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Golightly magician11

View GitHub Profile
@magician11
magician11 / listen-for-shopify-webhooks.js
Created Nov 21, 2016
How to listen to Shopify webhook event data with Node.js
View listen-for-shopify-webhooks.js
/* eslint-disable no-console */
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
/*
Shopify issues a HTTP POST request.
- https://help.shopify.com/api/tutorials/webhooks#receive-webhook
@magician11
magician11 / headless-chrome.js
Last active Aug 12, 2020
How to grab the page source from any dynamically generated webpage and then process it .
View headless-chrome.js
const CDP = require('chrome-remote-interface');
const chromeLauncher = require('chrome-launcher');
const cheerio = require('cheerio');
(async function() {
const launchChrome = () =>
chromeLauncher.launch({ chromeFlags: ['--disable-gpu', '--headless'] });
const chrome = await launchChrome();
const protocol = await CDP({ port: chrome.port });
@magician11
magician11 / circle-geometry.js
Created May 21, 2020
How to calculate a coordinate on a circle
View circle-geometry.js
const degreesToRadians = degrees => (degrees * Math.PI) / 180;
const pointOnCircle = (radius, radians, origin) => {
const x = origin.x + Math.cos(radians) * radius;
const y = origin.y + Math.sin(radians) * radius;
return { x, y };
};
@magician11
magician11 / react-ga-no-routes.jsx
Last active Apr 11, 2020
How to setup the React Google Analytics Module (react-ga) for your react.js app (with no routes).
View react-ga-no-routes.jsx
import ReactGA from 'react-ga'; // https://github.com/react-ga/react-ga
import { React, Component } from 'react';
class MyApp extends Component {
constructor() {
super();
this.state = {
someData: null,
};
@magician11
magician11 / tweetnacl-test.js
Last active Jan 8, 2020
How to encrypt and decrypt a message with TweetNaCl.js
View tweetnacl-test.js
const tweetnacl = require('tweetnacl'); // https://github.com/dchest/tweetnacl-js
tweetnacl.util = require('tweetnacl-util'); // https://github.com/dchest/tweetnacl-util-js
// utility function to display the Uint8Array
const asciiArmored = arr => tweetnacl.util.encodeBase64(arr);
// generate the key to encrypt a message
const secretKey = tweetnacl.randomBytes(32);
console.log(`secret key: ${asciiArmored(secretKey)}`);
View keybase.md

Keybase proof

I hereby claim:

  • I am magician11 on github.
  • I am magician11 (https://keybase.io/magician11) on keybase.
  • I have a public key ASDAs5s_X7XJx9A-ia8YhkFeP9nQ9sVrhFxmDNKLCgD5gQo

To claim this, I am signing this object:

@magician11
magician11 / remove-paypal-gateway.rb
Last active Sep 13, 2019
How to remove the PayPal payment gateway in Shopify if a product is tagged with 'no-paypal'.
View remove-paypal-gateway.rb
has_no_paypal_tag = Input.cart.line_items.any? { |line_item| line_item.variant.product.tags.include?('no-paypal') }
if has_no_paypal_tag
Output.payment_gateways = Input.payment_gateways.delete_if { |payment_gateway| payment_gateway.name.include?("PayPal") }
else
Output.payment_gateways = Input.payment_gateways
end
@magician11
magician11 / freshbooks-classic.js
Last active Jul 12, 2019
How to call Freshbooks Classic directly in Node.js using axios
View freshbooks-classic.js
const axios = require("axios");
const config = require("../security/auth.js");
const callFreshbooks = async (
xml,
apiUrl = config.freshbooks.url,
authToken = config.freshbooks.token
) => {
try {
const response = await axios({
@magician11
magician11 / write-to-firebase.js
Last active May 14, 2019
Writing data to Firebase from Node.js
View write-to-firebase.js
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.cert('./movies-387bf-firebase-adminsdk-4hoi8-c52699119b.json'),
databaseURL: 'https://movies-387bf.firebaseio.com',
});
// Get a database reference to our blog
const db = admin.database();
@magician11
magician11 / ajax.js
Last active Mar 22, 2019
JavaScript object to query string
View ajax.js
const queryParameters = {
actions: 'all',
actions_entities: 'true',
actions_display: 'true',
actions_format: 'list',
actions_limit: '1000',
action_fields: 'all',
action_member: 'true',
action_member_fields: 'all',
action_memberCreator: 'true',
You can’t perform that action at this time.