Skip to content

Instantly share code, notes, and snippets.

View itsjavi's full-sized avatar

Javi Aguilar itsjavi

View GitHub Profile
@itsjavi
itsjavi / current_request.php
Created February 20, 2014 09:12
Current request path in PHP
<?php
function url_path(){
// Base path
$script_name = isset($_SERVER["SCRIPT_NAME"]) ? $_SERVER["SCRIPT_NAME"] : '';
$base_path = '';
if (!empty($script_name)) {
$base_path = trim(str_replace('\\', '/', dirname($script_name)), '/ ');
}
// Path
@itsjavi
itsjavi / jquery.skrollto.js
Created March 21, 2014 10:02
Soft scroll to an element
$.fn.skrollto = function(speed, easing) {
speed = speed ||  1000;
easing = easing || 'swing';
return $(this).each(function(i, el){
//calculate destination place
var dest = 0;
var el = $(this);
if (el.is(':hidden')) {
@itsjavi
itsjavi / button_factory.less
Created March 21, 2014 10:42
Push-style bootstrap 3 button factory
.btn-factory(@color, @textcolor:#ffffff){
font-weight:800;
background:@color;
color:@textcolor;
box-shadow: 0 3px 0 0 darken(@color, 10%);
&:hover{
background:@color;
color:@textcolor;
box-shadow: 0 3px 0 0 darken(@color, 10%);
@itsjavi
itsjavi / ClassLoader.php
Created May 11, 2014 04:20
Class Loader for PHP 5.2+ based on Composer
<?php
class ClassLoader{
protected $prefixes = array();
protected $fallbackDirs = array();
protected $useIncludePath = false;
protected $classMap = array();
protected $history = array();
@itsjavi
itsjavi / Benchmarker.php
Created May 11, 2014 04:23
Benchmark class for PHP 5.2+ for calculating elapsed times and memory usage
<?php
class Benchmarker {
protected $start_time;
protected $end_time;
protected $memory_usage;
/**
* Sets start microtime
@itsjavi
itsjavi / regexp_arrayToFnCall.txt
Created May 12, 2014 11:26
Netbeans array to fn replace
search: \$_SERVER\[\'([A-Z_]{1,})\']
replace: \$this\-\>app\-\>server\(\'$1\'\)
@itsjavi
itsjavi / StopWatch.php
Created February 17, 2015 15:34
A simple "StopWatch" class to measure PHP execution time. The class can handle multiple separate timers at the same time.
<?php
/**
* A simple "StopWatch" class to measure PHP execution time.
* The class can handle multiple separate timers at the same time.
*/
class StopWatch {
/**
* @var $start float The start time of the StopWatch
*/
@itsjavi
itsjavi / AnnotationParser_with_BaseAnnotation.php
Last active August 29, 2015 14:20
PHP Annotation Parser based on Nette AnnotationParser.php
<?php
/**
* Annotations support for PHP.
* Class based on the Nette Framework annotation parser.
*/
class AnnotationParser
{
/** @internal single & double quoted PHP string */
const RE_STRING = '\'(?:\\\\.|[^\'\\\\])*\'|"(?:\\\\.|[^"\\\\])*"';
@itsjavi
itsjavi / autofit_background_image_script.html
Created October 27, 2010 10:50
Script for filling the entire window with a background image at any resolution (auto-fit)
<!DOCTYPE html>
<html>
<head>
<title>Auto-fit background image script</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<style>
html,body{
padding:0;
margin:0;
height:100%;
@itsjavi
itsjavi / jquery-ui.declarative.js
Created May 26, 2011 11:48
Initialize jQuery UI widgets and behaviours using HTML5 declarative markup
(function($){
$(document).ready(function(){
$("*[data-ui-widget]").each(function(){
$this = $(this);
switch($this.data("ui-widget")){
case "button":{
$this.button($this.data("ui-widget-options"));
}break;
case "datepicker":{
$this.datepicker($this.data("ui-widget-options"));