Skip to content

Instantly share code, notes, and snippets.

//
// returns a list of all elements under the cursor
//
function elementsFromPoint(x,y) {
var elements = [], previousPointerEvents = [], current, i, d;
// get all elements via elementFromPoint, and remove them from hit-testing in order
while ((current = document.elementFromPoint(x,y)) && elements.indexOf(current)===-1 && current != null) {
// push the element and its current style
@oslego
oslego / javascript_multiton.js
Created June 3, 2011 10:57
JavaScript Multiton Example
/*
Use, reuse but don't abuse!
Author: Razvan Caliman (razvan.caliman@gmail.com)
This is an example of a "Multiton" pattern;
Create a fixed number of instances of a class.
Use "lazy instantiation" to create objects only if needed.
If the maximum number of instances has been reached, return a random one from the ones created.
*/
@oslego
oslego / supports.js
Last active November 21, 2022 22:08
Basic feature detection with prefix support.
var Supports = (function(){
// all spaces are important!
var prefixes = ' -webkit- -moz- -o- -ms- ';
function getPrefixedProperties(property, prefixes) {
var properties = prefixes.join(property + " ").split(' ');
// ignore the last string which is empty.
return properties.slice(0, properties.length-1);
}
@oslego
oslego / hooks.js
Last active December 4, 2020 18:20 — forked from WebReflection/hooks.js
const augment = callback => () => {
const useState = {
init: true,
value: void 0,
update(value) {
useState.value = value;
callback(hooks)
}
};
const hooks = {
<!DOCTYPE html>
<html lang="en">
<head>
<style media="screen">
div {
animation: marker 0s 1;
}
@keyframes marker { to { outline-color: inherit } }
</style>
</head>
@oslego
oslego / StyleSheetArrayProxy.js
Created December 9, 2019 16:34
StyleSheetArray implementation with Proxy and Reflect
// https://github.com/WICG/construct-stylesheets/issues/45#issuecomment-522879888
'use strict';
function isArrayIndex(string) {
if (typeof string !== 'string') {
return false;
}
const number = Number(string);
return Number.isSafeInteger(number)
@oslego
oslego / gist:f13e136ffeaa6174289a
Last active January 3, 2019 14:24 — forked from sl4m/gist:5091803
create self-signed certificate for localhost
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@oslego
oslego / Guide to CSS Regions.md
Last active January 16, 2018 08:44
Short guide to using CSS Regions

Guide to CSS Regions

Introduction

CSS Regions are a mechanism used in web pages to separate content from its layout. Regions can be used to visually flow content from one element to another regardless of the content's original location in the DOM tree.

Concepts

@oslego
oslego / String.isBalanced.js
Created August 4, 2017 12:25
Method that returns true when a string is balanced and false otherwise.
/*
Task:
Given an input string return true if the string is balanced, otherwise return false.
A string is balanced when every opening bracket "{", square bracket "[", and parenthesis "("
has a matching closing character.
*/
const string = "{[()]}";
(function(input){