Skip to content

Instantly share code, notes, and snippets.

View anvk's full-sized avatar
⌨️
coding my way through life

Alexey Novak anvk

⌨️
coding my way through life
View GitHub Profile
@anvk
anvk / promises_recursion.js
Created May 26, 2016 19:24
Sequential execution of Promises using Recursion
function asyncFunc(e) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(e), e * 1000);
});
}
const arr = [1, 2, 3];
function workMyCollection(arr, results = []) {
return new Promise((resolve, reject) => {
@anvk
anvk / promises_reduce.js
Last active October 11, 2023 09:02
Sequential execution of Promises using reduce()
function asyncFunc(e) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(e), e * 1000);
});
}
const arr = [1, 2, 3];
let final = [];
function workMyCollection(arr) {
@anvk
anvk / flac_to_mp3.sh
Last active May 26, 2016 19:25
Flac to MP3 converstion with FFMPEG
for a in *.flac; do
ffmpeg -i "$a" -qscale:a 0 "${a[@]/%flac/mp3}"
done
@anvk
anvk / subl.sh
Created October 21, 2015 17:58
Alias for Sublime 3
# For Windows
alias subl='/c/Program\ Files/Sublime\ Text\ 3/subl.exe'
@anvk
anvk / debounceN.js
Last active October 20, 2015 13:21
Execute function N times per threshold
/*
* func - function to be called
* threshold - time period in milliseconds
* N - how many function calls will be allowed to execute
*/
var debounceN = function(func, threshold, N) {
var counter = 0;
return function f() {
@anvk
anvk / debounce.js
Last active October 20, 2015 12:44
Execute function not often than wait time period
/*
* func - function you want to debounce
* wait - time period in milliseconds
* immediate - boolean if you want to execute function right away
*/
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
@anvk
anvk / my_bash.sh
Last active September 2, 2019 12:34
Tiny change quick rebase in GIT
# First set your git config to push only current branch
# This will change default behaviour of your GIT push command
# instead of pushing all changed branches from your local repo to the remote
# it will push ONLY your CURRENT branch you are on to the remote
git config --global push.default simple
# Add this alias to your ~/.bash_profile (OSX, Linux) or ~/.bashrc (Windows + Git Bash)
vim ~/.bash_profile
# If you have not setup your branch to track remote one. CUR_BRANCH is the name of the branch you are working with
@anvk
anvk / deep_extend_javascript_objects.js
Last active September 19, 2020 04:01
Deep Extend for Javascript Objects (my polyfill for _.merge() function)
/* MIT license
* 2015 Alexey Novak
*
* Inspired by http://youmightnotneedjquery.com/ with few of my own modifications
*
**/
var deepExtend = function(out) {
out = out || {};