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 / vpn-setup.md
Last active December 17, 2022 14:36
How to setup a static IP for a developer who uses a MacBook

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

git clone https://github.com/trailofbits/algo.git
  • then run
python3 -m pip install --user --upgrade virtualenv
@magician11
magician11 / create-subscription.js
Last active July 28, 2022 23:21
How to fetch all products from Shopify in a single query
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 July 27, 2022 18:19
How to generating a PDF from HTML using JavaScript
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 / 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 / ajax.js
Last active June 21, 2022 00:33
JavaScript object to query string
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',
@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 / firebase-functions.js
Created April 18, 2022 20:51
How to conditionally schedule a Firebase pubsub function depending on the Firebase account
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 / sticky-dropdown.html
Created November 7, 2016 07:33
Creates a sticky dropdown for the Fusion Mega Menu for the Avada WordPress theme.
<script>
// makes the dropdown sticky on hover and removes it on scrolling
jQuery(document).ready(function () {
/*
On hovering over the products button, when the mouse is moved away,
then make the dropdown stick by resetting the attributes to do that
per Avada setup.
*/
jQuery('.shop-main-menu').hover(null, function() {
@magician11
magician11 / DiscordIcon.js
Created March 16, 2022 00:50
Discord icon for Material UI
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 / install-java.md
Last active January 12, 2022 16:00
How to install Java for the Firebase Local Emulator Suite on a Mac