Skip to content

Instantly share code, notes, and snippets.

@vitalymak
vitalymak / try-catch-vs-try-catcher.js
Created September 11, 2016 16:54
JavaScript try-catch vs try-cather wrapper
'use strict';
const ITERATIONS = 10000000;
const ERROR = new Error('Test error');
function tryCatcher(fn, ctx, args) {
try {
return fn.apply(ctx, args);
}
catch(err) {
@vitalymak
vitalymak / how_to.sh
Last active September 19, 2016 14:07
OS X macOS make diff work like git diff
brew update
brew install colordiff
# modify ~/.bash_profile
function diff {
colordiff -u "$@"
}
# sample usage:
# diff file1 file2
@vitalymak
vitalymak / hidden-classes-in-js-and-inline-caching.md
Created September 21, 2016 20:27 — forked from twokul/hidden-classes-in-js-and-inline-caching.md
Hidden classes in JavaScript and Inline Caching

Hidden classes in JavaScript and Inline Caching

Knowing how internals work is always a good. Pretty much for everything. Cars, trains, computers, you name it. It gives you an insight on what happens under the hood. You also act/react differently based on this knowledge.

As you might have guessed, it’s also true for web development. Knowledge of CSS transitions allows you to achieve better performance and not to use JavaScript in most cases. Knowledge of V8 internals allows you to write more performant JavaScript code. So let’s talk about V8 a little.

A little about V8

V8 is a JavaScript engine built by Google. Firefox built SpiderMonkey, Opera built Carakan and Microsoft built Chakra. One very important difference between V8 and other JavaScript engines is that V8 doesn’t generate any intermediate code. It compiles JavaScr

@vitalymak
vitalymak / gist:28fba012dd72d82d20476cf78717424a
Created October 3, 2016 15:38 — forked from stuart11n/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@vitalymak
vitalymak / spawn-nvm-node.sh
Last active November 15, 2016 11:26
Fork spawn/exec new instance of node difference
#!/usr/bin/env bash
. ~/.nvm/nvm.sh
nvm install 4.6.2 >/dev/null 2>&1
nvm install 6.9.1 >/dev/null 2>&1
echo 'console.log("Forked child: " + process.version)' > to-fork.js
# prints v6.9.1
@vitalymak
vitalymak / dir_sizes.sh
Created January 24, 2017 09:46
dir_sizes macOS using coreutils
# 1) first install coreutils
brew install coreutils
# 2) but!!! let them do not replace internal macOS utils by modifying PATH check your ~/.bash_profile
# that you include brew sbin & coreutils AFTER internal /usr/bin etc.
export PATH=$PATH:/usr/local/sbin # but NOT!!!: export PATH=/usr/local/sbin:$PATH
export PATH=$PATH:/usr/local/opt/coreutils/libexec/gnubin
# 3) add it to your ~/.bash_profile
function dir_sizes {
@vitalymak
vitalymak / git-push-example.sh
Created January 26, 2017 13:38
git push to remote branch with a different name
git push origin local-name:remote-name
@vitalymak
vitalymak / promise-all-wait.js
Last active February 14, 2017 10:30
Promise.all with wait all.
errors = [];
var promises = [
Promise.reject(new Error('Rejects immediately!')),
new Promise((resolve) => setTimeout(resolve, 5000)).then(() => 'Resolved after 5 seconds!')
];
promises = promises.map((promise, i) => promise.catch(error => {
errors[i] = error;
}));
@vitalymak
vitalymak / adb_over_wifi.md
Last active May 30, 2017 18:06
adb over wifi
@vitalymak
vitalymak / macos-virtualbox-without-menu.md
Last active April 18, 2017 13:33
VirtualBox on macOS host - hide macOS menu in a VM's fullscreen mode