Skip to content

Instantly share code, notes, and snippets.

View magician11's full-sized avatar

A magician11

  • Golightly+
  • New Zealand
View GitHub Profile
@magician11
magician11 / listen-for-shopify-webhooks.js
Created November 21, 2016 08:06
How to listen to Shopify webhook event data with Node.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 / react-ga-no-routes.jsx
Last active April 11, 2020 22:02
How to setup the React Google Analytics Module (react-ga) for your react.js app (with no routes).
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 / write-to-firebase.js
Last active June 28, 2022 10:24
Writing data to Firebase from Node.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 / secure-node-server.js
Last active December 15, 2016 04:46
How to add https to your Node.js server
// libraries
const express = require('express');
const https = require('https');
const fs = require('fs');
const cors = require('cors'); // Cross-Origin Resource Sharing
// setup express
const app = express();
app.use(cors());
@magician11
magician11 / regex-with-variables.js
Created March 17, 2017 10:31
How to use variables in regular expressions in JavaScript.
function getURL(startMatch, endMatch, str) {
var regex = new RegExp(startMatch + ': (.+), ' + endMatch);
var contents = str.split(regex)[1];
return contents ? contents : 'none found';
}
var str = 'website: http://www.google.com, soundcloud: http://www.soundcloud.com, facebook: http://www.facebook.com, stage: the main one';
console.log('Website URL:', getURL('website', 'soundcloud', str));
@magician11
magician11 / currency-conversion.html
Last active December 30, 2022 02:57
How To Create Your Own Currency Conversion App
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Currency Conversion</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
@magician11
magician11 / json-over-soap-wrapper.js
Last active December 4, 2018 14:22
How to a JSON API Wrapper for SOAP
const express = require('express');
const https = require('https');
const fs = require('fs');
const cors = require('cors');
const rpn = require('request-promise-native');
const bodyParser = require('body-parser');
/* eslint-disable comma-dangle,arrow-parens,max-len,no-console */
const app = express();
@magician11
magician11 / remove-paypal-gateway.rb
Last active May 18, 2022 07:03
How to remove the PayPal payment gateway in Shopify if a product is tagged with 'no-paypal'.
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 / headless-chrome.js
Last active August 12, 2020 13:03
How to grab the page source from any dynamically generated webpage and then process it .
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 / front-end.js
Last active August 2, 2017 21:36
How To Use jQuery To Post A CSV File To A Node.js Server
// using jQuery
$("#2020data").submit(function(e) {
$.ajax({
url: "https://e0d92634.ngrok.io/test",
type: "POST",
data: new FormData(this),
processData: false,
contentType: false
});