Skip to content

Instantly share code, notes, and snippets.

const removeProperties = ({
password,
blockExpires,
loginAttempts,
...rest
}) => rest;
@kadavre
kadavre / rxjs-diagrams.md
Created September 5, 2018 14:13 — forked from PCreations/rxjs-diagrams.md
Super Intuitive Interactive Diagrams to learn combining RxJS sequences by Max NgWizard K
$('p.descr').attr('unselectable', 'on')
.css('user-select', 'none')
.on('selectstart', false);
// You want to parse this address into parts:
var url = 'http://tutorialzine.com/books/jquery-trickshots?trick=12#comments';
// The trick; create a new link with the url as its href:
var a = $('<a>',{ href: url });
console.log('Host name: ' + a.prop('hostname'));
console.log('Path: ' + a.prop('pathname'));
console.log('Query: ' + a.prop('search'));
console.log('Protocol: ' + a.prop('protocol'));
console.log('Hash: ' + a.prop('hash'));
// Old way
console.log($('#elem').length == 1 ? "exists!" : "doesn't exist!");
// The trick:
jQuery.fn.exists = function(){ return this.length > 0; }
console.log($('#elem').exists() ? "exists!" : "doesn't exist!");
var route = {
_routes : {}, // The routes will be stored here
add : function(url, action){
this._routes[url] = action;
},
run : function(){
jQuery.each(this._routes, function(pattern){
if(location.href.match(pattern)){
// "this" points to the function to be executed
this();
// with jQuery
$(document).ready(function(){ /* ... */ });
// shorter jQuery version
$(function(){ /* ... */ });
// without jQuery (doesn't work in older IEs)
document.addEventListener('DOMContentLoaded', function(){
// your code goes here
}, false);
// and here's the trick (works everywhere):
r(function(){
var equalizeHeights = function () {
$(".equalizer").each(function(ix, el) {
var heights = $(el).find('.eq-watch').map(function() {
return $(this).height();
}).get();
maxHeight = Math.max.apply(null, heights);
$(el).find('.eq-watch').height(maxHeight);
});
};
(function() {
var results;
this.assert = function assert(value, desc) {
var li = document.createElement("li");
li.className = value ? "pass" : "fail";
li.appendChild(document.createTextNode(desc));
results.appendChild(li);
if (!value) {
li.parentNode.parentNode.className = "fail";
}
@kadavre
kadavre / ajax-promise.js
Created September 21, 2016 10:17
ajax jquery promise
function getAjaxPromise (url) {
return new Promise(function (resolve, reject) {
var xhttp = new XMLHttpRequest();
xhttp.open('GET', url, true);
xhttp.onload = function () {
if (xhttp.status == 200) {
resolve(JSON.parse(xhttp.response));
} else {
reject(xhttp.statusText);
}