Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew magician11

View GitHub Profile
@magician11
magician11 / create-subscription.js
Last active Jul 28, 2022
How to fetch all products from Shopify in a single query
View create-subscription.js
const setup = async () => {
const data = `
mutation {
webhookSubscriptionCreate(
topic: BULK_OPERATIONS_FINISH
webhookSubscription: {
format: JSON,
callbackUrl: "https://firebase-app.cloudfunctions.net/processAllProducts"}
) {
userErrors {
@magician11
magician11 / htmlToPdf.js
Last active Jul 27, 2022
How to generating a PDF from HTML using JavaScript
View htmlToPdf.js
const puppeteer = require('puppeteer');
const htmlToPdf = async html => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// https://pptr.dev/#?product=Puppeteer&version=v13.6.0&show=api-pagesetcontenthtml-options
await page.setContent(html);
// https://pptr.dev/#?product=Puppeteer&version=v13.6.0&show=api-pagepdfoptions
const buffer = await page.pdf({
format: 'A4',
@magician11
magician11 / firebase-functions.js
Created Apr 18, 2022
How to conditionally schedule a Firebase pubsub function depending on the Firebase account
View firebase-functions.js
const productionFirebaseAccount = 'production-firebase-account';
if (process.env.GCLOUD_PROJECT === productionFirebaseAccount) {
exports.generateInvoices = functions.pubsub
.schedule('0 15 * * 5') // every Friday at 3pm PST
.timeZone('America/Vancouver')
.onRun(async context => {
const generateInvoices = require('./reports/generateInvoices');
await generateInvoices();
});
@magician11
magician11 / DiscordIcon.js
Created Mar 16, 2022
Discord icon for Material UI
View DiscordIcon.js
import { SvgIcon } from '@mui/material';
const DiscordIcon = props => {
return (
<SvgIcon {...props}>
<path d="M19.2774 5.01386C17.9389 4.37206 16.5036 3.89921 15.0029 3.62839C14.9756 3.62317 14.9483 3.63623 14.9342 3.66235C14.7496 4.00545 14.5451 4.45304 14.402 4.80485C12.7879 4.55232 11.182 4.55232 9.60103 4.80485C9.45782 4.44522 9.24592 4.00545 9.0605 3.66235C9.04642 3.6371 9.01912 3.62404 8.99179 3.62839C7.49192 3.89835 6.05662 4.3712 4.71732 5.01386C4.70572 5.01908 4.69579 5.0278 4.68919 5.03911C1.96672 9.28954 1.22092 13.4355 1.58678 17.5301C1.58844 17.5501 1.5992 17.5693 1.6141 17.5814C3.41031 18.9599 5.15024 19.7968 6.85787 20.3515C6.8852 20.3602 6.91415 20.3497 6.93155 20.3262C7.33549 19.7498 7.69556 19.1419 8.00429 18.5027C8.02251 18.4653 8.00512 18.4209 7.96788 18.4061C7.39674 18.1797 6.8529 17.9036 6.32976 17.5902C6.28838 17.5649 6.28507 17.503 6.32314 17.4734C6.43323 17.3872 6.54334 17.2975 6.64846 17.207C6.66748 17.1904 6.69398 17.1869 6.71634 17.1974C10.1531 18.8371 13.8739 18.8371
@magician11
magician11 / vpn-setup.md
Last active Jul 4, 2022
How to setup a static IP for a developer who uses a MacBook
View vpn-setup.md

We're going to setup a personal WireGuard and IPsec VPN on DigitalOcean, from a Mac

  • Make sure you have a DigitalOcean account first
  • get algo git clone https://github.com/trailofbits/algo.git
  • then run python3 -m pip install --user --upgrade virtualenv
  • then run python3 -m virtualenv --python="$(command -v python3)" .env && source .env/bin/activate && python3 -m pip install -U pip virtualenv && python3 -m pip install -r requirements.txt
  • open ./config.cfg and add your list of users
@magician11
magician11 / install-java.md
Last active Jan 12, 2022
How to install Java for the Firebase Local Emulator Suite on a Mac
View install-java.md
@magician11
magician11 / registerForPushNotificationsAsync.js
Last active Nov 23, 2020
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.
View registerForPushNotificationsAsync.js
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 / 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 };
};
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 / 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({