Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / highlight.js
Created December 3, 2012 14:38
highligh(string, [words]) JS function
// Returns { highlighted: ..., count: ... }
function highlight(str, words)
{
var before = '<strong class="highlight">', beforeLen = before.length,
after = '</strong>', afterLen = after.length
if (typeof words == "string")
words = [words]
@meglio
meglio / OpenCorpora.scala
Created November 28, 2012 11:22
Parse opencorpora dictionary
package com.frazemet
import scala.io.Source
import xml.pull._
import collection.mutable.ListBuffer
object OpenCorpora {
def importFromXml(file: String) {
@meglio
meglio / aes256cbc.php
Created October 27, 2012 17:12
Enc/Dec AES 256 CBC, with data consistency validation
private static function iv()
{
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
return mcrypt_create_iv($iv_size, MCRYPT_RAND);
}
static function encrypt($str, $key32)
{
# Prepend 4-chars data hash to the data itself for validation after decryption
$str = substr(md5($str), 0, 4).$str;
@meglio
meglio / support.pdf.js
Created October 27, 2012 10:10
JQuery PDF support detection
/*
* Check for PDF support
* Based on http://downloads.beninzambia.com/blog/acrobat_detection.js.txt
*/
$.support.pdf = (function() {
try {
// IE
if(!$.support.cssFloat) {
var control = null;