sudo apt install zsh-autosuggestions zsh-syntax-highlighting zsh
// Google Apps Script for counting emails by sender in batches. Stopps and resumes after 5mins of processing to avoid reaching script runtime limit. | |
// 1. Allow required permissions | |
// 2. Add gmail service to project | |
// 3. Fill <your-email> in `runProcessor` function and adjust query if needed | |
// 4. Run function `runProcessor` | |
// 5. Result will be saved in a new spreadsheet | |
// Based on ideas from https://stackoverflow.com/a/59222719/5162536 and | |
// https://medium.com/geekculture/bypassing-the-maximum-script-runtime-in-google-apps-script-e510aa9ae6da |
// Execute the "run" function below after setting up the appropriate APIs | |
// Original credit: https://stackoverflow.com/a/59222719/501042 | |
function sender_list_paged(token) { | |
var dt = new Date().getTime(); | |
var ss = SpreadsheetApp.create('Gmail count emails by sender ' + dt); | |
var sh = ss.getActiveSheet() | |
sh.clear(); | |
sh.appendRow(['Email Address', 'Count']); | |
var token = token || null; | |
var query = "in:inbox is:unread"; |
The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.
In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.
This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.