Navigation Menu

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 / install-java.md
Last active January 12, 2022 16:00
How to install Java for the Firebase Local Emulator Suite on a Mac
@magician11
magician11 / registerForPushNotificationsAsync.js
Last active November 23, 2020 23:50
Register a device for push notifications using expo-notifications and returning the Expo Push Token. Then send a push notification using the Expo Push Token.
import Constants from 'expo-constants';
import * as Notifications from 'expo-notifications';
import * as Permissions from 'expo-permissions';
const registerForPushNotificationsAsync = async () => {
let token;
if (Constants.isDevice) {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
@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 };
};

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 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 / decoder.js
Created January 12, 2019 19:44
How to edit HTML game files
/*
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 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 / 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 / ajax.js
Last active June 21, 2022 00:33
JavaScript object to query string
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',