Skip to content

Instantly share code, notes, and snippets.

@gr2m
gr2m / worker.js
Created August 27, 2019 05:40
A Cloudflare worker to exchange an OAuth Web Flow code for an access token. Configure your CLIENT_ID and CLIENT_SECRET and you are all set.
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}`)
@leebyron
leebyron / PriorityQueue.js
Last active January 28, 2019 05:08
PriorityQueue.js uses a binary heap to ensure the highest priority item is always available to dequeue, and sorts on enqueue. A dynamically resizing Array can be used to model the binary heap, for a simpler and more efficient implementation.
/**
* 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>;
@khrome
khrome / gist:7d87534748545f576fd2
Last active September 16, 2023 17:33
__dirname in the browser
(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 {