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 / urlToPlainObject.js
Created April 9, 2024 09:03
converting-a-url-object-to-a-plain-object-in-java-scrip
// https://www.abeautifulsite.net/posts/converting-a-url-object-to-a-plain-object-in-java-script/
const url = new URL('https://api.chucknorris.io/jokes/random');
function urlToPlainObject(url) {
const plainObject = {};
for (const key in url) {
if (typeof url[key] === 'string') {
plainObject[key] = url[key];
@oscarmarina
oscarmarina / context-meta.ts
Last active April 4, 2024 15:15
Lit playground context-consume-provide
import { ReactiveController, ReactiveControllerHost } from 'lit';
import {
createContext,
ContextProvider,
ContextConsumer,
Context,
ContextType,
} from '@lit/context';
@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