Skip to content

Instantly share code, notes, and snippets.

View jasdeepkhalsa's full-sized avatar

Jasdeep Khalsa jasdeepkhalsa

View GitHub Profile
@jasdeepkhalsa
jasdeepkhalsa / ExtractValueFromKey.sh
Last active November 6, 2018 15:30
Extract a value from a file of key=value pairs using BASH
#!/bin/sh
VAR=$(grep "MyVar" test | grep "^$MyVar" | cut -d'=' -f2-)
echo $VAR
@jasdeepkhalsa
jasdeepkhalsa / show-hidden-mac.md
Created October 18, 2018 14:03
Quickest Way to Show/Hide Hidden Files on MacOS

Since macOS Sierra, when in Finder, you can use the shortcut:

CMD + SHIFT + .

@jasdeepkhalsa
jasdeepkhalsa / log.js
Created October 11, 2018 14:25
console.log Log Wrapper using ES6 Rest & Spread Syntax
function log(...args) {
console.log(...args);
}
@jasdeepkhalsa
jasdeepkhalsa / flattening-svgs.md
Created October 5, 2018 09:22
Flattening SVGs into One Layer / Path
@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 / health.json
Last active July 18, 2018 14:06
Healthcheck for microservices
// Each microservice should have an endpoint in a standard/agreed format for checking its health
// This makes it extremely easy to check the health of all microservices
// This can be run on a cronjob nightly
{
"healthy": true,
"pods": 2,
"podsAvailable": 2,
"lastUpdated": "12:00:00 UTC",
"errorMessage": ""
@jasdeepkhalsa
jasdeepkhalsa / create-react-app-with-a-custom-git-url.sh
Created May 22, 2018 09:51
Create React App with a Custom Git URL
# Ensure create-react-app is Installed
# For Github
```
$ create-react-app my-app --scripts-version git+ssh://[email protected]:<repo_owner>/<reponame>.git
```
# For Bitbucket (Git)
@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 / scrollTo.js
Created April 13, 2018 15:51
scrollTo - Cross-browser way to scroll to an element
function scrollTo(element) {
const bodyRect = document.body.getBoundingClientRect();
const elemRect = element.getBoundingClientRect();
const offset = Math.round(elemRect.top - bodyRect.top);
window.scroll({
top: offset,
left: 0,
behavior: 'smooth'
});
@jasdeepkhalsa
jasdeepkhalsa / renameObjectKey.js
Created March 19, 2018 10:48
Rename an object key in IE9+ whilst keeping its position in the object
function renameObjectKey(oldObj, oldName, newName) {
const newObj = {};
Object.keys(oldObj).forEach(key => {
const value = oldObj[key];
if (key === oldName) {
newObj[newName] = value;
} else {
newObj[key] = value;