Skip to content

Instantly share code, notes, and snippets.

@kevinweber
kevinweber / giphy.js
Created February 19, 2018 04:14
Giphy API Example
import {
checkStatus,
parseJSON
} from './request';
/**
* Request data Giphy API
* https://developers.giphy.com/explorer/
*/
@kevinweber
kevinweber / index.js
Last active February 12, 2018 03:18
AEM-React / AEM-Preact integration
import './index.scss';
import {
isObject,
traverseObjectByPath,
} from 'utils/methods';
import {
// INFO: The 'h' function import gets used in the final, transpiled code as a drop in replacement for React.createElement, and so needs to be imported even if you don't explicitly use it in the code you write
// eslint-disable-next-line no-unused-vars
@kevinweber
kevinweber / enforcer.js
Last active October 20, 2017 00:35
Enforcer.js: Address validation
import {
debounce as T_DEBOUNCE,
} from 'utils/methods';
/**
* T-ENFORCER provides methods to validate strings.
* This is developed with input fields in mind, but it shouldn't be limited to them.
*
* Author: Kevin Weber
*
@kevinweber
kevinweber / README.md
Created May 17, 2017 23:18 — forked from toodooleedoo/README.md
#AEM #Sightly #SSJS Server Side JavaScript Use-API Breadcrumbs

###Description Retrieve a Page Object from all pages which are in the Site root then build a breadcrumb component and display the current pages title in a submenu.

###Use case Display a bar under eg a menu which displays the current pages title and functional breadcrumb components o the right.

##Requirements

  • Responsive and which works on all mobile devices and desktop.
  • Current pages title on the left
  • Breadcrumbs on the right
@kevinweber
kevinweber / generateObjectKey.js
Last active April 7, 2017 04:56
Convert a given string so it can be used as the unique key/id of a JavaScript object. If no string is provided, a random string is generated.
/**
* Converts a given string so it can be used as the key of a JavaScript object.
* If no string is provided, a random string is generated.
*/
function generateObjectKey(string) {
var key;
if (typeof string === "undefined") {
string = Math.random().toString(36).substr(2, 5);
}
@kevinweber
kevinweber / createNestedObject.js
Last active February 24, 2017 23:41
Convert dot-notated string or path of object into an object using recursion. This is similar to Lodash's _.zipObject but it doesn't set any values.
/**
* Convert an array into an object where each object gets nested like this:
['string1', 'string2', 'string3']
becomes
{
string1: {
string2: {
@kevinweber
kevinweber / replaceOrAddValue.js
Last active February 23, 2017 22:50
URL query algorithm. A very basic solution to add or replace a property and its value to a URL.
/*
* A very basic solution to add or replace a property and its value to a URL
*
* Usage example:
* url = replaceOrAddValue(url, "property_name", "value");
*
* Source: https://gist.github.com/kevinweber/58a1b1bdcbab109018dc01a619f9b730
*/
function replaceOrAddValue(query, variable, value) {
var findVariable = variable + "=",
@kevinweber
kevinweber / Throttle
Last active December 23, 2016 17:38
Throttle
/**
* Throttle function
* based on https://remysharp.com/2010/07/21/throttling-function-calls
*/
function throttle(fn, threshold, scope) {
threshold = threshold || 250;
var last,
deferTimer;
@kevinweber
kevinweber / $.js
Last active December 19, 2016 19:13
MiniJQuery using documentSelectorAll - you don't need jQuery!
// Use this:
var $ = function (domSelector) {
return Array.prototype.slice.call(document.querySelectorAll(domSelector));
}
// Or this:
const $ = (domSelector) => [].slice.call(document.querySelectorAll(domSelector));
// And then use $ like this:
@kevinweber
kevinweber / debug-events.js
Last active December 9, 2016 14:07
Monitor events associated with DOM elements (for debugging only)
// See also: https://developers.google.com/web/tools/chrome-devtools/debug/command-line/events
monitorEvents(document.body); // logs all events on the body
monitorEvents(document.body, 'mouse'); // logs mouse events on the body
monitorEvents(document.body.querySelectorAll('input')); // logs all events on inputs