Skip to content

Instantly share code, notes, and snippets.

View chrisgfortes's full-sized avatar

Christian Fortes chrisgfortes

View GitHub Profile
@chrisgfortes
chrisgfortes / mergeDeep.js
Created December 13, 2019 19:26
Deep object merge JS
/**
* Performs a deep merge of `source` into `target`.
* Mutates `target` only but not its objects and arrays.
*
* @author inspired by [jhildenbiddle](https://stackoverflow.com/a/48218209).
*/
function mergeDeep(target, source) {
const isObject = (obj) => obj && typeof obj === 'object';
if (!isObject(target) || !isObject(source)) {
@chrisgfortes
chrisgfortes / git.txt
Created December 2, 2019 16:48
Find when a file was deleted in Git
// You can find the last commit which deleted file as follows:
git rev-list -n 1 HEAD -- [file_path]
@chrisgfortes
chrisgfortes / import-export.results.js
Last active November 7, 2019 15:00
Import/Export objects in JS
module.exports = {
key1: () => 'Key 1',
key2: () => 'Key 2',
};
import all, { key1 } from 'index';
// Result
// all = { key1, key2 }
// key1 = () => {}
@chrisgfortes
chrisgfortes / date.js
Created April 30, 2019 23:00
Get number of days in a specified month using JavaScript?
// Month here is 1-indexed (January is 1, February is 2, etc). This is
// because we're using 0 as the day so that it returns the last day
// of the last month, so you have to add 1 to the month number
// so it returns the correct amount of days
function daysInMonth (month, year) {
return new Date(year, month, 0).getDate();
}
// July
daysInMonth(7,2009); // 31
@chrisgfortes
chrisgfortes / index.html
Created April 26, 2019 16:06
Turning Off Autocomplete in Chrome with React
<div>
<input autocomplete="new-password" />
<input autocomplete="new-username" />
</div>
<!-- Reference: https://stackoverflow.com/questions/18531437/stop-google-chrome-auto-fill-the-input -->
@chrisgfortes
chrisgfortes / util-types.js
Created February 19, 2019 14:42
Util functions from lodash in pure JS:: _.isObject, _.isString, _.isNumber, _.isFunction, _.isBoolean, _.isArray, _.isRegExp
/**
* util-types could be used to replace some methods of lodash such as:
* _.isObject
* _.isString
* _.isNumber
* _.isFunction
* _.isBoolean
* _.isArray
* _.isRegExp
*/
@chrisgfortes
chrisgfortes / _.get.js
Last active February 19, 2019 14:28
Pure _.get from lodash
function _stringToPath(path) {
const containsBracketNotation = /\[[0-9]+\]/g;
if (path.match(containsBracketNotation)) {
path = path.replace(containsBracketNotation, s => `.${s.substring(1, s.length - 1)}`);
}
return path.split('.');
}
function get(source, path, defaultArgument) {
return _stringToPath(path).reduce((nestedObject, key) => {
@chrisgfortes
chrisgfortes / file.sh
Created February 6, 2019 19:22
Travis CI encrypt slack channel on travis-ci.com
travis encrypt --com '<SLACK_ACCOUNT>:<SLACK_TOKEN>#<SLACK_CHANNEL>' -r <REPO_USER>/<REPO_NAME>
travis encrypt --com '<SLACK_ACCOUNT>:<SLACK_TOKEN>#<SLACK_CHANNEL>'
@chrisgfortes
chrisgfortes / terminal-git-branch-name.md
Created August 16, 2018 14:32 — forked from joseluisq/terminal-git-branch-name.md
Add Git Branch Name to Terminal Prompt (Mac)

Add Git Branch Name to Terminal Prompt (Mac)

image

Open ~/.bash_profile in your favorite editor and add the following content to the bottom.

# Git branch in prompt.

parse_git_branch() {
@chrisgfortes
chrisgfortes / .aliases
Created June 10, 2018 15:20
Using custom command in the bash with autocompletion (MacOS - Bash)
#!/usr/bin/env bash
source ~/.bash_functions;
alias project='project $1'