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 / .htaccess
Last active October 2, 2017 12:54
ЧПУ
RewriteEngine On
#Aokis Control
RewriteCond %{REQUEST_URI} (^/aokis/control)
RewriteRule aokis/control[/]?(.*)? /?rmid=260&route=%{REQUEST_URI}&%{QUERY_STRING} [L]
@Danilovonline
Danilovonline / mysql.sql
Created August 22, 2017 05:34
Enable mysql queries log
SET GLOBAL general_log = 1;# '0' for disable
SET GLOBAL log_output = 'table';
SELECT * FROM mysql.general_log order by event_time desc
@Danilovonline
Danilovonline / ModelTable.php
Created August 11, 2017 19:56
ZF2: order on fetchAll()
public function fetchAll()
{
$resultSet = $this->tableGateway->select(function ($select) {
$select->order('promocode');
});
return $resultSet;
}
@Danilovonline
Danilovonline / index.js
Last active October 6, 2017 06:34
JQUERY: ajax
$.ajax({
url: url,
type: 'POST',
data: {},
cache: false,
dataType: 'json',
processData: false, // Don't process the files
contentType: false, // Set content type to false as jQuery will tell the server its a query string request
success: function(data, textStatus, jqXHR)
{
@Danilovonline
Danilovonline / ModelTable.php
Created August 10, 2017 07:32
PDO: get one
$sql = "
select
v
from
table
where
id = :id
LIMIT 0, 1
";
$q = $this->pdo->prepare($sql);
@Danilovonline
Danilovonline / ModelTable.php
Last active August 10, 2017 07:42
PDO: get list
//$list = array();
$sql = "
select
* #fields
from
table
WHERE
id = :id
";
$query = $this->get('pdo')->prepare($sql);
@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];
}
}
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 / indexController.php
Created March 10, 2017 13:09
zf2: without layout output
public function indexAction() {
//...
$view = new ViewModel(array(
//...
));
$view->setTerminal(true);
return $view;
}
@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)
})();