Skip to content

Instantly share code, notes, and snippets.

@vitalymak
vitalymak / Node.js child_process examples.js
Last active November 24, 2015 10:45
Node.js child_process examples
'use strict';
const child_process = require('child_process');
const execCallback = (resolve, reject) => {
return (error, stdout, stderr) => {
stdout && console.log(stdout);
stderr && console.log(stderr);
error ? reject(new Error(error)) : resolve();
};
};
@vitalymak
vitalymak / bluebird-finally-tap.js
Last active April 30, 2016 11:28
Bluebird finally & tap difference
'use strict';
const Promise = require('bluebird'); // at least 3.3.5
const log = console.log.bind(console); // bind is safeguard for browser
Promise.resolve('value 1')
.tap(log) // value 1
.then(log)// value 1
.then(log)// undefined
.then(() => Promise.reject(new Error('reason 1')))
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

Is a useful one-liner which will give you the full directory name of the script no matter where it is being called from

These will work as long as the last component of the path used to find the script is not a symlink (directory links are OK). If you want to also resolve any links to the script itself, you need a multi-line solution:

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
@vitalymak
vitalymak / bluebird-coroutine.js
Last active September 21, 2016 14:34
Bluebird's coroutine example: using generators (yield) Promise.coroutine and Promise.coroutine.addYieldHandler
'use strict';
const Promise = require('bluebird');
let start = Date.now();
let promises = [1];
for (let i = 1; i <= 10; ++i) {
promises.push(() => new Promise(resolve => setTimeout(() => {
console.log(`#${i} completed in ${Date.now() - start}ms`);
resolve('Resolved value ' + i);
@vitalymak
vitalymak / gpr.sh
Last active July 14, 2016 12:52
git checkout to upstream PR (pull request) with fetching it first
function gpr {
eval "git fetch upstream +refs/pull/"$@"/head:refs/remotes/upstream/pr/"$@" && git checkout upstream/pr/"$@""
}
@vitalymak
vitalymak / yeld-for-of.js
Created July 18, 2016 12:00
ES6 generators: yield yield* for of difference
'use strict';
function* f1 () {
yield 'f1 yield #1';
yield 'f1 yield #2';
return 'f1 RETURN';
}
function* f2 () {
yield 'f2 yield #1';
@vitalymak
vitalymak / gist:98a6a77fdee8928b264799c5db9dbd12
Created July 26, 2016 10:57 — forked from tonymtz/gist:714e73ccb79e21c4fc9c
Uninstall XQuartz.app from OSX Yosemite
launchctl unload /Library/LaunchAgents/org.macosforge.xquartz.startx.plist
sudo launchctl unload /Library/LaunchDaemons/org.macosforge.xquartz.privileged_startx.plist
sudo rm -rf /opt/X11* /Library/Launch*/org.macosforge.xquartz.* /Applications/Utilities/XQuartz.app /etc/*paths.d/*XQuartz
sudo pkgutil --forget org.macosforge.xquartz.pkg
# Log out and log in
@vitalymak
vitalymak / el-captain.sh
Created August 12, 2016 10:04
How to install OS X El Captain on VirtualBox
# First download El Captain from App Store (Purchases tab)
# instructions provided by http://apple.stackexchange.com/a/211722
hdiutil attach "/Applications/Install OS X El Capitan.app/Contents/SharedSupport/InstallESD.dmg" -noverify -nobrowse -mountpoint /Volumes/esd
hdiutil create -o ElCapitan3.cdr -size 7316m -layout SPUD -fs HFS+J
hdiutil attach ElCapitan3.cdr.dmg -noverify -nobrowse -mountpoint /Volumes/iso
asr restore -source /Volumes/esd/BaseSystem.dmg -target /Volumes/iso -noprompt -noverify -erase
rm /Volumes/OS\ X\ Base\ System/System/Installation/Packages
cp -rp /Volumes/esd/Packages /Volumes/OS\ X\ Base\ System/System/Installation
cp -rp /Volumes/esd/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/
@vitalymak
vitalymak / bluebird-map-vs-all.js
Created August 24, 2016 13:22
Bluebird's promise map vs all difference
const Promise = require('bluebird');
const list = [300, 500, 400]
const getMapper = name =>
ms => Promise.delay(ms).then(() => console.log(`${name}: ${ms}ms done in ${Date.now() - start}`));
const start = Date.now();
Promise.map(list, getMapper('map, infinity concurrency'));
@vitalymak
vitalymak / disable-auto-android-file-transfer.md
Created September 8, 2016 19:06 — forked from zeroseis/disable-auto-android-file-transfer.md
Disable auto start for Android File Transfer
  • Close Android File Transfer
  • Open Activity Monitor and kill “Android File Transfer Agent”
  • Go to where you installed “Android File Transfer.app” (I have it under /Applications)
  • Ctrl+click –> “Show package contents”
  • Go to Contents/Resources
  • Rename “Android File Transfer Agent” to e.g. “Android File Transfer Agent_DISABLED”
  • Then go to “/Users/username/Library/Application Support/Google/Android File Transfer” and again rename the Agent app.