Skip to content

Instantly share code, notes, and snippets.

function gmailAutoarchive() {
const delayDays = 2;
const batchSize = 100;
const maxDate = new Date();
maxDate.setDate(maxDate.getDate() - delayDays);
const threads = GmailApp.search(`in:inbox has:userlabels older_than:${delayDays}d`).filter((thread) => thread.getLastMessageDate() < maxDate);
if (threads.length) {
const PostGIS = {
// FUNCTIONS
gisContains: {
description: "Returns TRUE if and only if no points of supplied lie in the exterior of field, and at least one point of the interior of supplied lies in the interior of field.",
fname: "ST_Contains",
},
gisContainsProperly: {
description: "Returns TRUE if supplied intersects the interior of field but not the boundary (or exterior). Field does not contain properly itself, but does contain itself.",
fname: "ST_ContainsProperly",
},
@Rycochet
Rycochet / getHeight.ts
Created August 15, 2017 11:12
Get the height of the display, based on body - then on the lowest element within the body
/**
* Get the height of the display, based on body height, then the lowest element within it
*/
function getHeight(): number {
var i = 0,
body = document.body,
style = body.style,
elements = document.querySelectorAll("body *"),
best = body.offsetHeight + (parseInt(style.marginTop, 10) || 0) + (parseInt(style.marginBottom, 10) || 0);;
@Rycochet
Rycochet / exceljs.d.ts
Last active October 19, 2023 09:22
Typescript definitions for ExcelJS
/*
* Type definitions for ExcelJS
* Project: https://github.com/guyonroche/exceljs
* Definitions by: Rycochet https://github.com/Rycochet
*
* This is a WIP
*/
declare namespace ExcelJS {
type Zip = any;
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
@Rycochet
Rycochet / offsetParent.js
Created January 27, 2017 11:41
offsetParent polyfill
if (!("offsetParent" in document.body)) {
Object.defineProperty(HTMLElement.prototype, "offsetParent", {
"get": function() {
var element = this,
parent = element.parentElement,
html = document.documentElement,
found = null,
style = window.getComputedStyle(element);
if (element && style.position !== "fixed") {
@Rycochet
Rycochet / getQuery.js
Last active June 16, 2016 09:38
Parse (and cache) the query string and return the requested search value
function getQuery(search) {
if (!getQuery.parsed) {
var match, key, value,
rx = /([^=&]+)(?:=([^&]*))?/g,
parsed = getQuery.parsed = {};
while ((match = rx.exec(document.location.search.substring(1)))) {
key = decodeURIComponent(match[1]);
value = match[2] === undefined ? true : decodeURIComponent(match[2]);
if (parsed.hasOwnProperty(key)) {
@Rycochet
Rycochet / get_real_post.php
Created February 3, 2016 16:27
Gets the PHP _POST (or _GET) data with correct handling of nested brackets
/**
* Gets the _POST data with correct handling of nested brackets:
* "path[to][data[nested]]=value"
* "path"
* -> "to"
* -> "data[nested]" = value
* @return array
*/
function get_real_post() {
@Rycochet
Rycochet / strnatcasecmp.js
Created May 20, 2015 14:03
Compare two strings accounting for multi-digit numbers
/**
* Compare two strings accounting for multi-digit numbers
* @param {(string|number)} a First string to compare
* @param {(string|number)} b Second string to compare
* @return {number} 0 if they match, -1 if a comes before b, +1 if b comes before a
*/
function strnatcasecmp(a, b) {
a = ("" + a).toLowerCase();
b = ("" + b).toLowerCase();
@Rycochet
Rycochet / debounce.js
Created March 6, 2015 13:57
Javascript debounce shim
/**
* Make sure that we can't accidentally iterate over custom methods
* @param {Object} proto
* @param {string} fName
* @param {function(?)} fn
*/
function defineProperty(proto, fName, fn) {
if (!proto[fName]) {
proto[fName] = fn;
(Object.defineProperty || $.noop)(proto, fName, {"enumerable": false});