Skip to content

Instantly share code, notes, and snippets.

View magician11's full-sized avatar

A magician11

  • Golightly+
  • New Zealand
View GitHub Profile
@tomhicks
tomhicks / plink-plonk.js
Last active March 18, 2024 02:23
Listen to your web pages
@BjornDCode
BjornDCode / gist:5cb836a6b23638d6d02f5cb6ed59a04a
Created February 3, 2020 11:58
Tailwind - Fixed sidebar, scrollable content
// Source: https://twitter.com/calebporzio/status/1151876736931549185
<div class="flex">
<aside class="h-screen sticky top-0">
// Fixed Sidebar
</aside>
<main>
// Content
</main>
@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(', ');
@magician11
magician11 / nodejs-cron.js
Last active May 1, 2018 17:50
How to get a Node.js function to run once on the last day of each month
const moment = require('moment');
const someAction = () => console.log('Actioning...');
const wait = ms => new Promise((resolve, reject) => setTimeout(resolve, ms));
const startCron = async () => {
while (true) {
if (
moment().date() ===
@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)}`);
@magician11
magician11 / my-domain.com.conf
Last active January 19, 2018 19:42
How to add pre and post hooks for Certbot automatic renewals running Nginx
# renew_before_expiry = 30 days
version = 0.19.0
archive_dir = /etc/letsencrypt/archive/my-domain.com
cert = /etc/letsencrypt/live/my-domain.com/cert.pem
privkey = /etc/letsencrypt/live/my-domain.com/privkey.pem
chain = /etc/letsencrypt/live/my-domain.com/chain.pem
fullchain = /etc/letsencrypt/live/my-domain.com/fullchain.pem
# Options used in the renewal process
[renewalparams]
@magician11
magician11 / config.js
Last active December 2, 2017 14:03
How to send an email from Node.js using Gmail
module.exports = {
email: {
address: 'youraddress@gmail.com',
password: 'clever-password'
}
};
@ipepe
ipepe / install-chrome-headless.sh
Last active April 19, 2024 07:15
Installing headless chrome on Ubuntu.
#!/bin/bash
# from https://chromium.woolyss.com/
# and https://gist.github.com/addyosmani/5336747
# and https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:canonical-chromium-builds/stage
sudo apt-get update
sudo apt-get install chromium-browser
chromium-browser --headless --no-sandbox http://example.org/