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 / get-youtube-subtitles.js
Created August 14, 2018 17:12
How to extract plain text subtitles from YouTube
const { getSubtitles } = require('youtube-captions-scraper');
const getYouTubeID = require('get-youtube-id');
const getYouTubeSubtitles = async youtubeUrl => {
try {
const videoID = getYouTubeID(youtubeUrl);
const subtitles = await getSubtitles({ videoID });
return subtitles.reduce(
(accumulator, currentSubtitle) =>
`${accumulator} ${currentSubtitle.text}`,
@magician11
magician11 / json-over-soap-wrapper.js
Last active December 4, 2018 14:22
How to a JSON API Wrapper for SOAP
const express = require('express');
const https = require('https');
const fs = require('fs');
const cors = require('cors');
const rpn = require('request-promise-native');
const bodyParser = require('body-parser');
/* eslint-disable comma-dangle,arrow-parens,max-len,no-console */
const app = express();
@magician11
magician11 / folder-reset.js
Created December 18, 2018 03:30
How to recursively delete a directory then re-create it in Nodejs
const fs = require('fs');
const rimraf = require('rimraf');
const tempBackupDirectory = 'backups';
rimraf.sync(tempBackupDirectory);
fs.mkdirSync(tempBackupDirectory);
@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 / 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 / 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({

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 / 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 / react-ga-no-routes.jsx
Last active April 11, 2020 22:02
How to setup the React Google Analytics Module (react-ga) for your react.js app (with no routes).
import ReactGA from 'react-ga'; // https://github.com/react-ga/react-ga
import { React, Component } from 'react';
class MyApp extends Component {
constructor() {
super();
this.state = {
someData: null,
};
@magician11
magician11 / circle-geometry.js
Created May 21, 2020 07:05
How to calculate a coordinate on a circle
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 };
};