Skip to content

Instantly share code, notes, and snippets.

View oscarmarina's full-sized avatar

Oscar Marina oscarmarina

  • BBVA
  • Madrid, Spain
View GitHub Profile
@oscarmarina
oscarmarina / moveRowsWithKeywordToNewSheet.gs
Created November 14, 2023 21:05
Move Rows with Keyword
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Menu')
.addItem('Move Rows with Keyword', 'moveRowsWithKeywordToNewSheet')
.addToUi();
}
function moveRowsWithKeywordToNewSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeSheet = ss.getActiveSheet();
@oscarmarina
oscarmarina / request-submit-polyfill.js
Created July 14, 2023 10:17
Requests to submit the form. Unlike submit(), this method includes interactive constraint validation and firing a submit event, either of which can cancel submission.
(prototype => {
if (typeof prototype.requestSubmit === 'function') {
return;
}
const validateSubmitter = (submitter, form) => {
if (!(submitter instanceof HTMLElement)) {
throw new TypeError('The submitter element is not of type HTMLElement');
}
if (submitter.type !== 'submit') {
- name: Check object
run: |
cat << OBJECT
${{ toJson(github.event) }}
OBJECT
@oscarmarina
oscarmarina / toggle-ytp.js
Created May 29, 2023 21:16
Bookmark - Toggle the YouTube Bar/Controls
javascript: (function () {
var style = document.querySelector('#toggle-ytp');
if (style) {
style.remove();
} else {
var selector = '.ytp-chrome-top,.ytp-chrome-bottom';
style = document.createElement('style');
style.id = 'toggle-ytp';
style.textContent = selector + '{display:none;}';
document.head.appendChild(style);
@oscarmarina
oscarmarina / index.html
Created April 23, 2023 17:44 — forked from e111077/index.html
MWC Select working inside an MWC dialog
<!DOCTYPE html>
<head>
<script type="module" src="./simple-greeting.js"></script>
</head>
<body>
<simple-greeting name="World"></simple-greeting>
</body>
import type {ReactiveController, ReactiveControllerHost} from 'lit';
/**
* A reactive controller that updates a host when slotted content changes and
* provides helper methods for checking and getting assigned slot content.
*/
export class SlotController implements ReactiveController {
private _host: ReactiveControllerHost & Element;
private _slotNames?: ReadonlyArray<string>;
@oscarmarina
oscarmarina / getScrollableParent.js
Last active May 7, 2024 19:49
Returns the scroll parent of an element along a specified axis and the scroll size and client size.
/**
* Returns the scroll parent of an element along a specified axis and the scroll size and client size.
*
* @param {HTMLElement} el - The element to find the scroll parent of.
* @param {String} [axis='y'] - The axis to find the scroll parent for.
* @returns {Object} An object with the following properties:
* @property {HTMLElement} scrollParent - The scroll parent element.
* @property {Number} scrollParentSize - The size of the scroll parent along the specified axis.
* @property {Number} clientParentSize - The size of the scroll parent's client area along the specified axis.
*/
@oscarmarina
oscarmarina / getObjectType.js
Created March 16, 2023 15:00
This function uses Object.prototype.toString.call() to obtain the string representation of the obj argument. This function follows the pattern '[object <type>]', where <type> is the name of the object's constructor.
const getObjectType = obj => Object.prototype.toString.call(obj).slice(8, -1);
console.log(getObjectType(new Date())); // Date
console.log(getObjectType([])); // Array
console.log(getObjectType(true)); // Boolean
console.log(getObjectType(function() {})); // Function
console.log(getObjectType(x => x)); // Function
console.log(getObjectType(null)); // Null
console.log(getObjectType(37)); // Number
console.log(getObjectType(NaN)); // Number
@oscarmarina
oscarmarina / find-package-with-attribute.js
Created February 5, 2023 19:28
Traverse the directory tree in Node.js, starting from the current working directory, searching for a "package.json" file with a specific attribute while excluding the node_modules folder and files starting with a dot (.)
import fs from 'fs';
import path from 'path';
const traverseTree = (dir, attribute, cacheTravese = '') => {
const files = fs.readdirSync(dir);
for (const file of files) {
if (
file === 'node_modules' ||
file.startsWith('.') ||
file === cacheTravese
@oscarmarina
oscarmarina / escapeHTML.js
Created September 8, 2022 06:53
Escapes a string for use in HTML.
export const escapeHTML = (str) =>
str.replace(
/[&<>'"]/g,
(character) =>
({
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
"'": '&#39;',
'"': '&quot;',