Skip to content

Instantly share code, notes, and snippets.

View kospl's full-sized avatar

Kostiantyn Plakhotia kospl

  • 10:18 (UTC +02:00)
View GitHub Profile
@tryggvigy
tryggvigy / withRetries.js
Last active March 6, 2020 18:18
Promise retries with exponential backoff
// paste this in any JS REPL to see the execution!
// Note that the fakeAPI is simulated to be flaky so try executin this a few times
// to see both the success and failure case
(() => {
/**
* Wrap a promise API with a function that will attempt the promise over and over again
* with exponential backoff until it resolves or reaches the maximum number of retries.
* - First retry: 500 ms + <random> ms
* - Second retry: 1000 ms + <random> ms
* - Third retry: 2000 ms + <random> ms
@davidrleonard
davidrleonard / from-now.js
Last active February 18, 2024 11:23
moment.fromNow() implemented in vanilla JavaScript as a simple, standalone function. Runs in the browser. No dependencies required.
/**
* Implements all the behaviors of moment.fromNow(). Pass a
* valid JavaScript Date object and the method will return the
* time that has passed since that date in a human-readable
* format. Passes the moment test suite for `fromNow()`.
* See: https://momentjs.com/docs/#/displaying/fromnow/
*
* @example
*
* var pastDate = new Date('2017-10-01T02:30');
@tanaikech
tanaikech / submit.md
Last active September 11, 2024 15:51
Multipart-POST Request Using Google Apps Script

Multipart-POST Request Using Google Apps Script

April 20, 2019: GAS library for this situation was published. Please check it at https://github.com/tanaikech/FetchApp.

These sample scripts are for requesting multipart post using Google Apps Script.

In most cases, the multipart request is used for uploading files. So I prepared 2 sample situations as follows. For each situation, the request parameters are different.

  1. Upload a file from Google Drive to Slack.
  2. Convert an excel file to Spreadsheet on Google Drive using Drive API v3.
@ilbonte
ilbonte / youtube-captions.js
Created May 14, 2016 17:29
Get the transcript for any youtube's video
/*
DOES NOT WORK WITH AUTOMATIC CAPTIONS!
How to:
1. open the javascript console
2. paste the code below and press enter
3. click on the link and open the page
4. If you need to download the subtitles: right click and save as .vtt (can be open with vlc)
*/
var id=window.location.search.split("v=")[1];
var lang='en'; //default language is english (see below)