389 karma · joined March 7, 2012
function autoExtractGmailMedia() { const START_TIME = Date.now(); const TIME_LIMIT = 1000 * 60 * 5; // 5 minutes (leaves a 1-minute safety buffer) const BATCH_SIZE = 50; const FOLDER_NAME = "Gmail_Media_Export";
// 1. Retrieve our current position from the script's property store
const scriptProperties = PropertiesService.getScriptProperties();
let startIndex = parseInt(scriptProperties.getProperty('START_INDEX')) || 0;
// Locate or create the destination folder
let folder;
const folders = DriveApp.getFoldersByName(FOLDER_NAME);
if (folders.hasNext()) {
folder = folders.next();
} else {
folder = DriveApp.createFolder(FOLDER_NAME);
}
// 2. Process batches in a loop
// Updated search query to ignore USPS and non-primary tabs
const searchQuery = 'has:attachment -from:usps.gov -category:promotions -category:updates -category:social (filename:jpg OR filename:jpeg OR filename:png OR filename:zip)';
while (true) {
const threads = GmailApp.search(searchQuery, startIndex, BATCH_SIZE);
// If the search returns empty, we've hit the end of the inbox
if (threads.length === 0) {
console.log("Extraction completely finished.");
scriptProperties.deleteProperty('START_INDEX');
deleteTriggers(); // Clean up so it doesn't keep running
return;
}
for (let i = 0; i < threads.length; i++) {
const messages = threads[i].getMessages();
for (let j = 0; j < messages.length; j++) {
const attachments = messages[j].getAttachments();
for (let k = 0; k < attachments.length; k++) {
const attachment = attachments[k];
const name = attachment.getName().toLowerCase();
const type = attachment.getContentType();
const size = attachment.getSize();
// Apply size threshold (102,400 bytes = 100KB) and file type filter
if (size > 102400) {
if (type.includes('image/') || name.endsWith('.zip')) {
folder.createFile(attachment);
}
}
}
}
}
// Increment our starting index for the next batch
startIndex += BATCH_SIZE;
// 3. The Stopwatch Check
if (Date.now() - START_TIME > TIME_LIMIT) {
console.log(`Approaching timeout at index ${startIndex}. Saving state and passing the baton...`);
scriptProperties.setProperty('START_INDEX', startIndex.toString());
scheduleNextRun();
return; // Exit to avoid the hard timeout exception
}
}
}function scheduleNextRun() { deleteTriggers(); // Prevent duplicate overlapping triggers ScriptApp.newTrigger("autoExtractGmailMedia") .timeBased() .after(60 * 1000) // Fire a new execution 1 minute from now .create(); }
function deleteTriggers() { const triggers = ScriptApp.getProjectTriggers(); for (let i = 0; i < triggers.length; i++) { if (triggers[i].getHandlerFunction() === "autoExtractGmailMedia") { ScriptApp.deleteTrigger(triggers[i]); } } }
For some reason it didn't get appended to the podcast descriptions
Hopefully this will usher in some 'common sense' engineering at Ford and other manufacturers and get them back to sane and serviceable designs.
It was a cool little slice of history to see!
Things get trickier with software as well - with many engineering disciplines, the public can be placed in harm's way by the malpractice of engineering - that's why many civil firms require PE's. In other areas, it's less desirable - for defense contractors, many purposely avoid PE's due to our ethical obligations around harming the public.
Surrounding software, I think a major part of it is just that the laws haven't caught up with the times. NCEES now has a Software PE available but no clue about the contents of the exam. It seems like a tricky one to test for.
Elimination of the hazards is impractical, so minimization of risk exposure and frequency is the best that can practically be done.
All the hubbub about stopping new pipeline construction means that more incident prone methods are used - be it trucking, rail transportation, or use of 50+ year old pipelines. The new lines are better engineered, understood, and have more stringent operational controls in place. I've worked on pipelines from the 1940's that are still safely operated, and lines from the 2010's that have already self excavated. These things can be controlled with the right engineering, organizational, and governmental oversight.
New pipelines (especially ones considered DOT regulated in the US, overseen by PHMSA) typically are installed with automatic block valves and flow level leak detection systems. Those combined with a sensible internal and external corrosion control program can push the life of a pipeline without incident out past the useful life of the pipeline. But retrofitting these is expensive and most pipeline operators won't do it without regulatory or other political pressure.
The radiation plume under Hanford is not as terrible as certain sources make it to be, the same with the contamination of the river. The area around the reservation itself has led to a recovered and strong population of many endangered indigenous animals in the area as well.
Regarding Rocky Flats, again, not as terrible as many make it out to be. Once you factor in living at high elevation there's not a huge increase in overall exposure.
An important consideration that comes into this is that most of these were weapons production facilities (dealing with purifying and handling some of the nastiest material around).
The waste from properly designed and operated power reactors is a much cleaner and much easier to contain process. Condemning an entire avenue of clean energy (most of the fuel needs for a century+ which have already been extracted and refined) because the work done on the technology in the 40's-60's (when we were still figuring out how awful some of the waste is), is not conducive to progress.
Source: Field engineering on projects at Hanford, Rocky Flats, and Yucca Mountain
I personally think this is due to the infantilization in part of a lot of media outlets, where the emphasis has been placed on getting the ideas into the most hands possible instead of folks who'd actually benefit. Focusing the faires around 3D printing geegaws and cosplay items is fine if you want to make numbers, but you get consumers and the followons, and not creators from that.
You can think of it in the same vein as Marvel movies or Harry Potter books - low content, low thinking media that raises insane amounts of money based on appealing to the mass market and the wannabe 'geek' crowd that doesn't tend to do much innovating except in consumption methods.