Skip to content

Instantly share code, notes, and snippets.

View thednp's full-sized avatar
🚲
No longer working from home

thednp

🚲
No longer working from home
View GitHub Profile
@VineetKumarKushwaha
VineetKumarKushwaha / Publisher-Subscriber.js
Created July 3, 2020 11:49
Publisher-Subscriber Pattern
const pubSub = (() => {
const topicSubscriberMap = new Map();
const throwError = (topic) => {
throw new Error(`
No ${topic} named topic found in the registry.
Available topics:- ${JSON.stringify(getAllTopic())}
`);
};
const getAllTopic = () => Array.from(topicSubscriberMap.keys());
@erquhart
erquhart / selection-command.js
Last active February 29, 2024 10:31
Text selection commands for Cypress.io
/**
* Credits
* @Bkucera: https://github.com/cypress-io/cypress/issues/2839#issuecomment-447012818
* @Phrogz: https://stackoverflow.com/a/10730777/1556245
*
* Usage
* ```
* // Types "foo" and then selects "fo"
* cy.get('input')
* .type('foo')
/*--------------Library code----------------*/
/**
* BezierEasing - use bezier curve for transition easing function
* by Gaëtan Renaudeau 2014 – MIT License
*
* Credits: is based on Firefox's nsSMILKeySpline.cpp
* Usage:
* var spline = BezierEasing(0.25, 0.1, 0.25, 1.0)
* spline(x) => returns the easing value | x must be in [0, 1] range
*
@guilhermejcgois
guilhermejcgois / getStyle.ts
Last active July 20, 2023 11:38
Get computed styles (in typescript)
// Gist adapted from: https://gist.github.com/cms/369133
export getStyle(el: Element, styleProp: string): string {
let value;
const defaultView = el.ownerDocument.defaultView;
// W3C standard way:
if (defaultView && defaultView.getComputedStyle) {
// sanitize property name to css notation (hypen separated words eg. font-Size)
styleProp = styleProp.replace(/([A-Z])/g, '-$1').toLowerCase();
return defaultView.getComputedStyle(el, null).getPropertyValue(styleProp);
} else if (el['currentStyle']) { // IE
{
"alignleft": {
"selector": "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img",
"classes": "left"
},
"aligncenter": {
"selector": "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img",
"classes": "center"
},
"alignright": {
@geuis
geuis / gist:8b1b2ea57d7f9a9ae22f80d4fbf5b97f
Last active January 10, 2024 16:43
Get Youtube video urls
// Run from the dev tools console of any Youtube video
// Accurate as of July 2, 2020.
//
// Copy and paste this into the dev console in a browser with the desired video loaded.
//
// NOTE: Some Youtube videos do not directly expose the video url in the response.
// This script doesn't currently attempt to handle those. It will work for most other general video types though.
(async () => {
const html = await fetch(window.location.href).then((resp) => resp.text()).then((text) => text);
@phproberto
phproberto / templates\protostar\html\layouts\com_content\article\image.php
Created October 23, 2015 02:03
Joomla layouts to generate thumbnails on the fly
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
@SleepWalker
SleepWalker / swipe.js
Created September 30, 2015 04:59
A simple swipe detection on vanilla js
var touchstartX = 0;
var touchstartY = 0;
var touchendX = 0;
var touchendY = 0;
var gesuredZone = document.getElementById('gesuredZone');
gesuredZone.addEventListener('touchstart', function(event) {
touchstartX = event.screenX;
touchstartY = event.screenY;
@olmokramer
olmokramer / css-color-regex
Last active December 9, 2023 12:52
Regex for CSS colors: hex, rgb(a), hsl(a)
/(#([0-9a-f]{3}){1,2}|(rgba|hsla)\(\d{1,3}%?(,\s?\d{1,3}%?){2},\s?(1|0?\.\d+)\)|(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?\)){2})/i
@eugene-ilyin
eugene-ilyin / cookie.js
Created October 21, 2014 08:50
Work with cookies in native Javascript