Skip to content

Instantly share code, notes, and snippets.

View rajaraodv's full-sized avatar

Raja Rao DV rajaraodv

View GitHub Profile
//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"
//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 {
@rajaraodv
rajaraodv / MyFunctor.js
Last active February 8, 2019 13:45
A sample custom functor
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
@rajaraodv
rajaraodv / Monad-sample.js
Created November 9, 2016 00:28
A sample implementation of Monad
//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));
@rajaraodv
rajaraodv / Maybe-ramda-fantasy.js
Last active November 14, 2016 11:28
Maybe Monad sample implementation
//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;
}
//TODO Write this in Imperative v/s Functional style
const getUrlForUser = (user) => {
//todo
}
//User object
let joeUser = {
name: 'joe',
email: '[email protected]',
prefs: {
languages: {
@rajaraodv
rajaraodv / 0_reuse_code.js
Created September 18, 2016 21:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@rajaraodv
rajaraodv / gist:8c5160e105b33b841e41
Last active August 29, 2015 14:11
Upgrading to latest Git & Github tools to latest 2.2.1
--------------------------------
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,
@rajaraodv
rajaraodv / findNearBy
Last active August 29, 2015 14:05
Salesforce FindNearBy Example w/ bug fixes
<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">
@rajaraodv
rajaraodv / foobardirectiveFinal.js
Created November 25, 2012 05:43
foobar directive with solution
//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');
});