During a typical day, I would change to the main branch, pull the latest from the remote, delete the merged branches. Over and over all day, every day of the week. Now instead of all that checkout and pulling, I made a Git JERK!
Continue reading “Git Jerk”Category: Tech
Git -Xours -Xtheirs arguments
Git provides a helpful argument to prefer one branch or the other to “clobber” merge conflicts:
git merge main -Xours
git merge main -Xtheirs
I always get confused what the “X” means. I always assume “X” means mark which branch to clobber. Like “X” out their branch. Or “X” out our branch. Please wipe this mnemonic from your brain!
“X” means “PREFER”
“PREFER” the changes in their branch or “PREFER” the changes in our branch.
Jeez!
Links
Await Timeout
(async () => {
await new Promise(resolve => setTimeout(resolve, 500));
...
})();
Found on SO.
Extend URLSearchParams to object
There must be a reason this is a bad idea or it would be included in the API, right? 😅
URLSearchParams.prototype.toObject = function() {
return […this.keys()]
.reduce((o,k) => ({ …o, [k]: this.get(k) }), {});
}
Git Rollback Alias
Related to the Alias for Git sanity post from a few years back, recently added another to ~/.gitconfig
[alias]
revert-merge = !git revert -m 1 $1
rollback-merge = revert-merge
Where $1
is the commit hash. This only works for rollback of a merge commit on the main branch.
Deferred Promise
Found myself in a situation where I wanted to execute a process and then check back on it later to be sure it had completed.
class MyClass {
constructor() {
this.readyPromise = new Promise(
resolve => (this.readyResolve = resolve)
);
}
async executeProcesses() {
await // ...executing processes...
this.readyResolve();
}
ready() { return this.readyPromise }
}
Chrome extension with imports
To write a Chrome extension that allows ES6 imports
, imitate <script type="module">
with a dynamic import:
Chrome extension MV2 access to page data
Chrome extensions exist in an “isolated world” to prevent global var collisions between the website and the extension that runs on a given website. This mostly applies to content_scripts
in an extension.
E.g. window.foo
: my extension declares foo
in the global scope and the website the extension runs on also declares foo
in the global scope. With “isolated world” scoping for the extension, this is not a worry since it doesn’t share scope with the web page it runs on.
Comparison Formulae
Collecting performance metrics, I needed a way to compare optimization before/after numbers into some meaningful value that would impress the brass.
Continue reading “Comparison Formulae”Shell String Split
Having some trouble with this operation, found that you can use string replacement syntax to also split a string to array:
NPM_VER=$(npm -v) # 6.12.1
NPM_VER=(${NPM_VER//./ }) # Split on '.' as delimiter
echo "${NPM_VER[0]}" # 6
echo "${NPM_VER[1]}" # 12
echo "${NPM_VER[2]}" # 1