Skip to content

Instantly share code, notes, and snippets.

@Danktuary
Danktuary / index.js
Last active May 13, 2022 09:43
Raw event reaction add example
const { Client } = require('discord.js');
const client = new Client();
client.on('ready', () => {
console.log('Ready!');
});
const events = {
MESSAGE_REACTION_ADD: 'messageReactionAdd',
MESSAGE_REACTION_REMOVE: 'messageReactionRemove',
@anaisbetts
anaisbetts / stat-cache.js
Last active April 11, 2019 05:07
Make your Electron apps load faster, with this One Weird Trick
// Include this at the very top of both your main and window processes, so that
// it loads as soon as possible.
//
// Why does this work? The node.js module system calls fs.realpathSync a _lot_
// to load stuff, which in turn, has to call fs.lstatSync a _lot_. While you
// generally can't cache stat() results because they change behind your back
// (i.e. another program opens a file, then you stat it, the stats change),
// caching it for a very short period of time is :ok: :gem:. These effects are
// especially apparent on Windows, where stat() is far more expensive - stat()
// calls often take more time in the perf graph than actually evaluating the
@JordanDelcros
JordanDelcros / combine-rgba-colors.js
Created July 31, 2015 09:55
Combine two RGBA colors with JavaScript
// Fast and easy way to combine (additive mode) two RGBA colors with JavaScript.
// [red, green, blue, alpha] based on these maximul values [255, 255, 255, 1].
var base = [69, 109, 160, 1];
var added = [61, 47, 82, 0.8];
var mix = [];
mix[3] = 1 - (1 - added[3]) * (1 - base[3]); // alpha
mix[0] = Math.round((added[0] * added[3] / mix[3]) + (base[0] * base[3] * (1 - added[3]) / mix[3])); // red
mix[1] = Math.round((added[1] * added[3] / mix[3]) + (base[1] * base[3] * (1 - added[3]) / mix[3])); // green
mix[2] = Math.round((added[2] * added[3] / mix[3]) + (base[2] * base[3] * (1 - added[3]) / mix[3])); // blue