Skip to content

Instantly share code, notes, and snippets.

View crates's full-sized avatar
❤️‍🔥
Crates is CEO of llnnll.com, Athames.com, Crates.Media / Cr8s.Net : 844-CR8S-NET

Crates McDade crates

❤️‍🔥
Crates is CEO of llnnll.com, Athames.com, Crates.Media / Cr8s.Net : 844-CR8S-NET
View GitHub Profile
@crates
crates / ocean_wp-breadcrumbs-938.php
Created August 7, 2019 15:17
Fix for Ocean WP theme breadcrumbs bug
<?php
$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_day_link( get_the_time( 'Y' ), get_the_time( 'm' ), get_the_time( 'd' ) ) ), $day );
?>
@crates
crates / filterViaSpam.js
Last active May 30, 2024 19:48
Filter out "via" spam from Gmail (using script.google.com)
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();
@crates
crates / jsbin.banekiq.js
Last active February 27, 2021 18:27
Entombed maze generator // source: https://jsbin.com/banekiq
// 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!
@crates
crates / JSON-Parse.js
Created January 13, 2020 15:46
Polyfill for JSON.Parse
// 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;
@crates
crates / jQuery-queryStr.js
Created January 13, 2020 15:47
jQuery prototype to parse URL query strings
(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, " "));
@crates
crates / String-Truncate-Trim.js
Created January 13, 2020 16:00
String truncation and trim methods
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);
@crates
crates / leetcode-nim-game.js
Created January 23, 2020 17:24
Can I win a Nim Game? (LeetCode Interview Question)
/**
* @param {number} n
* @return {boolean}
*/
var canWinNim = function(n) {
if (n % 4 === 0) return false;
return true;
};
@crates
crates / leetcode-hamming-distance.js
Created January 23, 2020 17:27
Calculate the Hamming Distance between two integers (LeetCode Question)
/**
* @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) {
@crates
crates / leetcode-lfu-cache.js
Last active January 23, 2020 22:02
Least Frequently Used Cache (LFU) in JavaScript - LeetCode Interview Question
// 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;
@crates
crates / leetcode-super-washing-machines.js
Created January 23, 2020 22:25
Find the minimum number of moves to make all washing machines have the same number of dresses (LeetCode)
// 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}
*/