Skip to content

Instantly share code, notes, and snippets.

View ktajpuri's full-sized avatar

kamlesh tajpuri ktajpuri

View GitHub Profile
async function testAsync() {
let response = await fetch('https://mock-wholesaleonline.getsandbox.com/testRedux');
let result = await response.json();
return result;
}
testAsync()
.then((result) => console.log(result))
.catch((error) => console.log(error))
@ktajpuri
ktajpuri / ES6-generator-functions.js
Last active July 14, 2018 03:55
A brief introduction to generator functions
function* generator(i) {
yield i;
yield i + 10;
}
var gen = generator(10);
console.log(gen.next().value);
// expected output: 10
@ktajpuri
ktajpuri / movie-saga.js
Last active July 14, 2018 05:15
Tesing async fetch requests in redux saga
import { put, call, takeEvery} from 'redux-saga/effects';
import { fetchMoviesApi} from './moviesApi';
export function* fetchMoviesSaga(action) {
yield put({type: 'TOGGLE_LOADING', payload: true});
try {
const movies = yield call(fetchMoviesApi);
yield put({type: 'TOGGLE_LOADING', payload: false});
yield put({type: 'LOAD_INITIAL_MOVIES', payload: movies});
} catch (e) {
const quotes = ["quote1", "quote2", "quote3", "quote4", "quote5"];
class NotFound extends React.PureComponent {
render() {
let randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
return (
<h1>
Quote: <strong>{randomQuote}</strong>
</h1>
);
@ktajpuri
ktajpuri / functional-inheritence.js
Last active August 13, 2018 08:24
Demo for functional multilevel inheritence in javascript
Object.prototype.testFunc = function () {
console.log('I am test from of global ')
}
function Person(name, age) {
this.name = name;
this.age = age;
this.printIdentity = function() {
return 'Mr. ' + this.name;
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
printIdentity() {
return "Mr. " + this.name;
}
testFunc() {
console.log("I am test from person");
// Say you have this function
function demo() {
var a = 1;
let b = 2;
if (1) {
var c = 3;
let d = 4;
console.log(a, b, c, d);
}
console.log(a, b, c, d);
@ktajpuri
ktajpuri / how-this-differs-in-arrow-functions.js
Created February 26, 2019 12:58
how-this-differs-in-arrow-functions
this.myVar = "outer";
var obj = {
myVar: "inner",
myFunc1: function() {
console.log(this.myVar);
},
myFunc2: () => {
console.log(this.myVar);
},
@ktajpuri
ktajpuri / Useful aliases for bash
Created June 10, 2019 12:46
useful aliases for bash
alias s='git status'
alias b='git branch'
alias p='git pull'
alias a='git add .'
co () { git checkout "$@"; }
m () { git commit -m "$@";}