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
// This work is licensed under the Creative Commons Attribution 3.0 United States License. To view | |
// a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/ or send a letter | |
// to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. | |
// Copyright 2009 John Tantalo <[email protected]> | |
(function () { | |
// get selection | |
var selection = window.getSelection ? window.getSelection() : | |
document.getSelection ? document.getSelection() : |
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
/* | |
//Sequentially scrape a given list of URLs with a given minimum delay between fetches | |
//Usage: | |
let | |
BaseUrl = "http://example.com/?p=", | |
Pages = List.Numbers(1, 5), | |
Urls = List.Transform(Pages, each BaseUrl & Number.ToText(_)) | |
in | |
Web_FetchSequentially(Urls) |
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
export const alias = { | |
"openapi": "2.0", | |
"paths": { | |
"/path1": { | |
"get": { | |
"parameters": [ | |
{ | |
"in": "path", | |
"name": "my_param", | |
"schema": { "$ref": "#/x-MyDefs/person_id" } |
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
// using ES6 Proxy to deal with methods of Promise'd objects. works for me in Edge though not Chrome somehow. | |
let handler = { | |
get: (target, prop) => function() { | |
if(target instanceof Promise) { | |
let args = arguments; | |
return target.then((o) => o[prop].apply(o, args)); | |
} else { | |
let value = target[prop]; | |
return typeof value == 'function' ? value.bind(target) : value; | |
} |
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
// using ES6 Proxy to let Promises/Observables pretend like they're regular values. | |
// get the mapping function used for async objects | |
let getMapper = (target) => target instanceof Promise ? 'then' : | |
target instanceof Observable ? 'switchMap' : null; | |
// ^ fails if the Observable is in a local namespace e.g. Rx.Observable | |
// bind a value to its object if it's a function | |
let bindFn = (val, obj) => typeof val == 'function' ? val.bind(obj) : val; |
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
// get the CSS snippet needed to give one element the style of another | |
var R = require('ramda'); | |
var getPx = (str) => /(\d+)\s*px/g.test(str) ? Number(str.replace(/[^\d]/g, '')) : null; | |
var px2rem = R.curry((base, str) => str.replace(/(\d+)\s*px/g, (match, px) => Number(px)/base + 'rem')); | |
var base = getPx(getComputedStyle(document.documentElement).fontSize); | |
var toRem = px2rem(base); | |
var patchStyle = (fromEl, toEl, asRem = false) => { | |
let [styles, stylesTo] = [fromEl, toEl].map(getComputedStyle); | |
let css = R.pipe( |
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
let R = require('ramda'); | |
const up = (s) => s[0].toUpperCase() + s.substring(1).replace(/\-(\w)/, (match, letter) => letter.toUpperCase()); | |
// JSON.stringify(crudOpenApiEndpoints({ single: 'app' })) | |
function crudOpenApiEndpoints ({ single, plural = single + 's', id = 'id', type = 'integer' }) { | |
let $ref = `#/definitions/${up(single)}`; | |
let resp = (schema) => ({ description: 'OK', schema }); | |
let responses = { 204: resp({}) }; // empty non-GET response | |
let idPar = { name: id, in: 'path', required: true, type }; |
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
// install repos: https://github.com/jb55/javascript-iterators/wiki/Registry | |
const iterator = R.map({ | |
map: require('map-iterator'), | |
filter: require('filter-iterator'), | |
groupBy: require('groupby-iterator'), | |
sortBy: require('sortby-iterator'), | |
concat: require('concat-iterator'), | |
skip: require('skip-iterator'), | |
take: require('take-iterator'), |
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
var R = require('ramda'); | |
var deps = R.pipe( | |
R.match(/Depends: ([\w-]+)/g), | |
R.map(R.replace('Depends: ', '')), | |
R.join(' '), | |
R.concat('sudo apt-get install '), | |
); | |
/* |
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
// run on the page of a Youtube playlist to obtain the total playlist time in hours | |
Array.from(document.getElementsByClassName('ytd-thumbnail-overlay-time-status-renderer')) | |
.map(x=> { | |
var nums = x.innerText.split(':').map(Number); | |
var [h, m, s] = nums[2] !== undefined ? nums : [0, ...nums]; | |
return 3600*h+60*m + s; | |
}) | |
.reduce((a,b)=>a+b) / 3600 |
OlderNewer