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 / registerForPushNotificationsAsync.js
Last active November 23, 2020 23:50
Register a device for push notifications using expo-notifications and returning the Expo Push Token. Then send a push notification using the Expo Push Token.
import Constants from 'expo-constants';
import * as Notifications from 'expo-notifications';
import * as Permissions from 'expo-permissions';
const registerForPushNotificationsAsync = async () => {
let token;
if (Constants.isDevice) {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
@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 / circle-geometry.js
Created May 21, 2020 07:05
How to calculate a coordinate on a circle
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 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 / tweetnacl-test.js
Last active January 8, 2020 21:27
How to encrypt and decrypt a message with TweetNaCl.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)}`);

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 / freshbooks-classic.js
Last active July 12, 2019 11:49
How to call Freshbooks Classic directly in Node.js using axios
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 / supportedLanguages.js
Created December 28, 2018 00:41
Google Cloud Speech-to-Text API Language Support as a JavaScript array
export default [
['Afrikaans (Suid-Afrika)', 'af-ZA'],
['አማርኛ (ኢትዮጵያ)', 'am-ET'],
['Հայ (Հայաստան)', 'hy-AM'],
['Azərbaycan (Azərbaycan)', 'az-AZ'],
['Bahasa Indonesia (Indonesia)', 'id-ID'],
['Bahasa Melayu (Malaysia)', 'ms-MY'],
['বাংলা (বাংলাদেশ)', 'bn-BD'],
['বাংলা (ভারত)', 'bn-IN'],
['Català (Espanya)', 'ca-ES'],
@magician11
magician11 / remove-duplicates.js
Last active December 28, 2018 00:04
How to remove duplicates in a csv field
const removeDuplicates = csvStr => [...new Set(csvStr.split(',').map(tag => tag.trim()))].join(', ');