Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / pow-mod.js
Last active June 7, 2017 10:34
Power by module
function powMod(num, pow, mod) {
let res = 1;
for (let i = 0; i < pow; ++i) {
res = res * num % mod;
}
return res;
}
@vitalymak
vitalymak / git-push-without-pre-push-hook.sh
Created July 25, 2017 17:01
Git push without pre-push hook
function evalprint {
printf "\e[0;92m%s\n\n\e[0m" "$@"
eval "$@"
}
function gp {
local args=$(echo "$@")
evalprint "git push --no-verify $args; git status;"
}
__git_complete gp _git_push
@vitalymak
vitalymak / kill-gpg-agent.sh
Created July 26, 2017 09:25
Kill gpg-agent
gpgconf --kill gpg-agent
# You shouldn’t need to manually restart it. GPG will restart it when it’s needed.
@vitalymak
vitalymak / CorsProxy.swift
Created December 4, 2017 12:04 — forked from sciolist/CorsProxy.swift
GCDWebServer Cors proxy
import GCDWebServer
class CorsProxy {
init(webserver : GCDWebServer!, urlPrefix: String) {
var prefix =
(urlPrefix.hasPrefix("/") ? "" : "/")
+ urlPrefix
+ (urlPrefix.hasSuffix("/") ? "" : "/")
let pattern = "^" + NSRegularExpression.escapedPatternForString(prefix) + ".*"
@vitalymak
vitalymak / Git commit editior
Created June 26, 2018 17:28 — forked from S3ak/Git commit editior
How to set git commit editor to sublime
Method 1
git config --global core.editor "'c:/program files/sublime text 3/sublime_text.exe' -w"
Method 2
git config --global core.editor "subl -n -w"
Method 3
$ echo 'alias subl="/cygdrive/c/Program\ Files/Sublime\ Text\ 3/sublime_text.exe"' >> ~/.bashrc
@vitalymak
vitalymak / .profile
Created November 3, 2019 11:58 — forked from bmhatfield/.profile
Automatic Git commit signing with GPG on OSX
# In order for gpg to find gpg-agent, gpg-agent must be running, and there must be an env
# variable pointing GPG to the gpg-agent socket. This little script, which must be sourced
# in your shell's init script (ie, .bash_profile, .zshrc, whatever), will either start
# gpg-agent or set up the GPG_AGENT_INFO variable if it's already running.
# Add the following to your shell init to set up gpg-agent automatically for every shell
if [ -f ~/.gnupg/.gpg-agent-info ] && [ -n "$(pgrep gpg-agent)" ]; then
source ~/.gnupg/.gpg-agent-info
export GPG_AGENT_INFO
else