Skip to content

Instantly share code, notes, and snippets.

View rks's full-sized avatar

Randy Souza rks

View GitHub Profile
@adactio
adactio / _polyfills.js
Created November 9, 2020 17:19
JavaScript polyfills for matches,closest, and forEach.
// https://github.com/jonathantneal/closest/blob/master/src/index.js
var ElementPrototype = window.Element.prototype;
if (typeof ElementPrototype.matches !== 'function') {
ElementPrototype.matches = ElementPrototype.msMatchesSelector || ElementPrototype.mozMatchesSelector || ElementPrototype.webkitMatchesSelector || function matches(selector) {
var element = this;
var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
var index = 0;
while (elements[index] && elements[index] !== element) {
++index;
}
@jrop
jrop / async-await.js
Created March 8, 2017 17:52
async readdir (Node.JS)
const flatten = require('flatten')
const fs = require('mz/fs')
const path = require('path')
async function isDirectory(f) {
return (await fs.stat(f)).isDirectory()
}
async function readdir(filePath) {
const files = await Promise.all((await fs.readdir(filePath)).map(async f => {
@timoxley
timoxley / 1.rreaddir.js
Last active August 6, 2023 17:13
async/await recursive fs readdir
import { join } from 'path'
import { readdir, stat } from 'fs-promise'
async function rreaddir (dir, allFiles = []) {
const files = (await readdir(dir)).map(f => join(dir, f))
allFiles.push(...files)
await Promise.all(files.map(async f => (
(await stat(f)).isDirectory() && rreaddir(f, allFiles)
)))
return allFiles
{
"always_show_minimap_viewport": true,
"auto_indent": true,
"auto_match_enabled": true,
"bold_folder_labels": true,
"color_scheme": "Packages/Base16 Color Schemes/base16-default.dark.tmTheme",
"detect_indentation": false,
"draw_minimap_border": true,
"draw_white_space": "selection",
"ensure_newline_at_eof_on_save": true,
module RetryableTyphoeus
require 'typhoeus'
include Typhoeus
DEFAULT_RETRIES = 1
class Request < Typhoeus::Request
def original_on_complete=(proc)
@original_on_complete = proc