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 / robots.txt.njk
Created September 10, 2023 20:33
sitemap.xml and robots.txt for 11ty (Eleventy)
View robots.txt.njk
---
eleventyExcludeFromCollections: true
eleventyComputed:
permalink: "{{ site.robots }}"
---
Sitemap: {{ site.baseUrl + site.siteMap }}
User-agent: *
Disallow:
@magician11
magician11 / elevenlabs.js
Last active August 3, 2023 09:12
Playing audio generated from ElevenLabs in frontend JavaScript
View elevenlabs.js
import axios from 'axios';
const playAudio = async ({ text, voiceId }) => {
const response = await axios.post(
`https://api.elevenlabs.io/v1/text-to-speech/${voiceId}`,
{ text },
{
headers: {
'Content-Type': 'application/json',
'xi-api-key': process.env.REACT_APP_ELEVENLABS_API_KEY
@magician11
magician11 / PasswordInput.js
Created July 19, 2023 16:53
PasswordInput component for react-native-paper
View PasswordInput.js
import { useState } from 'react';
import { TextInput } from 'react-native-paper';
const PasswordInput = ({ password, setPassword }) => {
const [showPassword, setShowPassword] = useState(false);
return (
<TextInput
label="Password"
secureTextEntry={!showPassword}
@magician11
magician11 / expo-audio.js
Last active July 18, 2023 18:15
How to play a base64 encoded audio file in expo-av
View expo-audio.js
import { View } from 'react-native';
import {
cacheDirectory,
writeAsStringAsync,
EncodingType
} from 'expo-file-system';
import { Audio } from 'expo-av';
import { Button } from 'react-native-paper';
import base64AudioEncodedString from './assets/sounds';
@magician11
magician11 / create-subscription.js
Last active July 28, 2022 23:21
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 July 27, 2022 18:19
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 April 18, 2022 20:51
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 March 16, 2022 00:50
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 December 17, 2022 14:36
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

git clone https://github.com/trailofbits/algo.git
  • then run
python3 -m pip install --user --upgrade virtualenv
@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
View install-java.md