Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Golightly magician11

View GitHub Profile
@magician11
magician11 / circle-geometry.js
Created May 21, 2020
How to calculate a coordinate on a circle
View circle-geometry.js
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 };
};
View keybase.md

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 / 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 / decoder.js
Created Jan 12, 2019
How to edit HTML game files
View decoder.js
/*
This will take a .save game file, decode it into its JSON form,
and then save it to game-data.json
*/
const fs = require('fs');
const LZString = require('lz-string');
if (process.argv.length === 3) {
try {
const encodedData = fs.readFileSync(process.argv[2], 'utf8');
@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 / folder-reset.js
Created Dec 18, 2018
How to recursively delete a directory then re-create it in Nodejs
View folder-reset.js
const fs = require('fs');
const rimraf = require('rimraf');
const tempBackupDirectory = 'backups';
rimraf.sync(tempBackupDirectory);
fs.mkdirSync(tempBackupDirectory);
@magician11
magician11 / ajax.js
Last active Mar 22, 2019
JavaScript object to query string
View ajax.js
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 / get-youtube-subtitles.js
Created Aug 14, 2018
How to extract plain text subtitles from YouTube
View get-youtube-subtitles.js
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 / get-url-params.js
Created Jul 1, 2018
How to get all parameters from a URL as an associative array
View get-url-params.js
export const getURLparams = () => {
const pl = /\+/g;
const search = /([^&=]+)=?([^&]*)/g;
const decode = s => decodeURIComponent(s.replace(pl, ' '));
const query = window.location.search.substring(1);
const urlParams = {};
let match;
while ((match = search.exec(query))) {
urlParams[decode(match[1])] = decode(match[2]);
You can’t perform that action at this time.