Skip to content

Instantly share code, notes, and snippets.

View DmitriyWebDev's full-sized avatar

Dmitriy Gavrilov DmitriyWebDev

View GitHub Profile
@DmitriyWebDev
DmitriyWebDev / wordpress.different-langauges.php
Created October 3, 2017 11:16 — forked from scarstens/wordpress.different-langauges.php
Setup different languages for WordPress admin and front end
// setup one language for admin and the other for theme
// must be called before load_theme_textdomain()
function set_my_locale($locale) {
$locale = ( is_admin() ) ? "en_US" : "it_IT";
setlocale(LC_ALL, $local );
return $locale;
}
add_filter( 'locale', 'set_my_locale' );
@DmitriyWebDev
DmitriyWebDev / permutations.js
Created October 4, 2017 17:28 — forked from wassname/permutations.js
Combinatorics permutatons and product in javascript using lodash.js (like python's itertools)
/**
* Lodash mixins for combinatorics
* Inspired by python itertools: https://docs.python.org/2.7/library/itertools.html
*
* Usage:
* permutations([0,1,2],2) // [[0,1],[0,2],[1,0],[1,2],[2,0],[2,1]]
* combinations([0,1,2],2) // [[0,1],[0,2],[1,2]]
* combinations_with_replacement([0,1,2],2)// [[0,0],[0,1],[0,2],[1,1],[1,2],[2,2]]
* product([0,1,2],[0,1,2]) // [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]]
*
@DmitriyWebDev
DmitriyWebDev / getMinAgeDateWithMomentJs.js
Created July 21, 2018 10:20
Get the date with the minimum age using the Moment.js library
const dates = ["2018-07-01", "2018-02-01", "2017-01-01", "2015-07-19", "2010-07-19"];
getMinAgeDateWithMomentJs(dates); // return "2018-07-01"
function getMinAgeDateWithMomentJs(dates = []) {
if( !dates.length || typeof moment === 'undefined' ) {
console.log( 'getMinAgeDate(), invalid argument or moment.js is undefined' );
return false;
@DmitriyWebDev
DmitriyWebDev / getDateDifferenceWithCurrentDateByUsingMomentJs.js
Created July 21, 2018 10:35
Get the difference in date with the current date using the Moment.js library
const someDate = "2018-05-21";
const differenceWithCurrentDate = getDateDifferenceWithCurrentDate( someDate );
// if today "2018-07-21" ( for example )
// differenceWithCurrentDate = {
// type: 'months',
// count: 2
// }
@DmitriyWebDev
DmitriyWebDev / fade.js
Created July 28, 2018 18:34 — forked from alirezas/fade.js
fadeIn & fadeOut in vanilla js
function fadeOut(el){
el.style.opacity = 1;
(function fade() {
if ((el.style.opacity -= .1) < 0) {
el.style.display = "none";
} else {
requestAnimationFrame(fade);
}
})();
@DmitriyWebDev
DmitriyWebDev / jquery-scroll-bottom.js
Created August 4, 2018 11:22 — forked from toshimaru/jquery-scroll-bottom.js
Detect the scrolling to bottom of the page using jQuery.
$(window).on("scroll", function() {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
// when scroll to bottom of the page
}
});
@DmitriyWebDev
DmitriyWebDev / protips.js
Created December 9, 2018 19:29 — forked from nolanlawson/protips.js
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
@DmitriyWebDev
DmitriyWebDev / git-change-commit-messages.md
Created January 13, 2019 18:52 — forked from nepsilon/git-change-commit-messages.md
How to change your commit messages in Git? — First published in fullweb.io issue #55

How to change your commit messages in Git?

At some point you’ll find yourself in a situation where you need edit a commit message. That commit might already be pushed or not, be the most recent or burried below 10 other commits, but fear not, git has your back 🙂.

Not pushed + most recent commit:

git commit --amend

This will open your $EDITOR and let you change the message. Continue with your usual git push origin master.

@DmitriyWebDev
DmitriyWebDev / chat-frontend.js
Created March 12, 2019 17:15 — forked from martinsik/chat-frontend.js
Node.js chat frontend and server
$(function () {
"use strict";
// for better performance - to avoid searching in DOM
var content = $('#content');
var input = $('#input');
var status = $('#status');
// my color assigned by the server
var myColor = false;
@DmitriyWebDev
DmitriyWebDev / javascript.translit.js
Created March 26, 2019 07:56 — forked from croisillon/javascript.translit.js
JavaScript translater russian to translit
function rus_to_latin ( str ) {
var ru = {
'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd',
'е': 'e', 'ё': 'e', 'ж': 'j', 'з': 'z', 'и': 'i',
'к': 'k', 'л': 'l', 'м': 'm', 'н': 'n', 'о': 'o',
'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u',
'ф': 'f', 'х': 'h', 'ц': 'c', 'ч': 'ch', 'ш': 'sh',
'щ': 'shch', 'ы': 'y', 'э': 'e', 'ю': 'u', 'я': 'ya'
}, n_str = [];