Skip to content

Instantly share code, notes, and snippets.

$.validator.addMethod('require-one', function (value) {
return $('.require-one:checked').size() > 0; }, 'Please check at least one box.');
var checkboxes = $('.require-one');
var checkbox_names = $.map(checkboxes, function(e,i) { return $(e).attr("name")}).join(" ");
$("#itemForm").validate({
groups: { checks: checkbox_names },
errorPlacement: function(error, element) {
if (element.attr("type") == "checkbox")
@jgdoncel
jgdoncel / new_gist_file.php
Created November 27, 2013 10:00
Obtener el último día del mes t devuelve el número total de días del mes en cuestión From http://stackoverflow.com/questions/1686724/php-last-day-of-the-month
$fecha = "2013-11-23";
echo date("Y/m/t", strtotime($fecha));
@jgdoncel
jgdoncel / datatables.js
Created December 4, 2013 15:03
Cambiar envío de peticiones jquery.datatables de GET a POST
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
// $.getJSON( sSource, aoData, function (json) {
// if(json.error == 'session_out'){
// document.location.href='index.php?msg=session_out';
// } else {
// fnCallback(json)
// }
// });
$.post(sSource, aoData, function(json) {
@jgdoncel
jgdoncel / new_gist_file.java
Created December 12, 2013 11:34
Android, deshabilitar Strictmode
public void onCreate (Bundle savedInstanceState)
{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
}
@jgdoncel
jgdoncel / new_gist_file.java
Created December 12, 2013 14:57
Android: Reiniciar una aplicación
Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
@jgdoncel
jgdoncel / new_gist_file.sql
Created December 17, 2013 08:24
Transact SQL: Equivalente a GROUP_CONCAT de MySQL
SELECT
STUFF(
(
SELECT
',' + RTRIM(LTRIM(TELEFONO))
FROM CLIENTE
WHERE CLIENTE = '10655'
ORDER BY TELEFONO FOR xml path('')
)
, 1, 1, '')
<?php
// Obtener el array
$myarray = glob("*.*");
// Ordenar por fecha ascendente
usort($myarray, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
@jgdoncel
jgdoncel / date_add.sql
Created January 16, 2014 10:01
Filtrar en base a fechas utilizando intervalos desde la fecha actual. Calcular una diferencia entre fechas
// Obtener registros de la tabla con fecha superior a hace tres meses
SELECT * FROM tabla WHERE fecha >= DATE_ADD(NOW(),INTERVAL -3 MONTH)
// De otro modo:
SELECT * FROM tabla WHERE fecha >= (NOW() + INTERVAL -3 MONTH)
$path = $_FILES['image']['name'];
$ext = pathinfo($path, PATHINFO_EXTENSION);
@jgdoncel
jgdoncel / agujaBuffonPi.java
Created January 29, 2014 22:23
Estimar el valor de Pi usando el método de la "Aguja de Buffon" http://http://es.wikipedia.org/wiki/Aguja_de_Buffon
// Tomar una aguja de 1cm y un papel con líneas paralelas a 2cm
// Lanzar la aguja sobre el papel, cada vez que la aguja corta una linea
// cuenta como un acierto
// pi (aprox) = intentos / aciertos
import java.util.Random;
import java.util.Scanner;
public class BuffonPiEstimation
{