Skip to content

Instantly share code, notes, and snippets.

View jasdeepkhalsa's full-sized avatar

Jasdeep Khalsa jasdeepkhalsa

View GitHub Profile
@jasdeepkhalsa
jasdeepkhalsa / index.html
Created March 5, 2021 12:44 — forked from igrigorik/index.html
XHR streaming example
<p>Hello
<script>
var xhr = new XMLHttpRequest();
xhr.open('GET', '/stream');
xhr.seenBytes = 0;
xhr.onreadystatechange = function() {
console.log("state change.. state: "+ xhr.readyState);
@jasdeepkhalsa
jasdeepkhalsa / pipe.js
Last active March 12, 2021 15:42 — forked from ericelliott/pipe.js
Pipe
// Pipe takes the first argument and pipes it though each of the functions that you provide as the remaining arguments,
// and can be implemented as follows:
const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x);
const fn1 = s => s.toLowerCase();
const fn2 = s => s.split('').reverse().join('');
const fn3 = s => s + '!'
const newFunc = pipe(fn1, fn2, fn3);
const result = newFunc('Time'); // emit!
@jasdeepkhalsa
jasdeepkhalsa / compose.js
Created July 24, 2020 16:16 — forked from ericelliott/compose.js
Compose implementation
const compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x);
@jasdeepkhalsa
jasdeepkhalsa / react-route-based-code-splitting.js
Last active September 5, 2018 10:26 — forked from gaearon/webpack.config.js
React & Webpack Route-based code splitting example
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import Loadable from 'react-loadable';
const Loading = () => <div>Loading...</div>;
const Home = Loadable({
loader: () => import('./routes/Home'),
loading: Loading,
});
@jasdeepkhalsa
jasdeepkhalsa / fetchData.js
Last active April 26, 2018 16:17 — forked from Calvin-Huang/redux-saga-worker-and-watcher.js
Redux Saga Example with Worker and Watcher
import { call, put, takeLatest } from 'redux-saga/effects';
/*
const EXAMPLE_DISPATCHED_ACTION = {
type: 'FETCH_REQUESTED',
payload: { url: 'https://api.github.com' }
}
*/
// Watcher
@jasdeepkhalsa
jasdeepkhalsa / jasmine-this-vars.md
Created October 27, 2015 13:37 — forked from traviskaufman/jasmine-this-vars.md
Better Jasmine Tests With `this`

Better Jasmine Tests With this

On the Refinery29 Mobile Web Team, codenamed "Bicycle", all of our unit tests are written using Jasmine, an awesome BDD library written by Pivotal Labs. We recently switched how we set up data for tests from declaring and assigning to closures, to assigning properties to each test case's this object, and we've seen some awesome benefits from doing such.

The old way

Up until recently, a typical unit test for us looked something like this:

describe('views.Card', function() {
@jasdeepkhalsa
jasdeepkhalsa / ajax.js
Last active September 18, 2015 09:26 — forked from xeoncross/ajax.js
Simple, cross-browser Javascript POST/GET xhr request object. Supports request data and proper AJAX headers.
/**
* IE 5.5+, Firefox, Opera, Chrome, Safari XHR object
*
* @param string url
* @param object callback
* @param mixed data
* @param null x
*/
function ajax(url, callback, data, x) {
try {
/*
* insertAdjacentHTML.js
* Cross-browser full HTMLElement.insertAdjacentHTML implementation.
*
* 2011-10-10
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
@jasdeepkhalsa
jasdeepkhalsa / pr.md
Last active August 29, 2015 14:20 — forked from piscisaureus/pr.md

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 = [email protected]: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: