Skip to content

Instantly share code, notes, and snippets.

View manfromanotherland's full-sized avatar
🤏

Edmundo Santos manfromanotherland

🤏
View GitHub Profile
@electerious
electerious / scrollroot.js
Last active September 17, 2019 13:45
Cross-browser scroll element fetching
const scrollroot = (() => {
if ('scrollingElement' in document) return document.scrollingElement
const initial = document.documentElement.scrollTop
document.documentElement.scrollTop = initial + 1
const updated = document.documentElement.scrollTop
document.documentElement.scrollTop = initial
@electerious
electerious / html.js
Last active January 24, 2017 09:13
html = (literalSections, ...substs) => {
// Use raw literal sections: We don’t want
// backslashes (\n etc.) to be interpreted
let raw = literalSections.raw,
let result = ''
substs.forEach((subst, i) => {
// Retrieve the literal section preceding
const ajaxform = (form, next) => {
let url = form.action
let xhr = new XMLHttpRequest()
let data = new FormData(form)
xhr.open('POST', url)
xhr.onload = () => next(form, xhr)
xhr.send(data)
const type = (data) => {
return Object.prototype.toString.call(data).replace(/^\[object (.+)\]$/, "$1").toLowerCase()
}
@paulirish
paulirish / what-forces-layout.md
Last active August 8, 2025 11:10
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@electerious
electerious / each.js
Last active January 24, 2017 09:14
forEach for Objects, Arrays and NodeLists
const each = (data, fn) => {
if (data==null) return false
if ((data).constructor===Object) return Array.prototype.forEach.call(Object.keys(data), (key) => fn(data[key], key, data))
else return Array.prototype.forEach.call(data, (item, i) => fn(item, i, data))
}
@electerious
electerious / closest.js
Last active November 6, 2015 22:14
Select the closest matching parent of an element
const closest = (elem, className) => {
if (elem==null || elem.classList==null) return null
return (elem.classList.contains(className) ? elem : closest(elem.parentNode, className))
}
@drmmr763
drmmr763 / hubspot.php
Created September 9, 2015 21:07
hubspot.api
<?php
$query = array(
'refresh_token' => 'xxx', // $this->keys['refresh_token'],
'client_id' => 'yyy', //$this->keys[$this->getClientIdKey()],
'grant_type' => 'refresh_token',
);
$url = 'https://api.hubapi.com/auth/v1/refresh?' . http_build_query($query);
$ch = curl_init();
@nitaku
nitaku / README.md
Last active October 18, 2023 12:17
Three.js isometric camera
@DevinWalker
DevinWalker / gist:6fb2783c05b46a2ba251
Created April 17, 2015 17:31
WordPress: Loop through Categories and Display Posts Within
<?php
/*
* Loop through Categories and Display Posts within
*/
$post_type = 'features';
// Get all the taxonomies for this post type
$taxonomies = get_object_taxonomies( array( 'post_type' => $post_type ) );
foreach( $taxonomies as $taxonomy ) :