Skip to content

Instantly share code, notes, and snippets.

View jineeshjohn's full-sized avatar

Jineesh jineeshjohn

View GitHub Profile
<script>
let counter = 0;
const debounce = (fn, delay) => {
let timeoutId;
return () => {
clearTimeout(timeoutId);
timeoutId = setTimeout(fn, delay);
}
@jineeshjohn
jineeshjohn / launch.json
Created January 23, 2020 13:13
Debugging create react app jest test
// https://elijahmanor.com/cra-debug-vscode/
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug CRA Tests",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
@jineeshjohn
jineeshjohn / sample.js
Created January 6, 2020 12:01
How to create a proxy using react create app
//step 1: Inside package.json add proxy key
// eg: "proxy": "http://jsonplaceholder.typicode.com"
//step 2: sample program to retrive from jsonplaceholder
(async()=>{
const apiData = await fetch('/users');
const json = await apiData.json();
console.log("JJJ:", json);
@jineeshjohn
jineeshjohn / function.js
Created August 1, 2017 11:24
Different ways to write functions
function A(){}; // function declaration
var B = function(){}; // function expression
var C = (function(){}); // function expression with grouping operators
var D = function foo(){}; // named function expression
var E = (function(){ // IIFE that returns a function
return function(){}
})();
var F = new Function(); // Function constructor
var G = new function(){}; // special case: object constructor
var H = x => x * 2; // ES6 arrow function
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// Chaining
var lyrics=[
{line:1,words:"Im a lumberjack and Im okay"},
{line:2,words:"I sleep all night and I work all day"},
{line:3,words:"Hes a lumberjack and hes okay"},
{line:4,words:"He sleeps all night and he works all day"}
];
var values = _(lyrics).chain()
@jineeshjohn
jineeshjohn / sla.js
Last active December 2, 2016 13:40
Single level of abstraction - SLA
var responseJson = [
{type: 'input', id: 'key1', styles:{display:'block', color: 'red'}, someprop:'abc', someotherprop:'bcd'},
{type: 'radio', id: 'key2', styles:{display:'inline', color: 'blue'}, someprop:'xyz', someotherprop:'z'}
]
var parseResponse = function(response) {
var result = [];
for (var i=0; i<response.length; i++) {
var resultObj = {
type: response[i].type,
var responseJson = [
{type: 'input', id: 'key1', styles:{display:'block', color: 'red'}, someprop:'abc', someotherprop:'bcd'},
{type: 'radio', id: 'key2', styles:{display:'inline', color: 'blue'}, someprop:'xyz', someotherprop:'z'}
]
var parseResponse = function(response) {
var result = [];
for (var i=0; i<response.length; i++) {
var resultObj = {
type: response[i].type,
define(function(require){
'use strict';
var React = require('react');
var store = require('./store');
var RegisterForm = require('es6!./registerForm');
var VerifyForm = require('es6!./verifyForm');
var RegisterSuccess = require('es6!./registerSuccess');
var Stepper = require('es6!./stepper');
@jineeshjohn
jineeshjohn / gist:10725702
Last active August 29, 2015 13:59
Asynchronous way of executing array of JavaScript functions
function f1(cb){
console.log("I am f1");
cb();
}
function f2(cb){
console.log("I am f2");
cb()
}
function f3(){
console.log("I am f3");