Skip to content

Instantly share code, notes, and snippets.

View gerasimua's full-sized avatar
💭
Reactive waiting

Alexander gerasimua

💭
Reactive waiting
View GitHub Profile
@gerasimua
gerasimua / gist:7fd56202ff05452ffe49
Created October 28, 2014 12:05
Update param in query string
<?php
$qs = $_SERVER['QUERY_STRING'];
$ru = $_SERVER['REQUEST_URI'];
if($qs){
$ru = str_replace('?' . $qs, '', $ru);
$params = array();
parse_str($qs, $params);
$params['page'] = '%d';
$paramsPairs = array();
@gerasimua
gerasimua / gist:d5b568e340349a7f5208
Created October 15, 2014 14:19
Mongo autoincrement field
<?php
$func = new MongoCode(
'function insertDocument(doc, targetCollection) {
targetCollection = db[targetCollection];
var cursor = targetCollection.find( {}, { _id: 1 } ).sort( { _id: -1 } ).limit(1);
var seq = cursor.hasNext() ? cursor.next()._id + 1 : 1;
doc._id = NumberInt(seq);
var results = targetCollection.insert(doc);
return doc._id;
}'
@gerasimua
gerasimua / gist:8d74f8491a803170d7a1
Created October 14, 2014 15:52
Prevent send form by pressing enter
$('body').on("keyup keypress", '#addAds', function(e) {
var code = e.keyCode || e.which;
if (code == 13) {
e.preventDefault();
e.stopPropagation();
return false;
}
});
@gerasimua
gerasimua / gist:bacc3d1dd24cd22b3625
Created August 19, 2014 15:32
Ajax login check on ajax
$(function(){
$.ajaxPrefilter(function(options, _, jqXHR) {
jqXHR.success(function(data) {
if(data.indexOf('SOMEONSWER') != -1){
document.body.innerHTML = '';
window.location.pathname = '/LOGINURL';
}
});
});
});
@gerasimua
gerasimua / gist:99edc3ae3324ebd4a29c
Created August 15, 2014 17:07
PreAjax for check session expiration
$(function(){
$.ajaxPrefilter(function(options, _, jqXHR) {
jqXHR.success(function(data) {
try{
//return data with json in string if expired session
var jsonData = JSON.parse(data);
if(jsonData.message && (jsonData.message == 'autherror')){
//jqXHR.abort() - didn't work
document.body.innerHTML = '';
window.location = '/site_login';
function getInternetExplorerVersion()
{
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
@gerasimua
gerasimua / gist:3ac8da5fc9f8348d4763
Last active August 29, 2015 14:05
Maintenance with exceptions by IP
SetEnv APPLICATION_ENV development
Options +FollowSymlinks
Options -Indexes
<IfModule mod_rewrite.c>
RewriteBase /
RewriteEngine On
@gerasimua
gerasimua / gist:16a7004407e5220eccda
Created August 8, 2014 09:19
Z-index of YouTube video in IE
//Fix z-index youtube video embedding
$('iframe').each(function(){
var url = $(this).attr("src");
if(url){
var separator = (url.indexOf('?') > 0) ? '&' : '?';
$(this).attr('src', url + separator + 'wmode=transparent');
$(this).attr("wmode", 'Opaque');
}
});
@gerasimua
gerasimua / gist:3bb149928ed4bdb38656
Created August 6, 2014 15:01
IE check from css-tricks.com
var isMSIE = /*@cc_on!@*/0;
if (isMSIE) {
// do IE-specific things
} else {
// do non IE-specific things
}
@gerasimua
gerasimua / gist:fddffafaf5cba3e3d3c1
Created July 24, 2014 15:47
IE version detection
var IE = (function () {
"use strict";
var ret, isTheBrowser,
actualVersion,
jscriptMap, jscriptVersion;
isTheBrowser = false;
jscriptMap = {
"5.5": 5.5,