Skip to content

Instantly share code, notes, and snippets.

View qborreda's full-sized avatar
🏠
Working from home

Quique Borredá qborreda

🏠
Working from home
  • Valencia
  • 21:55 (UTC -12:00)
View GitHub Profile
@qborreda
qborreda / string_truncate.php
Created May 7, 2013 09:23
PHP Truncado de cadenas
<?php
// truncate with smart check for spaces
function truncate($string, $limit = 75, $break = " ", $pad = "...")
{
if (strlen($string) <= $limit) return $string;
$string = substr($string, 0, $limit);
if (false !== ($breakpoint = strrpos($string, $break)))
{
$string = substr($string, 0, $breakpoint);
@qborreda
qborreda / genera_cadena.php
Created May 7, 2013 09:25
PHP Generador de cadenas alfanuméricas
<?php
$Caracteres = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789';
$max = strlen($Caracteres) - 1;
for($x=1; $x<=100; $x++) {
for($i=0; $i < 8; $i++) {
@qborreda
qborreda / getDifference.php
Created May 7, 2013 09:26
PHP Diferencia en texto entre dos fechas
<?php
function getDifference($startDate,$endDate,$format)
{
list($date,$time) = explode(' ',$endDate);
$startdate = explode("-",$date);
$starttime = explode(":",$time);
list($date,$time) = explode(' ',$startDate);
$enddate = explode("-",$date);
$endtime = explode(":",$time);
@qborreda
qborreda / base64_img.php
Created May 7, 2013 09:27
PHP Base64 images
<?php
$img_src = "img/sample.jpg";
$imgbinary = fread(fopen($img_src, "r"), filesize($img_src));
$img_str = base64_encode($imgbinary);
echo '<img src="data:image/jpeg;base64,'.$img_str.'" alt="Alt text" />';
?>
@qborreda
qborreda / full_or_mobile.php
Created May 9, 2013 14:53
PHP - Fullsite or Mobile
global $assign_to_config;
if( ! isset($assign_to_config['global_vars']))
{
$assign_to_config['global_vars'] = array();
}
$useragent = $_SERVER['HTTP_USER_AGENT']; // Let's do some device detection
if (preg_match('/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(
@qborreda
qborreda / jquery_center.js
Created May 14, 2013 15:53
Center an element on screen with jQuery
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) +
$(window).scrollTop()) + "px");
this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
$(window).scrollLeft()) + "px");
return this;
}
jQuery.fn.center = function(parent) {
@qborreda
qborreda / leftPad.js
Created May 21, 2013 17:00
Devuelve un número como cadena formateada con ceros a la izda
/**
* Devuelve un número como cadena formateada con ceros a la izda
* @param {number} number El número original
* @param {integer} targetLength Número de caracteres que queremos obtener
* @return {string} Cadena compuesta de ceros y el número original
*/
function leftPad(number, targetLength) {
var output = number + '';
while (output.length < targetLength) {
output = '0' + output;
@qborreda
qborreda / ejemplo.html
Created May 22, 2013 08:51
Animates a collection of png images in a sequence Images should be named according to a pattern set in the img tag <img class="animated" interval="50" max="20" pattern="./images/image-sequence-#.png" />
<html>
<head>
<style>
.loading-background
{
width:48px;
height:48px;
display:inline-block;
background-color:Green;
@qborreda
qborreda / facebook_connect.php
Created June 6, 2013 08:50
PHP Facebook Connect and Data
<?php
//
// uses the PHP SDK. Download from https://github.com/facebook/php-sdk
include("facebook-php-sdk/src/facebook.php");
//
// from the facebook app page
define('YOUR_APP_ID', '32WEWWEWWEWEWEWEWEW24');
define('YOUR_APP_SECRET', '49fd00ce6237WEEWEWEWEWEW2');
@qborreda
qborreda / facebook_connect.html
Created June 6, 2013 08:52
JavaScript Facebook Connect
<html>
<head></head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
status : true, // check login status