Skip to content

Instantly share code, notes, and snippets.

View leongaban's full-sized avatar

Leon Gaban leongaban

View GitHub Profile
@leongaban
leongaban / dynamicPropertyDestructuring.js
Created January 17, 2018 22:54
Dynamic Property Destructuring O_O
const obj = { "foo": "bar" };
const p = "foo";
const { [p]: val } = obj;
console.log(val);
> "bar"
// Real world
const { [f]: param = false } = getContextParams(CONTEXT);
@leongaban
leongaban / update-using.git
Last active January 4, 2018 22:46
git update-using
update-using = "!f(){ CUR_BRANCH=$(git rev-parse --abbrev-ref HEAD); git checkout "$1" && git pull && git push --no-verify origin "$1":"$1" && git checkout $CUR_BRANCH && git rebase "$1"; }; f"
# 1) Grabs the name of the branch you're on
# 2) Checks out the REL branch you specified
# 3) Updates the REL branch from upstream
# 4) Hydrates the REL branch on origin
# 5) Checks out your feature branch again [from step 1]
# 6) Begins rebasing REL onto your feature branch
# Set upstream branch
# git branch --set-upstream-to upstream/REL_ENUDDEN
@leongaban
leongaban / getQuery.js
Created October 31, 2017 18:02
Query url & array
/* eslint-disable import/prefer-default-export */
const queryArray = arr => arr.map((v) => {
const a = v.split('='); // Split by the kvp separator (=)
return {
name: a.shift(), // Grab text before the first equal sign (the key)
value: a.join('=') // Grab the value (everything after the first equals)
};
});
@leongaban
leongaban / redux.js
Created October 30, 2017 18:10
cleanMapStateToProps function for redux
/* eslint-disable import/prefer-default-export */
import { initialStates } from '../reducers';
const defaultPropDef = {
value: null,
writable: false,
configurable: true,
enumerable: true
};
@leongaban
leongaban / pre-push
Created September 22, 2017 20:45
githooks pre-push
#!/bin/sh
yarn run test-eslint
RESULT=$?
[ $RESULT -ne 0 ] && exit 1
yarn run test-jest
RESULT=$?
[ $RESULT -ne 0 ] && exit 1
exit 0
@leongaban
leongaban / environment.js
Created June 12, 2017 14:43
Get environment variable into node and create a js file
const environment = process.env.NODE_ENV;
const stream = fs.createWriteStream("src/services/environment.js");
stream.once('open', function(fd) {
stream.write('const env = "'+environment+'"\n');
stream.write('export default env');
stream.end();
});
@leongaban
leongaban / validate_zipcode.js
Created May 4, 2017 16:03
Validate Zipcode in Javascript
// http://stackoverflow.com/questions/160550/zip-code-us-postal-code-validation
const validZipcode = (zipcode) => zipcode.match(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
@leongaban
leongaban / formatPhoneNumber.js
Created May 4, 2017 16:01
Phone number formatting in Javascript
const numberVerified = (number) => R.isEmpty(number) ? false : number.match(/^[(]{0,1}[0-9]{3}[)]{0,1}[-\s\.]{0,1}[0-9]{3}[-\s\.]{0,1}[0-9]{4}$/);
const formatPhone = (number) => {
// http://stackoverflow.com/questions/6204867/fastest-way-to-remove-hyphens-from-a-string-js
const new_number = number.replace(/-/g, '');
return Number(new_number);
};
@leongaban
leongaban / hyper.js
Created March 3, 2017 16:12
My HyperTerm gist
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 12,
// font family with optional fallbacks
fontFamily: 'Menlo, "DejaVu Sans Mono", Consolas, "Lucida Console", monospace',
// terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk)
cursorColor: 'rgba(248,28,229,0.8)',
@leongaban
leongaban / InfiniteScrolling.js
Created January 6, 2017 17:16
InfiniteScrolling
const maxlimitCheck = () => this.tags.length >= TOTAL_TAGS;
const checkScrollLimit = () => {
if (!LIMIT_REACHED) {
const scrollingTrue = true;
PARAMS.start += this.limit;
maxlimitCheck() ? LIMIT_REACHED = true : fetchTags(scrollingTrue);
}
};