Skip to content

Instantly share code, notes, and snippets.

View Danilovonline's full-sized avatar

Danilov Anatoly Danilovonline

  • Russia, Izhevsk
View GitHub Profile
@Danilovonline
Danilovonline / get_phones_from_page.js
Last active August 29, 2015 14:02
Поиск телефонов на странице
document.body.innerHTML.match(/((8|\+7)?[\- ]?)?(\(?\d{3,4}\)?[\- ]?)?[\d\- ]{4,8}[\d]{2}/g)
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
header("location:{$protocol}://_:_@{$_SERVER['SERVER_NAME']}");
echo '<pre>';
echo '<small>' . __FILE__ . "</small>\n";
print_r($VAR$);
echo '</pre>';
@Danilovonline
Danilovonline / gist:24189ba5fe8f1f1e85ce
Created October 9, 2014 10:41
Delete empty strings from text
$str = preg_replace( "#\s*?\r?\n\s*?(?=\r\n|\n)#s" , "" , $str );
@Danilovonline
Danilovonline / highlightFound
Created November 6, 2014 06:54
highlightFound
/**
* "Подсветка" найденного кода в тексте
*
* @param string $str
* @param string $search
*
* @return string
*/
function highlightFound($str, $search='')
{
@Danilovonline
Danilovonline / load_js.js
Last active February 8, 2017 06:47
Dynamic load JS file
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
var scheme = (document.location.href.indexOf('https://') === 0) ? 'https://' : 'http://';
s1.src = scheme + 'example.com/example.js';
s1.charset="UTF-8";
//s1.crossorigin="anonymous";
s0.parentNode.insertBefore(s1,s0);
})();
@Danilovonline
Danilovonline / load_css.js
Created February 8, 2017 06:47
Dynamic load CSS file
(function(){
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
var scheme = (document.location.href.indexOf('https://') === 0) ? 'https://' : 'http://';
fileref.setAttribute("href", scheme + 'example.com/example.css')
document.getElementsByTagName("head")[0].appendChild(fileref)
})();
@Danilovonline
Danilovonline / indexController.php
Created March 10, 2017 13:09
zf2: without layout output
public function indexAction() {
//...
$view = new ViewModel(array(
//...
));
$view->setTerminal(true);
return $view;
}
var oldFetch = fetch; // must be on the global scope
fetch = function(url, options) {
var promise = oldFetch(url, options);
//todo: action
console.log(url);
return promise;
}
@Danilovonline
Danilovonline / cross_browser_ajax.js
Last active December 1, 2020 14:04
Cross-browser AJAX(pure JS)
function httpRequest(url, method, data, success_callback, failure_callback) {
var xhr;
var data2 = [];
if (typeof data == 'object') {
for(var index in data) {
if (data.hasOwnProperty(index)) {
data2[data2.length] =index+'='+data[index];
}
}