Skip to content

Instantly share code, notes, and snippets.

Jasdeep Khalsa jasdeepkhalsa

Block or report user

Report or block jasdeepkhalsa

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jasdeepkhalsa
jasdeepkhalsa / react-hooks.md
Created Oct 13, 2019
React Hooks Transition Guide
View react-hooks.md

setState -> const [state, setState] = useState()

componentDidMount -> useEffect(() => {}, [])

componentDidMount & componentDidUpdate -> useEffect(() => {}, [props.changedValue]

componentWillUnmount & componentDidUnmount -> useEffect(() => { return () => console.log('Cleaning up') }, [])

shouldComponentUpdate -> export default React.memo(myComponent, () => console.log('finer grain control here, but I work opposite to shouldComponentUpdate. Usually out of the box memoization is good enough')

View elm-starter.elm
import Html exposing (..)
-- MODEL
type alias Model = { ... }
-- UPDATE
@jasdeepkhalsa
jasdeepkhalsa / jenkinsfile-stage.groovy
Last active Jul 10, 2019
Adding a stage into a Jenkins file
View jenkinsfile-stage.groovy
stage('Lint') {
steps {
sh 'npm run lint'
}
}
@jasdeepkhalsa
jasdeepkhalsa / complex-git-rebase-strategies.md
Last active May 15, 2019
Complex git rebase strategies (using --rebase-merges)
View complex-git-rebase-strategies.md

Firstly make sure you're using a decent editor with your git e.g. Atom, VS Code etc.

git config --global core.editor "atom"

To modify a merge commit history, like the merges done by popular online version control systems such as GitLab or Bitbucket:

¢ git rebase --rebase-merges -i HEAD~1
@jasdeepkhalsa
jasdeepkhalsa / triggerEventIE8+.js
Created Feb 20, 2019
triggerEvent dispatch fire trigger events cross browser IE8 compatible
View triggerEventIE8+.js
function triggerEvent(elem, eventType) {
const noop = () => {}
if ('createEvent' in document) {
// modern browsers, IE9+
const evt = document.createEvent('HTMLEvents') || new Event(eventType);
evt.initEvent ? evt.initEvent(eventType, true, false) : noop();
elem.dispatchEvent(evt);
return;
}
@jasdeepkhalsa
jasdeepkhalsa / video-to-gif.sh
Created Jan 9, 2019
Video to GIF with FFMPEG
View video-to-gif.sh
ffmpeg -i video.mp4 -filter_complex "[0:v] fps=24,scale=1080:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" video.gif
## REFERENCES
# https://engineering.giphy.com/how-to-make-gifs-with-ffmpeg/
# https://ffmpeg.org/ffmpeg-filters.html#scale-1
@jasdeepkhalsa
jasdeepkhalsa / numberToWords.js
Last active Dec 28, 2018
Number to Words Convertor
View numberToWords.js
import { toWords } from 'number-to-words';
export function numberToWords(number) {
if (!number || number === true) {
return number;
}
const numWithNoNonDigits = number.replace ? number.replace(/\D/g,'') : number;
const numToArray = numWithNoNonDigits.toString().split('');
@jasdeepkhalsa
jasdeepkhalsa / ExtractValueFromKey.sh
Last active Nov 6, 2018
Extract a value from a file of key=value pairs using BASH
View ExtractValueFromKey.sh
#!/bin/sh
VAR=$(grep "MyVar" test | grep "^$MyVar" | cut -d'=' -f2-)
echo $VAR
@jasdeepkhalsa
jasdeepkhalsa / show-hidden-mac.md
Created Oct 18, 2018
Quickest Way to Show/Hide Hidden Files on MacOS
View show-hidden-mac.md

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

CMD + SHIFT + .
@jasdeepkhalsa
jasdeepkhalsa / log.js
Created Oct 11, 2018
console.log Log Wrapper using ES6 Rest & Spread Syntax
View log.js
function log(...args) {
console.log(...args);
}
You can’t perform that action at this time.