Skip to content

Instantly share code, notes, and snippets.

@TheGreatGaspy
TheGreatGaspy / download-file.js
Created March 30, 2024 21:04 — forked from javilobo8/download-file.js
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@TheGreatGaspy
TheGreatGaspy / object-watch.js
Created March 30, 2024 21:02 — forked from eligrey/object-watch.js
object.watch polyfill in ES5
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@TheGreatGaspy
TheGreatGaspy / better-nodejs-require-paths.md
Created March 30, 2024 20:55 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@TheGreatGaspy
TheGreatGaspy / grab links.bookmarklet
Created March 30, 2024 20:37 — forked from ttscoff/grab links.bookmarklet
Create a bookmark and paste the code from `grab links.bookmarklet` into the url. Trigger it on a page containing links you want to save and then click the section of the page containing the links. A Markdown list of all links will be generated, and clicking the resulting list will select all for copying.
@TheGreatGaspy
TheGreatGaspy / README.md
Created December 25, 2023 03:00 — forked from brainysmurf/README.md
Named parameters, required parameters, and interfaces

Interfaces in Javascript for Google Apps Scripts

I really like named parameters. I can live without them, but there is one place where I really need them. Cases in which I want to create a class and the paramters are guaranteed to be present, nothing extra. This is one way of implementing them. (It's kinda ugly, but kinda cool.)

Project Key

Either copy into your project, or use as a library: MWzXfEDYTWuJ_Xj0ap9H8-68b30WIDiE_

Wrong behaviour

@TheGreatGaspy
TheGreatGaspy / submit.md
Created September 24, 2023 13:04 — forked from tanaikech/submit.md
Retrieve Difference Between 2 Dimensional Arrays using Google Apps Script

Retrieve Difference Between 2 Dimensional Arrays using Google Apps Script

This sample script retrieves the difference elements between 2 dimensional arrays using Google Apps Script. In Google Apps Script, 2 dimensional arrays are often used at Google Docs and Google APIs. And from my recent report, it has already found that the process cost of filter() is the lowest in the other loop methods. So I use the script like this.

var ar1 = [["a1", "b1", "c1"], ["a2", "b2", "c2"], ["a3", "b3", "c3"], ["a4", "b4", "c4"], ["a5", "b5", "c5"]];
var ar2 = [["a2", "b2", "c2"], ["a5", "b5", "c5"], ["a1", "b2", "c3"]];

var res = ar1.filter(function(e) {return ar2.filter(function(f) {return e.toString() == f.toString()}).length == 0});

Logger.log(res); // [["a1","b1","c1"],["a3","b3","c3"],["a4","b4","c4"]]
@TheGreatGaspy
TheGreatGaspy / submit.md
Created September 24, 2023 13:03 — forked from tanaikech/submit.md
Putting All Response Values from Google Form to Google Spreadsheet using Google Apps Script

Putting All Response Values from Google Form to Google Spreadsheet using Google Apps Script

This is a sample script for putting all response values from Google Form to Google Spreadsheet using Google Apps Script.

Sample script

Please copy and paste the following script to the script editor of Google Spreadsheet and set the variables of formId and sheetName.

@TheGreatGaspy
TheGreatGaspy / submit.md
Created September 24, 2023 13:02 — forked from tanaikech/submit.md
Retrieving Event ID from Event URL of Google Calendar using Google Apps Script

Retrieving Event ID from Event URL of Google Calendar using Google Apps Script

This is a sample script for retrieving the event ID from the event URL of Google Calendar using Google Apps Script.

The event URL is like https://www.google.com/calendar/event?###. At the event URL, ### of https://www.google.com/calendar/event?### is not the event ID. So it is required to convert it.

Sample script

var eventUrl = "https://www.google.com/calendar/event?###";
@TheGreatGaspy
TheGreatGaspy / submit.md
Created September 24, 2023 13:01 — forked from tanaikech/submit.md
Copying Google Spreadsheet by Removing Container-Bound Script Using Google Apps Script

Copying Google Spreadsheet by Removing Container-Bound Script Using Google Apps Script

This is a sample script for copying a Google Spreadsheet including a container-bound script by removing the container-bound script using Google Apps Script.

When you want to copy a Google Google Spreadsheet including a container-bound script by removing the container-bound script using Google Apps Script, this could be achieved by using "get" and "create" methods of Sheets API before. The sample script is as follows.

const obj = Sheets.Spreadsheets.get(