Skip to content

Instantly share code, notes, and snippets.

@meglio
meglio / ajax-items.js
Created August 28, 2014 14:17
JS component to allow for inline edition of CRM items in admin panels through inline dialogs.
function AjaxItems($container, config) {
var defaultOpts = {
textNoItems: "Не знайдено",
removalActionClass: "actionRemove",
removalDialog: function(el) { return confirm('Видалити?') },
showNoItems: function($container, message) {
$container.empty().append( $div().text(message) )
},
// If you want item removal to be handled, add an element with class .actionRemove (or another specified in removalActionClass option)
itemDom: function(el) {
@meglio
meglio / act-type-input.js
Created August 28, 2014 14:00
JS component used in notarzvit.com for fast multi-word binary tree search of notary act type names
function ActiveActsBranch()
{
// { actTypes: ..., searchTree: ... }
var meta = null
this.load = function(callback)
{
if (typeof activeActsBranchTimestamp !== "undefined" && activeActsBranchTimestamp && $.jStorage.storageAvailable())
{
var savedTimestamp = $.jStorage.get('activeActsBranchTimestamp', null)
@meglio
meglio / Router.php
Created August 28, 2014 13:52
Simple router class for small and medium projects
<?php
/**
* Class Router is static class which serves for routing purposes and can be used in 2 modes: full-map and on-the-go.
*
* Reads request uri path from $_GET['_REQUEST_URI']
*/
namespace _\web;
@meglio
meglio / Lazy.php
Created August 28, 2014 13:51
Simple but powerful class that allows for easy static and per-instance parametrized lazy value storage
<?php
namespace _\lang;
use ReflectionFunction;
use RuntimeException;
/**
* Trait Lazy
*
@meglio
meglio / Eway.php
Created August 28, 2014 13:49
Integration with eWay payment system
<?php
namespace _\integrations;
use _\Curl;
use _\lang\Arr;
use _\lang\Lazy;
use RuntimeException;
@meglio
meglio / affx-api-documentation-example
Created August 27, 2014 14:07
API documentation example
# API ACCESS
* Access Point: http://affiliatex.com/api
* All fields must be passed in POST variables; GET variables will be ignored.
* You will have to retrieve a secret key in order to use AffiliateX API.
# API RESPONSE FORMAT
The response will be always JSON-encoded.
<?php
namespace _\lang;
trait Classes
{
static function fullClassName()
{
return __CLASS__;
<?php
# Router:
R::route('GET|POST', '/ajax', '\_\web\Ajax::processAjaxCall');
# Handler method:
static function processAjaxCall()
<?php
# Autoload that works only with _ namespace
if (!spl_autoload_register(function ($class) {
if (substr($class, 0, 2) !== '_\\')
return;
$class = (string)str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 2));
$file = ROOT_PATH . '/_core/' . $class . '.php';
if (file_exists($file))
include $file;
@meglio
meglio / denis-x.js
Last active August 29, 2015 13:56
Denis' generic utils for JS
RegExp.escape = function (text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
if (!Math.sqr) {
Math.sqr = function (x) {
return x * x;
}
}