Skip to content

Instantly share code, notes, and snippets.

View umidjons's full-sized avatar
🏠
Working from home

Umid umidjons

🏠
Working from home
View GitHub Profile
@umidjons
umidjons / htmlspecialchars.php
Created July 4, 2013 04:49
Accept form values safer with htmlspecialchars()
<?php
$someValue = isset( $_REQUEST[ 'VALUE' ] ) ? htmlspecialchars( $_REQUEST[ 'VALUE' ], ENT_QUOTES, 'utf-8' ) : '';
?>
@umidjons
umidjons / regexp_notepad.txt
Created July 5, 2013 07:38
RegExp Tips in Notepad++
# Put '); before EOL
# CTRL+H, Regular Expression is checked
Find what: (\r\n)
Replace with: '\);\1
# Put INSERT INTO table VALUES( before every digits at the beginning of the line
Find what: ^(\d+)
Replace with: INSERT INTO table VALUES\(\1
@umidjons
umidjons / conv_5num_to_date.sql
Created July 5, 2013 11:08
Convert (Excel date) 5 digit numbers to date in mysql
SELECT
iar_d AS date_5_num, /* numbers like: 40479, 40298, 39038, 41075 */
DATE('1899-12-30') + INTERVAL iar_d DAY AS normal_date /* converted dates */
FROM registry_private_clinics
WHERE iar_d REGEXP '^[0-9]{5}$' /* only rows with NNNNN format, where N is [0-9] */
@umidjons
umidjons / str_to_date.sql
Created July 5, 2013 11:36
Convert date string to date and insert into another table For example, string '14.03.2013' becomes '2013-03-14' date.
INSERT INTO other_table (num, c_date)
SELECT lic_num, STR_TO_DATE(lic_date,'%d.%m.%Y') /* converts date from %d.%m.%Y to %Y-%m-%d format */
FROM my_table
@umidjons
umidjons / split_string_substring_index_mysql.sql
Created July 6, 2013 06:00
Split string in MySQL with SUBSTRING_INDEX( str, delim, count ) Convert string to mysql date with STR_TO_DATE( str, format )
SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2); /* 'www.mysql' */
SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2); /* 'mysql.com' */
/* split by 'ва' case-insensetively, and convert last date value to mysql date */
SELECT STR_TO_DATE(SUBSTRING_INDEX(LOWER('30.11.2010 ва 01.11.2011'),'ва',-1),'%d.%m.%Y'); /* '2011-11-01' */
@umidjons
umidjons / bx_page_window_size.php
Created July 6, 2013 07:52
Bitrix Framework: Change pagination items count in navigation bar.
<?php
// By default navigation bar looks like this:
// Начало | Пред. | 1 2 3 4 5 6 7 8 9 10 | След. | Конец | Все
$result->nPageWindow = 5; // CDBResult object
// Now navigation bar looks like this:
// Начало | Пред. | 1 2 3 4 5 | След. | Конец | Все
@umidjons
umidjons / bx_current_site_date_time_format.php
Created July 8, 2013 05:12
Bitrix: Get current site's date and time formats
<?
// выводит текущую дату в формате текущего сайта
echo date($DB->DateFormatToPHP(CSite::GetDateFormat("SHORT")), time());
// Возвращает формат времени, указанный в настройках сайта.
echo $GLOBALS["DB"]->DateFormatToPHP( CSite::GetTimeFormat() );
?>
@umidjons
umidjons / bx_dialog_box.php
Last active October 2, 2019 07:50
Bitrix Dialog box example more on that here: http://alexvaleev.ru/popup-window-bitrix/
<?
CUtil::InitJSCore( array( 'window' ) ); // load Bitrix's window library
$APPLICATION->AddHeadScript( '/js/jquery.min.js' ); // load jQuery
?>
<? ob_start(); // start capturing HTML output ?>
<p>Some HTML content...</p>
<?
$content = ob_get_contents(); // save output info variable
$content = str_replace( array( "\n", "\r" ), '', $content ); // remove EOL-s - content: attribute of the BX.CDialog() requires that!
@umidjons
umidjons / current_url.js
Last active June 21, 2018 17:24
Get current URL/path in javascript (without domain)
jQuery(document).ready(function(){
var path = window.location.pathname;
var pathName = path.substring(0, path.lastIndexOf('/') + 1);
console.log(path); // get current path, for ex: '/index.php', '/docs/pdf/detail.php'
console.log(pathName); // for ex: '/index.php'=>'/', '/docs/pdf/detail.php'=>'/docs/pdf/'
});
@umidjons
umidjons / Regexp_on_the_fly__Change_state.js
Created July 11, 2013 11:12
* Change state programmatically with trigger() // hover, focus, active, visited * Build reqular expression on the fly
jQuery(document).ready(function () {
var myElem = $('a.myClass'),
txt="hello",
longText="some very very long text with /hello/world/, wow",
pattern = '\/' + txt + '\/',// build regexp pettern on the fly, pattern=/\/hello\//
rx = new RegExp(pattern, 'i'); // create regexp object
if (rx.test(longText)) { // test - is there /hello/ in longText?
myElem.trigger('hover'); // if there is, change state of the <a class"myClass"> to <a class"myClass:hover">
}
});