Skip to content

Instantly share code, notes, and snippets.

@rafagarcia
rafagarcia / nvmCommands.js
Created April 12, 2022 10:47 — forked from chranderson/nvmCommands.js
Useful NVM commands
// check version
node -v || node --version
// list installed versions of node (via nvm)
nvm ls
// install specific version of node
nvm install 6.9.2
// set default version of node
@rafagarcia
rafagarcia / gist:645d94057ff14b14853563d001a7872e
Created March 29, 2022 15:41 — forked from CrookedNumber/gist:8964442
git: Removing the last commit

Removing the last commit

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.

If you want to "uncommit" the commits, but keep the changes around for reworking, remove the "--hard": git reset HEAD^ which will evict the commits from the branch and from the index, but leave the working tree around.

If you want to save the commits on a new branch name, then run git branch newbranchname before doing the git reset.

@rafagarcia
rafagarcia / async-await-vs-promises-errors.js
Created December 4, 2018 16:45 — forked from k-vosswinkel/async-await-vs-promises-errors.js
Playing with promises and async/await
const returnsAPromise = (string) => (
new Promise((resolve, reject) => {
if (typeof string !== 'string') reject('Not a string!');
resolve(`String is a resolved promise now: ${string}`);
})
);
const myString = "Kait's string";
let isOurPromiseFinished = false;
Hex Opacity Values
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
@rafagarcia
rafagarcia / JS Quiz Answer Explanations.md
Created August 30, 2017 06:47 — forked from MattSurabian/JS Quiz Answer Explanations.md
My attempt to explain the answers for David Shariff's feelings hurting JS quiz found at: davidshariff.com/js-quiz/

Are your feelings hurt?

If you rushed through David Shariff's JS Quiz or are just new to JS they might be. I know mine were. After I dried my eyes, I took the quiz again, this time very slowly trying to get at the meat behind each answer. Below is my attempt to explain each question's answer and offer some interesting permutations so that others can move beyond their hurt feelings and come out the other side better JS developers.

I initially thought I'd turn this into a blog post but think it's probably better as a gist.

Question #1

Don't over think it.

var foo = function foo() {
@rafagarcia
rafagarcia / JS Quiz Answer Explanations.md
Created August 30, 2017 06:47 — forked from MattSurabian/JS Quiz Answer Explanations.md
My attempt to explain the answers for David Shariff's feelings hurting JS quiz found at: davidshariff.com/js-quiz/

Are your feelings hurt?

If you rushed through David Shariff's JS Quiz or are just new to JS they might be. I know mine were. After I dried my eyes, I took the quiz again, this time very slowly trying to get at the meat behind each answer. Below is my attempt to explain each question's answer and offer some interesting permutations so that others can move beyond their hurt feelings and come out the other side better JS developers.

I initially thought I'd turn this into a blog post but think it's probably better as a gist.

Question #1

Don't over think it.

var foo = function foo() {
@rafagarcia
rafagarcia / array_iteration_thoughts.md
Created January 16, 2017 08:16 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@rafagarcia
rafagarcia / make_writable.js
Created September 8, 2016 07:34 — forked from moehlone/make_writable.js
Make JavaScript readonly propertys writable (example for overwriting navigator.userAgent; useful for unit tests -> browser detection)
/**
* Creates a read/writable property which returns a function set for write/set (assignment)
* and read/get access on a variable
*
* @param {Any} value initial value of the property
*/
function createProperty(value) {
var _value = value;
/**
@rafagarcia
rafagarcia / .gitignore
Created July 29, 2016 06:48 — forked from jdsteinbach/.gitignore
Sass+PostCSS
node_modules