Skip to content

Instantly share code, notes, and snippets.

@fomigo
fomigo / is_ajax.php
Created January 13, 2012 18:50
How to know it's an ajax request
<?php
$ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
@fomigo
fomigo / email_string_parsing.php
Created January 13, 2012 18:54
Example of parsing strings of emails
<?php
$string = 'first@mail.ru=From first||second@mail.ru=From second';
$mails = explode('||', $string);
$to = array();
foreach ($mails as $mail) {
list($key, $value) = explode('=', $mail);
$to[trim($key)] = trim($value);
}
@fomigo
fomigo / ajaxSetupForLoadingImage.js
Created January 13, 2012 18:58
How to control 'loading...' process in Ajax request
$(document).ready(function () {
/*************** FIRST EXAMPLE *********************/
$.ajaxSetup({
beforeSend: function() {
$('#general-ajax-load').fadeIn();
},
complete: function() {
$('#general-ajax-load').fadeOut();
},
@fomigo
fomigo / MODX Basic Template
Created February 3, 2012 16:49
MODX Basic Template extended
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>[[++site_name]] - [[*pagetitle]]</title>
<base href="[[++site_url]]" />
<style>
body {margin:auto; width:800px; color: #5F5F5F;}
</style>
</head>
@fomigo
fomigo / jquery.groupedAjax.js
Created February 17, 2012 11:35 — forked from Zoramite/jquery.groupedAjax.js
jQuery ajax grouping with Deferred objects.
(function($){
var requests = {};
$(function(){
// Determine which data you need and call the getData()...
// Stubbing in some example data...
// This is a unique request and would make an ajax call
getData({
foo: 'bar'
@fomigo
fomigo / jquery deferred
Created February 28, 2012 12:35
just one of the usage jquery deferred
$.when(
$.ajax('ajax.php')
).then(function(data){
// Here I can work with data like I would with a regular ajax request
alert($(data).find('mynode').text());
})
@fomigo
fomigo / SplClassLoader.php
Created March 10, 2012 05:51 — forked from jwage/SplClassLoader.php
SplClassLoader implementation
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
@fomigo
fomigo / gist:2011903
Created March 10, 2012 16:14 — forked from d33pfri3d/gist:2005383
jQuery : Ajax Deferred
$.X = function(){
var deferred = new $.Deferred();
// DO AJAX
/*
$.ajax({
// Do Ajax Call
url: '',
//Success
@fomigo
fomigo / defaultTemplateByParentTv.plugin.php
Created April 9, 2012 15:37 — forked from bfncs/defaultTemplateByParentTv.plugin.php
Default Children Template by Parent TV - modX Revolution Plugin
<?php
/**
* =========================
* defaultTemplateByParentTv
* =========================
*
* Plugin for modX Revolution
* Set default template for children of a ressource
*
* Author:
@fomigo
fomigo / jquery.defaultvalues.js
Created April 9, 2012 15:39 — forked from bfncs/jquery.defaultvalues.js
jQuery Plugin: Default form values from labels
/* DefaultValues v0.1 - Form input default values from labels
* by Marc Loehe
* http://marcloehe.de
*/
(function ($) {
$.fn.DefaultValues = function() {
return this.each(function() {
var form = $(this);
$(this).find('input[type=text], textarea').each(function() {