Skip to content

Instantly share code, notes, and snippets.

@mrLexx
mrLexx / CodeLineNumber
Created February 6, 2014 02:07
Код с номерами строк. 1. Номера могут начинаться с какого угодно числа, могут разрываться, могут быть не числами (например, ... для обозначения того, что часть кода не приводится). 2. Номера не должны копироваться. 3. Длинные строки должны переноситься.
<style type="text/css">
.code {
font-family: Consolas, "Liberation Mono", Courier, monospace;
border-collapse: collapse;
line-height: 18px;
font-size: 13px;
}
.code th {
color: #333;
@mrLexx
mrLexx / Vagrantfile
Last active March 8, 2017 16:03
PuPHPet Integration with hostsupdater
Vagrant.configure("2") do |config|
## Begin vagrant-hostsupdater
## https://github.com/cogitatio/vagrant-hostsupdater
## vagrant plugin install vagrant-hostsupdater
if Vagrant.has_plugin?("vagrant-hostsupdater") && configValues['apache']['install'] == '1'
config.hostsupdater.remove_on_suspend = true
config.hostsupdater.aliases = Array.new
configValues['apache']['vhosts'].each do |i, host|
@mrLexx
mrLexx / rotate_array.php
Created April 29, 2014 23:46
PHP: Rotate array
<?php
$keys = array_keys($arr);
$val = $arr[$keys[0]];
unset($arr[$keys[0]]);
$arr[$keys[0]] = $val;
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
@mrLexx
mrLexx / gist:9422bbc5a116503b37bfd23b82c5fc3b
Created July 12, 2019 04:08
vagrant host 504 error, долго загружаются проекты vagrant.
sudo nano /etc/php/5.6/fpm/pool.d/www.conf
ps -ef | grep fpm
@mrLexx
mrLexx / bot_detect.php
Created November 13, 2019 06:15
обнаружение ботов
<?php
//http://qaru.site/questions/60076/how-to-detect-search-engine-bots-with-php
if (preg_match('/bot|crawl|curl|dataprovider|search|get|spider|find|java|majesticsEO|google|yahoo|teoma|contaxe|yandex|libwww-perl|facebookexternalhit/i', $_SERVER['HTTP_USER_AGENT'])) {
// is bot
}
if (preg_match('/apple|baidu|bingbot|facebookexternalhit|googlebot|-google|ia_archiver|msnbot|naverbot|pingdom|seznambot|slurp|teoma|twitter|yandex|yeti/i', $_SERVER['HTTP_USER_AGENT'])) {
// allowed bot
}

Detect google and yandex search bots (crawl, spider)

function detectSearchBot($ip, $agent, &$hostname)
{
    $hostname = $ip;

    // check HTTP_USER_AGENT what not to touch gethostbyaddr in vain
    if (preg_match('/(?:google|yandex)bot/iu', $agent)) {
 // success - return host, fail - return ip or false
@mrLexx
mrLexx / first_last_day.sql
Created April 16, 2020 11:06
First and Last day of month on mysql
select DATE_FORMAT(now(),'%Y-%m-01'),LAST_DAY(now());
@mrLexx
mrLexx / mysql_gen_pass.sql
Last active June 4, 2020 01:01
Generate a random string in MySQL
SELECT SUBSTRING(REPLACE(REPLACE(REPLACE( TO_BASE64(MD5(RAND())), '=',''),'+',''),'/',''), 2, 8);
SELECT SUBSTRING(REPLACE(REPLACE(REPLACE( TO_BASE64(MD5(RAND())), '=',''),'+',''),'/',''), 2, FLOOR(10+RAND()*31));
@mrLexx
mrLexx / git_update.sh
Created April 15, 2021 06:18
git update
sudo add-apt-repository ppa:git-core/ppa -y
sudo apt-get update
sudo apt-get install git -y
git --version