❤️🔥
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processMessages(thread, label, search) { | |
var messages = thread.getMessages(); | |
for (var j = 0; j < messages.length; j++) { | |
var message = messages[j]; | |
var body = message.getRawContent(); | |
if (typeof search === 'string') { // used for single-string searches: | |
if (body.indexOf(search) > -1) { | |
thread.addLabel(label).markRead().markUnimportant().moveToArchive(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Entombed maze generator | |
// More info at https://www.semanticscholar.org/paper/Entombed%3A-An-archaeological-examination-of-an-Atari-Aycock-Copplestone/fc18c3f88be41e4102654c1d883b907d7bfae6d2 | |
// Written by reddit.com/user/JaggedMetalOs | |
// Here's what I'd like to see added: (Crates) | |
// * There must be at least one valid path from start to exit | |
// * Areas that are completely enclosed should have no openings inside | |
// * Avoid shorter paths that go less far, in favor of longer, meandering ones | |
// * It would be cool to see an AI that can generate complex mazes! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// POLYFILL FOR JSON.PARSE IN UNSUPP BROWSERS: | |
if (!window.JSON) { | |
window.JSON = { | |
parse: function(sJSON) { return eval('(' + sJSON + ')'); }, | |
stringify: (function () { | |
var toString = Object.prototype.toString; | |
var isArray = Array.isArray || function (a) { return toString.call(a) === '[object Array]'; }; | |
var escMap = {'"': '\\"', '\\': '\\\\', '\b': '\\b', '\f': '\\f', '\n': '\\n', '\r': '\\r', '\t': '\\t'}; | |
var escFunc = function (m) { return escMap[m] || '\\u' + (m.charCodeAt(0) + 0x10000).toString(16).substr(1); }; | |
var escRE = /[\\"\u0000-\u001F\u2028\u2029]/g; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { // Prototypes a function to parse URL query strings: | |
$.QueryString = (function(a) { | |
if (a === "") return {}; | |
var b = {}; | |
for (var i = 0; i < a.length; ++i) | |
{ | |
var p=a[i].split('='); | |
if (p.length !== 2) continue; | |
try { | |
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof String.prototype.trimAll !== 'function') { | |
String.prototype.trimAll = function() { /* Trim all whitespace from strings: */ | |
var sString = this; | |
if (typeof(sString) === 'undefined' || (!sString)) return ''; | |
while(sString.substring(0,1) == ' ' || | |
sString.substring(0,1) == '\r' || | |
sString.substring(0,1) == '\n') { | |
sString = sString.substring(1, sString.length); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} n | |
* @return {boolean} | |
*/ | |
var canWinNim = function(n) { | |
if (n % 4 === 0) return false; | |
return true; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} x | |
* @param {number} y | |
* @return {number} | |
*/ | |
const hammingDistance = function(x, y) { | |
let distance = 0; | |
let xor = x ^ y; // bitwise operation calculates the xor | |
while (xor > 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Designed to solve this LeetCode problem: https://leetcode.com/problems/lfu-cache/ | |
// Author: Crates McD (https://cr8s.net) | |
// Runtime: 420 ms, faster than 8.00% of JavaScript online submissions for LFU Cache. | |
// Memory Usage: 60.2 MB, less than 100.00% of JavaScript online submissions for LFU Cache. | |
/** | |
* @param {any} comparator | |
* @return {boolean} | |
*/ | |
const isNull = comparator => comparator == null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Designed to solve this LeetCode problem: https://leetcode.com/problems/super-washing-machines/ | |
// Author: Crates McD (https://cr8s.net) | |
// Runtime: 52 ms, faster than 100.00% of JavaScript online submissions for Super Washing Machines. | |
// Memory Usage: 35 MB, less than 100.00% of JavaScript online submissions for Super Washing Machines. | |
// Time complexity: O(n); space complexity: O(1) | |
/** | |
* @param {number[]} machines | |
* @return {number} | |
*/ |