Skip to content

Instantly share code, notes, and snippets.

View frizar's full-sized avatar

Vitaly Schekin frizar

  • Ukraine
View GitHub Profile
function saveSelection() {
if (window.getSelection) {
var sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
return sel.getRangeAt(0);
}
} else if (document.selection && document.selection.createRange) {
return document.selection.createRange();
}
return null;
@frizar
frizar / youtube-vimeo-url-parser.js
Created November 11, 2020 09:00 — forked from w3core/youtube-vimeo-url-parser.js
YouTube Vimeo URL Parser
function parseVideo (url) {
// - Supported YouTube URL formats:
// - http://www.youtube.com/watch?v=My2FRPA3Gf8
// - http://youtu.be/My2FRPA3Gf8
// - http://y2u.be/huKvjPQ-Xm4
// - https://youtube.googleapis.com/v/My2FRPA3Gf8
// - http://www.youtube.com/embed/Ab25nviakcw
// - http://www.youtube-nocookie.com/v/Ab25nviakcw?version=3&hl=en_US
// - http://www.youtube.com/watch?feature=player_embedded&v=Ab25nviakcw#
// - Supported Vimeo URL formats:
@frizar
frizar / unique-objects-by-prop-es6.js
Created July 26, 2019 08:12
ES6 array of unique objects by prop
// https://javascript.info/map-set
const uniqueObjectsByProp = (array, prop) => {
let map = new Map(array.map(item => [item[prop], item]));
return Array.from(map.values());
};
let arr = [{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }, { id: 1, name: 'Item 1' }];
let uniqueArr = uniqueObjectsByProp(arr, 'id');