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
//Step 1. Instead of.. | |
if (user == null) { //not logged in | |
return indexURLs['en']; //return default page | |
} | |
//Use: | |
Maybe(user) //Returns Maybe({userObj}) or Maybe(null). i.e. data wrapped INSIDE "Maybe" | |
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
//Imperative: | |
//Too many if-else and null checks; relying on global indexURLs; decided that "en" urls are default for any country | |
const getUrlForUser = (user) => { | |
if (user == null) { //not logged in | |
return indexURLs['en']; //return default page | |
} | |
if (user.prefs.languages.primary && user.prefs.languages.primary != 'undefined') { | |
if (indexURLs[user.prefs.languages.primary]) {//if translation exists, | |
return indexURLs[user.prefs.languages.primary]; | |
} else { |
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 add1 = (a) => a + 1; | |
class MyFunctor { //Custom "Functor" | |
constructor(value) { | |
this.val = value; | |
} | |
map(fn) { //Applies function to this.val + returns new Myfunctor | |
return new Myfunctor(fn(this.val)); | |
} | |
} | |
//temp is a Functor instance that's storing value 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
//Monad - a sample implementation | |
class Monad { | |
constructor(val) { | |
this.__value = val; | |
} | |
static of(val) {//Monad.of is simpler than "new Monad(val) | |
return new Monad(val); | |
}; | |
map(f) {//Applies the function but returns another Monad! | |
return Monad.of(f(this.__value)); |
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
//Showing relevant parts from the Maybe implementation from ramda-fantasy lib | |
//See https://github.com/ramda/ramda-fantasy/blob/master/src/Maybe.js for full source | |
function Maybe(x) { //<-- main constructor that returns Maybe of Just or Nothing | |
return x == null ? _nothing : Maybe.Just(x); | |
} | |
function Just(x) { | |
this.value = x; | |
} |
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
//TODO Write this in Imperative v/s Functional style | |
const getUrlForUser = (user) => { | |
//todo | |
} | |
//User object | |
let joeUser = { | |
name: 'joe', | |
email: '[email protected]', | |
prefs: { | |
languages: { |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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 Git version: | |
-------------------------------- | |
git --version | |
If you don't see one of the following, you should to update: | |
v1.8.5.6, v1.9.5, v2.0.5, v2.1.4, and v2.2.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
<apex:page sidebar="false" showheader="false" standardController="Warehouse__c" recordSetVar="warehouses" extensions="FindNearby"> | |
<!-- (Won't work anymore) Include in Google's Maps API via JavaScript static resource | |
<apex:includeScript value="{!$Resource.googleMapsAPI}" /> | |
--> | |
<!-- Set this API key to fix JavaScript errors in production --> | |
<!--http://salesforcesolutions.blogspot.com/2013/01/integration-of-salesforcecom-and-google.html--> | |
<script type="text/javascript" | |
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDYaP-xy0Noe1HCeNOmWE2MZYwUcehnZM0&sensor=false"> |
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
//Wrap masonry with ImagesLoaded and wrap that again with a $timeout w/ a small delay solves the issue. | |
clientAppModule.directive('addMasonry', function($timeout) { | |
return { | |
restrict: 'A', | |
link: function(scope, element) { | |
$timeout(function(val) { //looks like timeout or deferred solves the issue | |
scope.container.imagesLoaded(function() { | |
scope.container.masonry('reload'); | |
}); |