Skip to content

Instantly share code, notes, and snippets.

Andrew Golightly magician11

Block or report user

Report or block magician11

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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({
@magician11
magician11 / supportedLanguages.js
Created Dec 28, 2018
Google Cloud Speech-to-Text API Language Support as a JavaScript array
View supportedLanguages.js
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 Dec 28, 2018
How to remove duplicates in a csv field
View remove-duplicates.js
const removeDuplicates = csvStr => [...new Set(csvStr.split(',').map(tag => tag.trim()))].join(', ');
@magician11
magician11 / nodejs-cron.js
Last active May 1, 2018
How to get a Node.js function to run once on the last day of each month
View nodejs-cron.js
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 Apr 14, 2018
How to encrypt and decrypt a message with TweetNaCl.js
View tweetnacl-test.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 Jan 19, 2018
How to add pre and post hooks for Certbot automatic renewals running Nginx
View my-domain.com.conf
# 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 Dec 2, 2017
How to send an email from Node.js using Gmail
View config.js
module.exports = {
email: {
address: 'youraddress@gmail.com',
password: 'clever-password'
}
};
@ipepe
ipepe / install-chrome-headless.sh
Last active Oct 10, 2019
Installing headless chrome on Ubuntu.
View install-chrome-headless.sh
#!/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/
@magician11
magician11 / front-end.js
Last active Aug 2, 2017
How To Use jQuery To Post A CSV File To A Node.js Server
View front-end.js
// using jQuery
$("#2020data").submit(function(e) {
$.ajax({
url: "https://e0d92634.ngrok.io/test",
type: "POST",
data: new FormData(this),
processData: false,
contentType: false
});
@magician11
magician11 / headless-chrome.js
Last active Jun 8, 2018
How to grab the page source from any dynamically generated webpage and then process it .
View headless-chrome.js
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 });
You can’t perform that action at this time.