Skip to content

Instantly share code, notes, and snippets.

View itsjavi's full-sized avatar
🤖

Javi Aguilar itsjavi

🤖
View GitHub Profile
@itsjavi
itsjavi / get_closure_param_names.php
Created January 15, 2013 17:49
Get PHP closure function parameter names
<?php
function get_closure_params(\Closure $fn){
preg_match_all('/\[\$(.+)\]/', print_r($fn, true), $matches);
return isset($matches[1]) ? $matches[1] : array();
}
@itsjavi
itsjavi / jquery-fontsize-fit.js
Created March 5, 2013 15:12
Fit font-size in container's width
$.fn.fitFontSize = function(minFontSize, containerWidth){
minFontSize = minFontSize || 12;
return this.each(function(){
var $this = $(this);
var sectionWidth = containerWidth || $this.parent().innerWidth();
var spanWidth = $this.width();
var newFontSize = (sectionWidth/spanWidth) * minFontSize;
$this.css({"font-size" : newFontSize, "line-height" : (newFontSize+2) + "px"});
});
};
@itsjavi
itsjavi / fbstats.php
Created August 14, 2013 10:08
PHP function for getting batch url stat counters (likes, shares, ...)
<?php
function facebook_url_stats($urls, $orderBy = "ORDER BY like_count DESC") {
$urls = implode("', '", $urls);
$urls = "'" . $urls . "'";
$fql = "SELECT url, normalized_url, share_count, like_count, comment_count, ";
$fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM ";
$fql .= "link_stat WHERE url IN ({$urls}) {$orderBy}";
@itsjavi
itsjavi / emberjs_template_loader.js
Last active December 23, 2015 18:19
emberjs external template loader with callback
function loadTemplates(templates, callback) {
var _loadCount = 0;
$('body').bind('templates_loaded', callback);
if(templates.length === 0){
$('body').trigger('templates_loaded');
}else{
$(templates).each(function(i, el) {
var _tpl = $('<script>');
_tpl.attr('type', 'text/x-handlebars');
@itsjavi
itsjavi / permtest.php
Created January 14, 2014 11:42
PHP filesystem permission test
<?php
error_reporting(-1);
ini_set('display_errors', true);
echo '<h1>PHP permission test</h1>';
$currdir = realpath(dirname(__FILE__));
$testdir = $currdir . '/' . time();
$testfile = $testdir . '/mytest.txt';
@itsjavi
itsjavi / slugize.js
Last active January 4, 2016 02:29
JS string slugize
/*
This is a merge of the node slugize-component module
Usage: $str.slugize('SómE StrïNG');
*/
(function(){
var special = ['À','à','Á','á','Â','â','Ã','ã','Ä','ä','Å','å','Ă','ă','Ą','ą','Ć'
, 'ć','Č','č','Ç','ç','Ď','ď','Đ','đ', 'È','è','É','é','Ê','ê','Ë','ë'
, 'Ě','ě','Ę','ę','Ğ','ğ','Ì','ì','Í','í','Î','î','Ï','ï', 'Ĺ','ĺ','Ľ'
, 'ľ','Ł','ł','Ñ','ñ','Ň','ň','Ń','ń','Ò','ò','Ó','ó','Ô','ô','Õ','õ'
, 'Ö','ö','Ø','ø','ő','Ř','ř','Ŕ','ŕ','Š','š','Ş','ş','Ś','ś','Ť','ť'
@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();