Skip to content

Instantly share code, notes, and snippets.

@codingfox-rus
codingfox-rus / py
Created July 7, 2022 18:50
pre-push hook
#!/usr/bin/python3
import subprocess
import re
task_pattern = 'DDD\-\d+'
# Получаем в выводе только текущую ветку
current_branch = subprocess.check_output(['git', 'symbolic-ref', '--short', 'HEAD']).decode().strip()
curr_branch_parts = current_branch.split('/')
curr_branch_key = None
$numArr = [];
$numArr[] = rand(1000, 9999);
$numArr[] = rand(1000, 9999);
$numArr[] = rand(1000, 9999);
$numArr[] = rand(1000, 9999);
echo implode('', $numArr) . PHP_EOL;
<?php
mb_internal_encoding("UTF-8");
mb_regex_encoding('UTF-8');
$logPath = '';
$dbh = new PDO('mysql:host=localhost;dbname=log', 'root', 'password');
$handle = @fopen($logPath, "r");
@codingfox-rus
codingfox-rus / passgen.php
Created September 14, 2018 10:28
Генерация паролей в Codeigniter 3
<?php
function get_password_hash($password)
{
$options = [
'salt' => random_string('alnum', 30),
'cost' => 10
];
return password_hash($password, PASSWORD_BCRYPT, $options);
}
<?php
$html = '<div><img alt="" src="http://example.com/" alt="test"></div>';
$imgPattern = '/<img\s(.*)\/?>/U';
preg_match_all($imgPattern, $html, $matches, PREG_SET_ORDER);
$uId = 1;
foreach ($matches as $match) {
$img = trim($match[0]);
$attrContent = trim($match[1]);
@codingfox-rus
codingfox-rus / google-docs-to-html-fix.php
Last active February 6, 2018 12:11
Фикс при переводе дока из Google Docs в Html, для сохранения в БД через визуальный редактор (он режет некоторые теги)
<?php
$html = file_get_contents('index.html');
$cssPattern = '/\.(c[0-9]+)\{(.*)\}/U';
preg_match_all($cssPattern, $html, $cssMatches, PREG_SET_ORDER);
$classPattern = '/\sclass=\"([A-Za-z0-9\s]+)\"/U';
preg_match_all($classPattern, $html, $classMatches, PREG_SET_ORDER);
foreach ($classMatches as $clMatch){
@codingfox-rus
codingfox-rus / pdo_example.php
Last active September 28, 2017 11:48
Образец соединения через PDO
<?php
$host = '';
$db = '';
$user = '';
$pass = '';
$charset = 'utf8';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
@codingfox-rus
codingfox-rus / slice_array_of_sequences.php
Last active December 15, 2016 06:18
Алгоритм для разбиения массива по последовательностям чисел
<?php
$arr = [2,3,4,8,9,10,14,15,16,20,21,22];
// Вычисляем "пропуски" - индексы массива, на которых последовательность прерывается
$skips = [];
$start = $arr[0];
for ($i = 1; $i < sizeof($arr); $i++) {
if (($arr[$i] - $start) > 1) {
$skips[] = $i;
}
@codingfox-rus
codingfox-rus / upload.php
Created August 2, 2015 13:14
Загрузчик картинок для CKEditor
<?php
function getex($filename) {
return end(explode(".", $filename));
}
if($_FILES['upload']) {
if (($_FILES['upload'] == "none") || (empty($_FILES['upload']['name'])) ) {
$message = "Вы не выбрали файл";
} else if ($_FILES['upload']["size"] == 0 || $_FILES['upload']["size"] > 2050000) {
@codingfox-rus
codingfox-rus / validate_mobile_phone_number.php
Last active December 15, 2016 06:22
Валидация мобильного телефонного номера
<?php
/**
* @param $phone
* @return bool
*/
public function correctPhone($phone)
{
$phone = preg_replace('/[^0-9]/', '', trim($phone));
preg_match('/9[0-9]{9,9}/', $phone, $result);