This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| const doSomething = () => console.log('doing something'); | |
| /** | |
| useEffect(() => { | |
| doSomething(); | |
| return () => cleanup(); | |
| }, [whenThisChanges]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Finding a single element in the array | |
| // | |
| // filter returns an array with less items than the original array | |
| const performSomething = (item) => { | |
| return item | |
| } | |
| const items = ['a', 'b', 'c'] | |
| items.forEach((item) => { | |
| performSomething(item) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(window.ga) { | |
| window.ga(function (tracker) { | |
| // Grab a reference to the default sendHitTask function. | |
| var originalSendHitTask = tracker.get('sendHitTask'); | |
| // Modifies sendHitTask to send a copy of the request to a local server after | |
| // sending the normal request to www.google-analytics.com/collect. | |
| tracker.set('sendHitTask', function (model) { | |
| originalSendHitTask(model); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*! | |
| * Dynamically changing favicons with JavaScript | |
| * Works in all A-grade browsers except Safari and Internet Explorer | |
| * Demo: http://mathiasbynens.be/demo/dynamic-favicons | |
| */ | |
| // HTML5™, baby! http://mathiasbynens.be/notes/document-head | |
| document.head || (document.head = document.getElementsByTagName('head')[0]); | |
| function changeFavicon(src) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * ------------------------------------ | |
| * Using Map & Join | |
| * ------------------------------------ | |
| */ | |
| // ES6 | |
| var queryString = Object.keys(params).map(key => key + '=' + params[key]).join('&'); | |
| // ES5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function form_params( form ) | |
| { | |
| var params = new Array() | |
| var length = form.elements.length | |
| for( var i = 0; i < length; i++ ) | |
| { | |
| element = form.elements[i] | |
| if(element.tagName == 'TEXTAREA' ) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var e=document.createElement('div'); | |
| e.id='I3q96EY1VjNB'; | |
| e.style.display='none'; | |
| document.body.appendChild(e); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * | |
| * Returns a URL query parameter by it's key. | |
| * eg. You have a URL: http://host.com/some/path?uniquekey=value | |
| * The function call qs('uniquekey') returns 'value' | |
| * | |
| * @param key string | |
| * @return string | |
| * | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * This snippet is meant to return your | |
| * analytics client ID, of your web visitor | |
| * to a variable of your choosing. | |
| * | |
| * This REQUIRES that you have Classic/Universal Analytics. | |
| * | |
| * Step-by-step: | |
| * 1. Go to your GTM container. (https://tagmanager.google.com) | |
| * 2. Go to Variables. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Extend Array prototype | |
| */ | |
| Array.prototype.toQueryString = function(){ | |
| var out = new Array(); | |
| for(key in this){ | |
| out.push(key + '=' + encodeURIComponent(this[key])); | |
| } |