Skip to content

Instantly share code, notes, and snippets.

View mmarchini's full-sized avatar
🛑
taking a break

mary marchini mmarchini

🛑
taking a break
View GitHub Profile
@mmarchini
mmarchini / macros.md
Last active January 1, 2022 05:00
FFXIV Macros

Macros

Music Toggle

Toggles music on/off

/micon "Dance" emote
/bgm
const total = 200000
const batch = 32768
const tokens1 = [], tokens2 = []
const one = () => {
tokens1.push(0);
if (tokens1.length > 0 && tokens2.length > 0) {
tokens1.splice(0, 1);
tokens2.splice(0, 1);
}
@mmarchini
mmarchini / index.md
Last active September 23, 2020 06:08
Node.js Unhandled Rejections context links
@mmarchini
mmarchini / resource-leak-mitigation.js
Created August 10, 2020 21:55
resource-leak-mitigation.js
const http = require('http');
const server = http.createServer(handle);
server.listen(3000);
process.on('unhandledRejection', (err) => {
throw err;
});
function handle (req, res) {
@mmarchini
mmarchini / resource-leak.js
Created August 10, 2020 21:55
resource-leak.js
const http = require('http');
const server = http.createServer(handle);
server.listen(3000);
function handle (req, res) {
doStuff()
.then((body) => {
res.end(body);
});
@mmarchini
mmarchini / unhandled-rejections.js
Created August 10, 2020 21:54
unhandled-rejections.js
async function foo() {
throw new Error();
}
foo() // 1. Unhandled at this point
.catch(() => console.error("an error occured")); // 2. Now it's handled
try {
await foo();
} catch(e) { // 3. Handled
@mmarchini
mmarchini / async-readFile.js
Created August 10, 2020 21:54
async-readFile.js
// async function version
const { readFile } = require('fs').promises;
async function readJsonFile(file) {
// Promise is rejected if fails to read or if unexpected JSON input.
return JSON.parse(await readFile(file));
}
@mmarchini
mmarchini / callback-readFile.js
Created August 10, 2020 21:53
callback-readFile.js
// Callback version
const { readFile } = require('fs');
function readJsonFile(file, cb) {
readFile(file, (err, data) => {
if (err) {
// If error while reading file, propagate the error via callback
return cb(err, null);
}
// Unexpected invalid JSON input, code will throw
@mmarchini
mmarchini / promise-rejections.js
Created August 10, 2020 21:53
promise-rejections.js
Promise.reject(new Error()); // This will result in a rejection
new Promise((fulfill, reject) => {
reject(new Error()); // This will result in a rejection
});
new Promise(() => {
throw new Error(); // This will result in a rejection
});
new Promise
console.log