Skip to content

Instantly share code, notes, and snippets.

View peacefulseeker's full-sized avatar

Alexey Vorobyov peacefulseeker

  • Riga
View GitHub Profile
@peacefulseeker
peacefulseeker / jQuery_copyOnClick.js
Last active November 27, 2017 15:48
jQuery - Copy with JS on element click(Works well for pre + code tags)
/* Works well on pre + code tags. */
function copySelected() {
return document.execCommand('copy');
}
$("#element").on("click", function () {
setTimeout(function (argument) {
copySelected();
}, 100);
});
@peacefulseeker
peacefulseeker / jQuery_gcSmoothScroll.js
Last active November 27, 2017 15:48
jQuery - Google Chrome Smooth Scrolling
/* One line script, that is responsible for google chrome detection and adding smooting to it's scroll */
(function(e){e.extend({browserSelector:function(){var e=navigator.userAgent,t=e.toLowerCase(),n=function(e){return t.indexOf(e)>-1},r="gecko",i="webkit",s="safari",o="opera",u=document.documentElement,a=[!/opera|webtv/i.test(t)&&/msie\s(\d)/.test(t)?"ie ie"+parseFloat(navigator.appVersion.split("MSIE")[1]):n("firefox/2")?r+" ff2":n("firefox/3.5")?r+" ff3 ff3_5":n("firefox/3")?r+" ff3":n("gecko/")?r:n("opera")?o+(/version\/(\d+)/.test(t)?" "+o+RegExp.jQuery1:/opera(\s|\/)(\d+)/.test(t)?" "+o+RegExp.jQuery2:""):n("konqueror")?"konqueror":n("chrome")?i+" chrome":n("iron")?i+" iron":n("applewebkit/")?i+" "+s+(/version\/(\d+)/.test(t)?" "+s+RegExp.jQuery1:""):n("mozilla/")?r:"",n("j2me")?"mobile":n("iphone")?"iphone":n("ipod")?"ipod":n("mac")?"mac":n("darwin")?"mac":n("webtv")?"webtv":n("win")?"win":n("freebsd")?"freebsd":n("x11")||n("linux")?"linux":"","js"];c=a.join(" ");u.className+=" "+c}})})(jQuery);(func
@peacefulseeker
peacefulseeker / jQuery_scrollToElement.js
Last active November 27, 2017 16:09
jQuery - Smooth Scrolling to Element
(function($) {
$("a[href^='#']")
.not('[href="#"]')
.not('[href="#0"]')
.on('click', function ( event ) {
event.preventDefault();
var $scrollTarget = $( $(this).attr('href') );
$scrollTarget = $scrollTarget.length ? $scrollTarget : $('[name="' + $(this).attr('href').slice(1) + '"]');
/* If not found stop execution */
if ( !$scrollTarget.length ) return;
@peacefulseeker
peacefulseeker / SQL_replace-data-sql-query-wordpress.sql
Last active November 27, 2017 16:24
WordPress - Replace data within WordPress Database
-- Define the repeating string to replace in database table, as well as the string that should be replaced by.
-- SET @what_to_be_replaced = "http://dev.sehner.international", @to_be_replaced_by = "https://sehner.international";
SET @what_to_be_replaced = "https://www.pflegemarkt.com", @to_be_replaced_by = "http://dev.pflegemarkt.com";
-- Update every table columns that usually contains wrong domain(local development or dev version of website)
-- You should provide collation of table as well for the following tables, otherwiser it will throw the error, usually it is COLLATE utf8mb4_general_ci.
-- THESE ARE DEFAULT TABLES OF WORDPRESS
UPDATE pm_commentmeta SET meta_value = REPLACE(meta_value, @what_to_be_replaced, @to_be_replaced_by );
UPDATE pm_comments SET comment_content = REPLACE(comment_content, @what_to_be_replaced ,@to_be_replaced_by);
@peacefulseeker
peacefulseeker / .htaccess_wp_memory_limit_curl_timout
Last active November 27, 2017 16:19
WordPress - wp-config.php define WordPress Memory Limit and cURL Temout
/* WordPress Memory Limit */
define('WP_MEMORY_LIMIT', '256M');
/* cURL Timeout */
ini_set('default_socket_timeout', '300');
@peacefulseeker
peacefulseeker / JavaScript_getSelected.js
Last active November 27, 2017 16:24
JavaScript - return the current selection
function getSelected() {
if (window.getSelection) {
return window.getSelection().toString();
} else if (document.getSelection) {
return document.getSelection().toString();
} else {
var selection = document.selection && document.selection.createRange();
if (selection.text) {
return selection.text.toString();
}
@peacefulseeker
peacefulseeker / jQuery_InfiniteScrollDown_OnajaxComlplete.js
Last active November 27, 2017 16:21
jQuery - Infinite Scroll Down on dynamic ajax content loaded
/* Test here: http://www.meinpraktikum.de/praktikum/suchen?utf8=%E2%9C%93&q=&location=*/
(function( $ ) {
$(document).ajaxComplete(function(){
$("html, body").animate({ scrollTop: $(document).height() }, "slow");
console.log($(".search-result-vacancies-box").length);
})
})(jQuery);
@peacefulseeker
peacefulseeker / .htaccess_rewrite_folder_in_url
Last active November 27, 2017 15:47
Htaccess rewrite folder path and redirect
<IfModule mod_rewrite.c>
# IMPORTANT TO PLACE IT BEFORE OTHER REWRITE RULES. REDIRECTS ONE FOLDER PATH TO ANOTHER
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^produkte/(.*)$ /pm_produkte/$1 [L,NC,R=302]
</IfModule>
@peacefulseeker
peacefulseeker / .htaccess_https_and_www_force
Last active November 30, 2017 13:31
Htaccess HTTPS and WWW. force in URL
# Taken from here : https://simonecarletti.com/blog/2016/08/redirect-domain-http-https-www-apache/
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
@peacefulseeker
peacefulseeker / php_dumper.php
Last active November 27, 2017 16:19
PHP - Dumper by Koterov Dmitriy
<?php ## Функция для вывода содержимого переменной.
// Распечатывает дамп переменной на экран.
function dumper( $obj ) {
echo
"<pre>",
htmlspecialchars( dumperGet( $obj ) ),
"</pre>";
}
// Возвращает строку - дамп значения переменной в древовидной форме