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() { | |
var spyId = 'spyEvent'; | |
Class.extend({ | |
addEventSpy: function (instance) { | |
/* | |
accepts one argument - Class instance. | |
works by adding a local fireEvent method on the instance | |
instead of going TO proto chain to Class.Event::fireEvent | |
*/ |
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
//Source: https://github.com/yearofmoo/MooTools-Event.outerClick/blob/master/Source/Event.outerClick.js | |
(function($,$$){ | |
var events; | |
var check = function(e){ | |
var target = $(e.target); | |
var parents = target.getParents(); | |
events.each(function(item){ | |
var element = item.element; | |
if (element != target && !parents.contains(element)) |
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
// The "once" wrapper | |
function once(fn, context) { | |
var executed = false; | |
return function() { | |
if(executed) return; | |
executed = true; | |
fn.apply(context || this, arguments); | |
}; | |
} | |
var canOnlyFireOnce = once(function() { |
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
// Get Multiple URLs to file | |
var OutputUrlsToFile, arrayOfUrls, system, fs, t; | |
system = require("system"); | |
fs = require('fs'); | |
/* | |
Get given urls | |
@param array of URLs to get | |
@param callbackPerUrl Function called after finishing each URL, including the last URL | |
@param callbackFinal Function called after finishing everything | |
*/ |
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 Leaflet's LatLng class | |
* giving it the ability to calculate the bearing to another LatLng | |
* Usage example: | |
* here = map.getCenter(); / some latlng | |
* there = L.latlng([37.7833,-122.4167]); | |
* var whichway = here.bearingWordTo(there); | |
* var howfar = (here.distanceTo(there) / 1609.34).toFixed(2); | |
* alert("San Francisco is " + howfar + " miles, to the " + whichway ); | |
* |
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
componentDidUpdate(prevProps, prevState) { | |
Object.entries(this.props).forEach( | |
([key, val]) => | |
prevProps[key] !== val && console.log(`Prop '${key}' changed`) | |
) | |
if (this.state) { | |
Object.entries(this.state).forEach( | |
([key, val]) => | |
prevState[key] !== val && console.log(`State '${key}' changed`) |
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 _ from "lodash"; | |
const iterations = 10000; | |
const sortByIndex = (a, b, index, ascending) => | |
ascending ? a[index] - b[index] : b[index] - a[index]; | |
const sortListingsWithMemoize = _.memoize((listings, index, ascending) => { | |
//console.log('sortListings with memoize...') | |
return listings.sort((a, b) => sortByIndex(a, b, index, ascending)); | |
}); |
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 _ from 'lodash' | |
const id = 'unique_id' | |
const arr = [ | |
{ id: "cd3405db863314ea9c0a923c9e21ee28", beds: 2, bath: 1 }, | |
{ id: "90472efaad627e518957da32f31b1558", beds: 4, bath: 2 }, | |
{ id: "14ed01de968e15c7dcfe39a726e9b514", beds: 5, bath: 3 }, | |
{ id: "14ed01de968e15c7dcfe39a726e9b514", beds: 1, bath: 4 } | |
]; | |
const sort = (listings, index, ascending) => { |
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
[ | |
{ | |
"id": "cd3405db863314ea9c0a923c9e21ee28", | |
"beds": 2, | |
"bath": 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
import React, { Component } from "react"; | |
class Listings extends Component { | |
sortByIndex = (a, b, index, ascending) => (ascending ? a[index] - b[index] : b[index] - a[index]) | |
sortListings = (listings, index, ascending) => | |
listings.sort((a,b) => this.sortByIndex(a, b, index, ascending)) | |
render() { | |
const sortedListings = this.sortListings(this.props.listings, 'beds', false) |
OlderNewer