Skip to content

Instantly share code, notes, and snippets.

@sbarrat
sbarrat / DBConnection.php
Created Feb 8, 2012
Singleton PDO DB Connection PHP
View DBConnection.php
final class DBConnection {
private static $_handle = null;
private static $_dsn = "mysql:dbname=mydb;host=my.host.com;port=3306";
private static $_user = "myUserName";
private static $_password = "myPassword";
private static $_options = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"); // SET UTF-8
/**
* Deny Construct
*/
@sbarrat
sbarrat / generoPersona.php
Last active Mar 13, 2016
Detección de genero de Persona España
View generoPersona.php
function generoPersona($nombre, $provider = 'genderAPI')
{
$providers = array(
'genderAPI' => array(
'url' => 'https://gender-api.com/get?name=',
'pais' => '&country=ES'
),
'genderize' => array(
'url' => 'https://api.genderize.io/?name=',
'pais' => '&country_id=es'
@sbarrat
sbarrat / vbaColorToWeb.php
Last active Dec 19, 2015
Function to change vba color to hex or rgb
View vbaColorToWeb.php
/**
* vbaColorToWeb.php Class to convert VBA color to web Color
*
*
* PHP Version 5.3
*
* @author Ruben Lacasa Mas <ruben@rubenlacasa.es>
* @copyright 2013 Ruben Lacasa Mas http://rubenlacasa.es
* @license http://creativecommons.org/licenses/by-nc-nd/3.0
* CC-BY-NC-ND-3.0
@sbarrat
sbarrat / .htaccess
Created Jun 16, 2013
Acceso restringido de usuarios con Apache
View .htaccess
AuthType Basic
AuthName "Mi Sitio Seguro"
AuthBasicProvider file
AuthUserFile /ruta/completa/ficheroUsuarios
Require valid-user
@sbarrat
sbarrat / datosEntreFechas.sql
Created Jun 12, 2013
Seleccionar datos entre dos fechas
View datosEntreFechas.sql
SELECT data FROM tbl WHERE date BETWEEN date1 AND date2
View datePickerInlineEs.html
<!--
Demo de datepicker inline en castellano
Autor: Ruben Lacasa Mas <http://rubenlacasa.es>
-->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="author" content="Ruben Lacasa Mas - rubenlacasa.es">
@sbarrat
sbarrat / SumaTiempos.php
Last active Dec 17, 2015
Clase PHP para sumar tiempos / PHP Class to add times
View SumaTiempos.php
<?php
/**
* SumaTiempos.php Clase para sumar tiempos
*
* Esta clase sirve para teniendo un tiempo inicial y un Array con tiempos
* los suma y nos devuelve el tiempo final
*
* PHP Version 5.3
*
* @author Ruben Lacasa Mas <ruben@rubenlacasa.es>
@sbarrat
sbarrat / datepickerEs.js
Created Jul 20, 2012
Datepicker jQuery en castellano
View datepickerEs.js
$('.datepicker').datepicker({
dateFormat: "dd-mm-yy",
firstDay: 1,
dayNamesMin: ["Do", "Lu", "Ma", "Mi", "Ju", "Vi", "Sa"],
dayNamesShort: ["Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sab"],
monthNames:
["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio",
"Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"],
monthNamesShort:
["Ene", "Feb", "Mar", "Abr", "May", "Jun",
@sbarrat
sbarrat / bugzillaWebService.php
Created Jan 31, 2012
XMLRPC_Client Bugzilla with Zend Framework
View bugzillaWebService.php
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
$server = 'http://bugzilla.mydomain.com/xmlrpc.cgi';
$client = new Zend_XmlRpc_Client( $server );
// Create the http client
$httpClient = new Zend_Http_Client();
$httpClient->setCookieJar();
$client->setHttpClient( $httpClient );
// Bugzilla Login
$params = new Zend_XmlRpc_Value_Struct(
@sbarrat
sbarrat / xmlrpcClientBugzilla.php
Created Jan 28, 2012
XMLRCP Client Bugzilla Login
View xmlrpcClientBugzilla.php
/**
* require PEAR/XML_RPC2 library
* Works fine with bugzilla 4.0.3
*/
require_once 'XML/RPC2/Client.php';
$server = 'http://bugzilla.mydomain.com/xmlrpc.cgi';
$params = array( 'login' => 'bugzilla@mydomain.com','password' =>'mypassword', 'remember' => 1);
$client = XML_RPC2_Client::create( $server );
$userid = $client->__call( 'User.login' , $params );