This file contains 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
var mediaJSON = { "categories" : [ { "name" : "Movies", | |
"videos" : [ | |
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org", | |
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ], | |
"subtitle" : "By Blender Foundation", | |
"thumb" : "images/BigBuckBunny.jpg", | |
"title" : "Big Buck Bunny" | |
}, | |
{ "description" : "The first Blender Open Movie from 2006", | |
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ], |
This file contains 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
#301 Redirects for .htaccess | |
#Redirect a single page: | |
Redirect 301 /pagename.php http://www.domain.com/pagename.html | |
#Redirect an entire site: | |
Redirect 301 / http://www.domain.com/ | |
#Redirect an entire site to a sub folder | |
Redirect 301 / http://www.domain.com/subfolder/ |
This file contains 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 logClass(target: any) { | |
// save a reference to the original constructor | |
var original = target; | |
// a utility function to generate instances of a class | |
function construct(constructor, args) { | |
var c : any = function () { | |
return constructor.apply(this, args); | |
} |
This file contains 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
// we have to represent human relation in oop style | |
class Human { | |
constructor(firstName,lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
sleepNow() { | |
console.log(`${this.firstName} ${this.lastName} is sleeping`) | |
} |
This file contains 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 addNumber = (num1,num2) => num1+num2 | |
const getAbsoulte = (num) => Math.abs(num) | |
// addNumber has arity of two | |
// getAbsoulte has arity of one |
This file contains 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
// Our task is to multiply a number with 3 and take absolute of that number | |
const multiplyWith3 = (x)=>x*3; | |
const getAbsouleOfNum = (x)=>Math.abs(x) | |
// here we have two component multiplyWith3 and getAbsouleOfNum | |
// if we want to do that without compose we will do like these | |
let x = 15; | |
let xAfterMultiply = multiplyWith3(x); | |
let xAfterAbsoulte = getAbsouleOfNum(xAfterMultiply); | |
//Let's do in composable way |
This file contains 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 notMemoized = (x) => { | |
return x*2; | |
} | |
notMemoized(2); // 4 | |
notMemoized(2); // 4 | |
// every time we run the function the multiplication code get executed which can be optimized by memoization | |
const memoizedFn = () => { | |
const cache = {}; |
This file contains 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 multiply = (a,b,c) =>a*b*c; | |
//Partial Application | |
const partiallyMultiplyBy5 = multiply.bind(null,5); | |
partiallyMultiplyBy5(4,10) //200 | |
// in above example partiallyMultiplyBy5 partially apply multiply function with 5 as first argument. | |
// when executing the partiallyMultiplyBy5 function we just have to pass remaining paramater as the first argument 5 has been remember | |
// due to closure. |
This file contains 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 multiply = (a,b) => a*b; | |
multiply(4,6) // 24 | |
//above is the function that take multiple argument let convert into curring | |
const curring = (a)=>(b)=>a*b; | |
curring(5)(4); // 20 | |
// we have converted multiply function that take 2 param | |
// into two function that takes one parameter at a time |
This file contains 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 hocFn = function() { | |
return function() { | |
return 5; | |
} | |
} | |
hocFn() // will return function | |
hocFn()() // will return 5 | |
// hocFn return function so it is HOC | |
const fn = function(x) { |
NewerOlder