This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ //make __dirname, __filename work in the browser | |
if(window && !window['__dirname']){ | |
var stackTrace = function () { | |
var lines = (new Error()).stack.split("\n"); | |
// 0 = message, 1 = stackTrace | |
lines.shift(); lines.shift(); | |
var result = lines.map(function(line){ | |
if(line.indexOf('(native)') != -1){ | |
return { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* For compare function return: | |
* - Less than zero: item1 has higher priority than item2. | |
* - Zero: same. | |
* - Greater than zero: item1 has lower priority than item2. | |
*/ | |
export type CompareFunction<T> = (item1: T, item2: T) => number; | |
export class PriorityQueue<T> { | |
_items: Array<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
const CLIENT_ID = '<your client ID>' | |
const CLIENT_SECRET = '<your client Secret>' | |
async function handleRequest(request) { | |
if (request.method === 'GET') { | |
return new Response(`$ curl -XPOST -H'Content-Type: application/json' -d'{"code": "<your oauth code>"}' ${request.url}`) |