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
| const peopleArray = [ | |
| { id: 123, name: "dave", age: 23 }, | |
| { id: 456, name: "chris", age: 23 }, | |
| { id: 789, name: "bob", age: 23 }, | |
| { id: 101, name: "tom", age: 23 }, | |
| { id: 102, name: "tim", age: 23 } | |
| ]; | |
| const arrayToObject = (array) => | |
| array.reduce((obj, 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
| 'tr' => [ /* Turkish */ | |
| 'ş' => 's', | |
| 'Ş' => 'S', | |
| 'ı' => 'i', | |
| 'İ' => 'I', | |
| 'ç' => 'c', | |
| 'Ç' => 'C', | |
| 'ü' => 'u', | |
| 'Ü' => 'U', | |
| 'ö' => 'o', |
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
| document.body.addEventListener("myEventName", doSomething, false); | |
| function doSomething(e) { | |
| alert("Event is called: " + e.type); | |
| } | |
| var myEvent = new CustomEvent("myEventName"); | |
| document.body.dispatchEvent(myEvent); |
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
| // Assuming "?post=1234&action=edit" | |
| var urlParams = new URLSearchParams(window.location.search); | |
| console.log(urlParams.has('post')); // true | |
| console.log(urlParams.get('action')); // "edit" | |
| console.log(urlParams.getAll('action')); // ["edit"] | |
| console.log(urlParams.toString()); // "?post=1234&action=edit" | |
| console.log(urlParams.append('active', '1')); // "?post=1234&action=edit&active=1" |
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 supportsVideoType(type) { | |
| let video; | |
| // Allow user to create shortcuts, i.e. just "webm" | |
| let formats = { | |
| ogg: 'video/ogg; codecs="theora"', | |
| h264: 'video/mp4; codecs="avc1.42E01E"', | |
| webm: 'video/webm; codecs="vp8, vorbis"', | |
| vp9: 'video/webm; codecs="vp9"', | |
| hls: 'application/x-mpegURL; codecs="avc1.42E01E"' |
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 debounce(func, wait, immediate) { | |
| var timeout; | |
| return function() { | |
| var context = this, args = arguments; | |
| var later = function() { | |
| timeout = null; | |
| if (!immediate) func.apply(context, args); | |
| }; | |
| var callNow = immediate && !timeout; | |
| clearTimeout(timeout); |
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 debounce(fn, delay) { | |
| var timer = null; | |
| return function() { | |
| var context = this, args = arguments; | |
| clearTimeout(timer); | |
| timer = setTimeout(function() { | |
| fn.apply(context, args); | |
| }, delay); | |
| }; | |
| } |
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
| // Parse YouTube ID from url | |
| function _parseYouTubeId(url) { | |
| var regex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/; | |
| return url.match(regex) ? RegExp.$2 : url; | |
| } |
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
| // Check variable types | |
| var _is = { | |
| object: function(input) { | |
| return input !== null && typeof input === 'object'; | |
| }, | |
| array: function(input) { | |
| return input !== null && (typeof input === 'object' && input.constructor === Array); | |
| }, | |
| number: function(input) { | |
| return input !== null && ((typeof input === 'number' && !isNaN(input - 0)) || (typeof input === 'object' && input.constructor === Number)); |
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
| <?php | |
| $items = []; | |
| array_push($items, ["key" => "Current Date T", "value" => date('Y-m-d H:i:s T')]); | |
| array_push($items, ["key" => "Current Date", "value" => $date = date('Y-m-d H:i:s')]); | |
| array_push($items, ["key" => "LOCALE TIMESTAMP: ", "value" => strtotime($date)]); // true | |
| array_push($items, ["key" => "UTC TIMESTAMP: ", "value" => strtotime($date." UTC")]); // wrong | |
| array_push($items, ["key" => "TIME", "value" => time()]); | |
| array_push($items, ["key" => "BD from LOCALE", "value" => strtotime("1992-01-28 02:00:00")]); // 696556800 | |
| array_push($items, ["key" => "BD from UTC 00:00:00", "value" => strtotime("1992-01-28 00:00:00 UTC")]); // 696556800 |