Skip to content

Instantly share code, notes, and snippets.

@meglio
meglio / Router.php
Created February 17, 2013 03:00
Simple HTTP routing utility
<?php
/**
* Class Router is static class which serves for routing purposes and can be used in 2 modes: full-map and on-the-go modes.
*
* Reads request uri path from $_GET['_REQUEST_URI']
*/
class Router
{
@meglio
meglio / inline-watch.js
Last active December 14, 2015 16:29
Replaces jQuery element or its content temporarily with watch symbol of iconic font (icon-refresh). To be used with http://fortawesome.github.com
/**
* Replaces jQuery element or its content temporarily with watch symbol of iconic font (icon-refresh)
*
* To be used with http://fortawesome.github.com
*/
function replaceByWatch(el, replaceInnerContent) {
var watch = $icon('icon-refresh icon-spin')
if (replaceInnerContent) {
@meglio
meglio / Arr.php
Last active April 12, 2021 17:52
<?php
class Arr
{
static function get($arr, $keys = null, $default = null)
{
if (is_null($keys))
return $arr;
foreach((array)$keys as $k)
{
@meglio
meglio / Lazy.php
Last active November 24, 2015 02:02
<?php
/**
* Trait Lazy
*
* Allows for static and dynamic lazy initialization.
* NB. Include "use Lazy;" in every class you want this functionality, otherwise collision may happen if any of parents use Lazy.
*
* Example:
@meglio
meglio / saved.css
Created January 31, 2014 12:14
Creates a nice caption which disappears with animation like on this video: http://www.screenr.com/4xmH - useful for "Saved" notifications over "Save" buttons etc.
.action-success {
position: absolute;
z-index: 1000;
color: green;
border: 1px dashed green;
background-color: rgba(255,255,255,0.5);
font-size: 14px;
padding: 2px 4px;
border-radius: 8px;
text-align: center;
@meglio
meglio / Router.php
Created February 3, 2014 19:35
A simple web-router
<?php
/**
* Serves for routing purposes and can be used in 2 modes:
* 1. Build the full map and then process
* 2. Process on the go until a matched mapping is found
*
* Reads request uri path from $_GET['_REQUEST_URI']
*/
@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;
}
}
<?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;
<?php
# Router:
R::route('GET|POST', '/ajax', '\_\web\Ajax::processAjaxCall');
# Handler method:
static function processAjaxCall()
<?php
namespace _\lang;
trait Classes
{
static function fullClassName()
{
return __CLASS__;