Skip to content

Instantly share code, notes, and snippets.

View jasdeepkhalsa's full-sized avatar

Jasdeep Khalsa jasdeepkhalsa

View GitHub Profile
@jasdeepkhalsa
jasdeepkhalsa / on-resize-end.js
Last active February 21, 2018 16:52
On Resize End ES6 Code
const doSomething = () => { /* Do something */ }
let onResizeEnd;
window.addEventListener('resize', () => {
if (onResizeEnd) {
clearTimeout(onResizeEnd);
}
onResizeEnd = setTimeout(() => doSomething(), 400);
});
@jasdeepkhalsa
jasdeepkhalsa / jest-collect-coverage-from-coverage-report.md
Created February 19, 2018 10:24
Creating a coverage report in Jest using the `--collectCoverageFrom` (array) option
jest --collectCoverageFrom='[\"**/*.js\",\"!src/js/vue/**/*.js\"]' --coverage
@jasdeepkhalsa
jasdeepkhalsa / i18n-in-aem-and-vue.md
Last active March 11, 2018 19:32
Simple i18n (Internationization) of Vue apps in AEM (Adobe Experience Manager) without using any libraries

How to do i18n (Internationization) within Vue apps using the :lang prop

JavaScript

import Template from './template.html';

export default {
  template: Template,
 props: {
@jasdeepkhalsa
jasdeepkhalsa / git-squash-all-commits-in-master-branch-into-one-commit.md
Created February 13, 2018 10:34
GIT: Squash all commits in the master branch into one commit
git checkout --orphan new-squashed-branch master
git commit
@jasdeepkhalsa
jasdeepkhalsa / replace-query-string.js
Created January 2, 2018 14:47
Changing a page URL without reloading with window.history.replaceState (IE11+)
window.history.replaceState(null, null, `${location.pathname}?abcd=1234`);
@jasdeepkhalsa
jasdeepkhalsa / Github Master Rebase.md
Last active January 4, 2018 12:22
When the master branch's history changes, this is how to pull
# Rebase the master branch
git checkout master
git pull --rebase
# Checkout the branch you want to rebase with master
git pull --rebase origin master
@jasdeepkhalsa
jasdeepkhalsa / add-event.js
Created August 17, 2017 09:34
Add Custom Event & Trigger Event Cross-browser
/**
* @param element The element to add the event
* @param type Event type (i.e. 'click')
* @param callback Function to execute when event is triggered
*/
function (element, type, callback) {
try {
element.addEventListener(type, callback, false);
} catch (e) {
element.attachEvent('on' + type, callback);
@jasdeepkhalsa
jasdeepkhalsa / typescript-2.x-string-enum.ts
Created May 26, 2017 15:08
TypeScript 2.x String Enum
export enum ExampleStringEnum {
PROPERTY_A = 'property-a' as any as ExampleStringEnum,
PROPERTY_B = 'property-b' as any as ExampleStringEnum,
}
@jasdeepkhalsa
jasdeepkhalsa / d3-transition-as-named-function.js
Created March 28, 2017 15:39
Calling a D3 Transition as a Named Function
function myTransitionSettings(transition) {
transition
.delay(0)
.duration(100)
.style('background', 'blue')
}
d3.transition().call(myTransitionSettings)
@jasdeepkhalsa
jasdeepkhalsa / check-scheduled-transitions-in-D3.js
Last active March 28, 2017 15:41
Check Number of Scheduled Transitions in D3.js v4
function checkScheduledTransitions(element) {
const transitions = element.__transition
if (transitions) {
return Object.keys(transitions).length
} else {
return false
}
}