Skip to content

Instantly share code, notes, and snippets.

View bhaveshdaswani93's full-sized avatar
👋
Building Awesome things with Laravel React Vue

Bhavesh Daswani bhaveshdaswani93

👋
Building Awesome things with Laravel React Vue
View GitHub Profile
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" ],
@bhaveshdaswani93
bhaveshdaswani93 / .htaccess
Created December 21, 2020 05:42 — forked from ScottPhillips/.htaccess
Common .htaccess Redirects
#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/
@bhaveshdaswani93
bhaveshdaswani93 / class_decorator.ts
Created February 4, 2020 03:39 — forked from remojansen/class_decorator.ts
TypeScript Decorators Examples
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);
}
@bhaveshdaswani93
bhaveshdaswani93 / composition_vs_inheritance.js
Created January 4, 2020 08:54
composition vs inheritance explained by example
// 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`)
}
@bhaveshdaswani93
bhaveshdaswani93 / arity_in_javascript.js
Created December 29, 2019 13:30
Arity in javascript
const addNumber = (num1,num2) => num1+num2
const getAbsoulte = (num) => Math.abs(num)
// addNumber has arity of two
// getAbsoulte has arity of one
@bhaveshdaswani93
bhaveshdaswani93 / compose_and_pipe.js
Last active December 29, 2019 13:14
Let's understand compose and pipe with an example
// 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
@bhaveshdaswani93
bhaveshdaswani93 / memoization_in_javascript.js
Created December 28, 2019 07:52
In this gist i will try to explain memoization in javascript
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 = {};
@bhaveshdaswani93
bhaveshdaswani93 / partial_application_in_js.js
Created December 28, 2019 05:15
In this gist i will try to explain you about partial application
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.
@bhaveshdaswani93
bhaveshdaswani93 / curring_javascript.js
Created December 28, 2019 04:39
Currying in javascript
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
@bhaveshdaswani93
bhaveshdaswani93 / high_order_function.js
Created December 28, 2019 03:11
In this example i will explain high order function
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) {