Skip to content

Instantly share code, notes, and snippets.

View sunilhari's full-sized avatar
✈️
Fight or Flight

Sunil Hari sunilhari

✈️
Fight or Flight
View GitHub Profile
@sunilhari
sunilhari / AsyncComponent.jsx
Created April 7, 2018 11:45 — forked from lencioni/AsyncComponent.jsx
<AsyncComponent> at Airbnb used for Webpack code splitting
// Usage:
//
// function loader() {
// return new Promise((resolve) => {
// if (process.env.LAZY_LOAD) {
// require.ensure([], (require) => {
// resolve(require('./SomeComponent').default);
// });
// }
// });
@sunilhari
sunilhari / node-curry.js
Created April 4, 2018 05:00 — forked from fernandezpablo85/node-curry.js
Explanation of the curry function for node.js
function curriedReadFile(path) {
var _done, _error, _result;
var callback = function(error, result) {
_done = true,
_error = error,
_result = result;
};
fs.readFile(path, function(e, r) {
@sunilhari
sunilhari / pr.md
Created March 15, 2018 12:09 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@sunilhari
sunilhari / CurriedFunc.js
Created March 2, 2018 06:00
Curried Function
const curry = (fn)=>(...args)=>(fn.bind(null,...args));
// Example
add = (a,b)=>{
return a+b;
}
const curriedAdd= curry(add);
console.log(curriedAdd(2)(3)) // 5
console.log("Hello World!!!!'); // Hello World!!!!
console.log("My Name is %s and I am %d years old","Bob",12); //My Name is Bob and I am 12 years old
function counter(label){
console.count(label);
}
counter('label1'); // label1 : 1
counter('label1'); // label1 : 2
counter('label1'); // label1 : 3
counter('label2'); // label2 : 1
console.count();//1
var noError = true;
console.assert(noError,'There is an Error','in the code block');
//Output
noError = false;
console.assert(noError,'There is an Error','in the code block');
//Output
Assertion failed: There is an Error in the code block
// The classic AJAX call - dispatch before the request, and after it comes back
function myThunkActionCreator(someValue) {
return (dispatch, getState) => {
dispatch({type : "REQUEST_STARTED"});
myAjaxLib.post("/someEndpoint", {data : someValue})
.then(
response => dispatch({type : "REQUEST_SUCCEEDED", payload : response}),
error => dispatch({type : "REQUEST_FAILED", error : error})
);
function multiply(n,n){
return n*n;
}
function square(n){
return multiply(n,n);
}
function print(n){
var squared = square(n);
//TIME_OUT = 0
Expected Output
----------------
"Before Set-Time-Out"
"Inside Set-Time-Out"
"Exiting Set-Time-Out after 0 milliseconds"
"Outside Set-Time-Out"
Actual Output