Skip to content

Instantly share code, notes, and snippets.

View digitalhydra's full-sized avatar
💭
please don't turn this into The MS social network

Jairo Mejia digitalhydra

💭
please don't turn this into The MS social network
View GitHub Profile
@digitalhydra
digitalhydra / curl get data.php
Created December 13, 2013 16:17
curls fuction to get data from a url
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
@digitalhydra
digitalhydra / smq.css
Created December 13, 2013 16:39
standard media querys
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen
@digitalhydra
digitalhydra / beforeunload.js
Created December 13, 2013 16:44
execute something before user leave the page before unload javascript
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
@digitalhydra
digitalhydra / validate_date
Created December 13, 2013 16:54
validate date function
function checkDate() {
var myDayStr = document.CheckDate.formDate.value;
var myMonthStr = document.CheckDate.formMonth.value;
var myYearStr = document.CheckDate.formYear.value;
var myMonth = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); var myDateStr = myDayStr + ' ' + myMonth[myMonthStr] + ' ' + myYearStr;
/* Using form values, create a new date object
using the setFullYear function */
var myDate = new Date();
myDate.setFullYear( myYearStr, myMonthStr, myDayStr );
@digitalhydra
digitalhydra / base64js.js
Created December 13, 2013 17:00
base 64 decode/encode
function base64_decode (data) {
// http://kevin.vanzonneveld.net
// + original by: Tyler Akins (http://rumkin.com)
// + improved by: Thunder.m
// + input by: Aman Gupta
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Onno Marsman
// + bugfixed by: Pellentesque Malesuada
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + input by: Brett Zamir (http://brett-zamir.me)
@digitalhydra
digitalhydra / formatear-numero.js
Created December 13, 2013 19:15
formatear numeros a miles
function oNumero(numero){
//Propiedades
this.valor = numero || 0
this.dec = -1;
//Métodos
this.formato = numFormat;
this.ponValor = ponValor;
//Definición de los métodos
function ponValor(cad){
@digitalhydra
digitalhydra / detect-nav.php
Created December 13, 2013 19:16
detectar navegador con php
<?php
function ObtenerNavegador($user_agent) {
$navegadores = array(
'Opera' => 'Opera',
'Mozilla Firefox'=> '(Firebird)|(Firefox)',
'Galeon' => 'Galeon',
'Mozilla'=>'Gecko',
'MyIE'=>'MyIE',
'Lynx' => 'Lynx',
'Netscape' => '(Mozilla/4\.75)|(Netscape6)|(Mozilla/4\.08)|(Mozilla/4\.5)|(Mozilla/4\.6)|(Mozilla/4\.79)',
@digitalhydra
digitalhydra / thumb-gd.php
Created December 13, 2013 19:19
generar thumbnail conGD
<?php
// Simple Thumb Gen
// Por Alex para WebTaller.com
$original = imagecreatefromjpeg("original.jpg");
$thumb = imagecreatetruecolor(150,150); // Lo haremos de un tamaño 150x150
$ancho = imagesx($original);
$alto = imagesy($original);
@digitalhydra
digitalhydra / levenstein.php
Created December 13, 2013 19:52
detectar strings parecidos util para busquedas de texto
int levenshtein (string cad1, string cad2)
Esta función devuelve la distancia Levenshtein entre las dos cadenas argumento,
ó -1 si alguna de las cadenas tiene más de 255 caracteres.
La distancia Levenshtein se define como el mínimo número de caracteres que se
tienen que sustituir, insertar o borrar para transformar cad1 en cad2.
@digitalhydra
digitalhydra / text-in-array.js
Created December 13, 2013 19:55
buscar texto en array
function oc(a)
{
var o = {};
for(var i=0;i<a.length;i++)
{
o[a[i]]='';
}
return o;
}