Skip to content

Instantly share code, notes, and snippets.

@vitalymak
vitalymak / difference_between_reference_and_pointer.cpp
Last active June 3, 2017 17:18
The difference between a reference and a pointer C++
// Difference between a pointer and a reference in C++
// http://cpp.sh/64ahf
#include <iostream>
int main()
{
int a = 123;
int b = 456;
int & ra = a; // reference, also "int &ra = a;
@vitalymak
vitalymak / utils.sh
Last active May 19, 2017 14:49
Bash: search files by extension, without extension etc.
find . -name *.jpg # find all *.jpg files
find . -type f -name '*.*' | sed 's|.*\.||' | sort -u # find all unique file extensions
find . -type f ! -name "*.*" # find all files without extensions
find . -type f ! -name "*.*" | sed 's!.*/!!' | sort -u # find all unique file names without extension
@vitalymak
vitalymak / atime.sh
Last active May 18, 2017 11:16
macOS get average time for 10 command runs, using coreutils/date and node
atime() {
local times=()
local start end total
for i in {1..10}; do
start=$(/usr/local/opt/coreutils/libexec/gnubin/date +%s%N)
"$@" >/dev/null 2>&1
end=$(/usr/local/opt/coreutils/libexec/gnubin/date +%s%N)
total=$(expr $end - $start)
times+=( $total )
@vitalymak
vitalymak / process_env_info.sh
Created May 15, 2017 11:13
env vars of running process Linux & macOS
ps -p <PID> -wwwE
# or
ps -p <PID> -wwwe
# more info https://serverfault.com/questions/66363/environment-variables-of-a-running-process-on-unix
@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
@vitalymak
vitalymak / adb_over_wifi.md
Last active May 30, 2017 18:06
adb over wifi
@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 / 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 / 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 / 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