Skip to content

Instantly share code, notes, and snippets.

J@sdeep jhbsk

View GitHub Profile
@jhbsk
jhbsk / 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;
}
@jhbsk
jhbsk / 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
@jhbsk
jhbsk / 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('');
@jhbsk
jhbsk / 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
@jhbsk
jhbsk / 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 + .
@jhbsk
jhbsk / log.js
Created Oct 11, 2018
console.log Log Wrapper using ES6 Rest & Spread Syntax
View log.js
function log(...args) {
console.log(...args);
}
@jhbsk
jhbsk / flattening-svgs.md
Created Oct 5, 2018
Flattening SVGs into One Layer / Path
View flattening-svgs.md
@jhbsk
jhbsk / react-route-based-code-splitting.js
Last active Sep 5, 2018 — forked from gaearon/webpack.config.js
React & Webpack Route-based code splitting example
View react-route-based-code-splitting.js
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,
});
@jhbsk
jhbsk / health.json
Last active Jul 18, 2018
Healthcheck for microservices
View health.json
// 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": ""
@jhbsk
jhbsk / create-react-app-with-a-custom-git-url.sh
Created May 22, 2018
Create React App with a Custom Git URL
View create-react-app-with-a-custom-git-url.sh
# Ensure create-react-app is Installed
# For Github
```
$ create-react-app my-app --scripts-version git+ssh://git@github.com:<repo_owner>/<reponame>.git
```
# For Bitbucket (Git)
You can’t perform that action at this time.