Skip to content

Instantly share code, notes, and snippets.

View wescleymatos's full-sized avatar
:octocat:
I'm ready!

Wescley Matos wescleymatos

:octocat:
I'm ready!
View GitHub Profile
/**
* Função para validar sequencia de digitos de Renavam
*
* @link http://blog.victorjabur.com/2010/05/28/renavam_veiculos_java/ Função baseada em uma de java retirada desse link
* @param string|int renavam Sequencia de digitos do renavam
* @return boolean
*/
function verificaRenavam( renavam ) {
var d = renavam.split("");
@wescleymatos
wescleymatos / binet.js
Created May 21, 2014 22:02
Caucular Fibinacci
var Binet = function( X ) {
var sqrt5 = Math.sqrt( 5 );
return ( 1 / sqrt5 ) * ( Math.pow( ( 1 + sqrt5 ) / 2 , X ) - Math.pow( ( 1 - sqrt5 ) / 2 , X ) );
}
<?php
/*
This function saved my life.
found on: http://www.sitepoint.com/forums//showthread.php?t=438748
by: crvandyke
It takes an object, and when all else if/else/recursive functions fail to convert the object into an associative array, this one goes for the kill. Who would'a thunk it?!
*/
$array = json_decode(json_encode($object), true);
@wescleymatos
wescleymatos / get_latlng_gmaps.php
Created July 31, 2013 15:32
Obtém a latitude e longitude direto do google mapa a partir de um banco de dados de cidades.
<?php
header('Content-Type: text/html; charset=utf-8');
//conexão com o servidor
$conect = mysql_connect("host", "user", "password");
// Caso a conexão seja reprovada, exibe na tela uma mensagem de erro
if (!$conect) die ("<h1>Falha na coneco com o Banco de Dados!</h1>");
// Caso a conexão seja aprovada, então conecta o Banco de Dados.
function str_pad (input, pad_length, pad_string, pad_type) {
// Returns input string padded on the left or right to specified length with pad_string
//
// version: 1009.2513
// discuss at: http://phpjs.org/functions/str_pad
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + namespaced by: Michael White (http://getsprink.com)
// + input by: Marco van Oort
// + bugfixed by: Brett Zamir (http://brett-zamir.me)
// * example 1: str_pad('Kevin van Zonneveld', 30, '-=', 'STR_PAD_LEFT');
<html>
<head>
<title>DEMONSTRAÇÃO: Marcar todas as Check Boxes de uma lista</title>
</head>
<body>
<script>
function checkAll(o){
console.log(o);
var boxes = document.getElementsByTagName("input");
for (var x=0;x<boxes.length;x++){
@wescleymatos
wescleymatos / altura_div.js
Last active December 18, 2015 01:48
Pega a altura das divs e ordena o array de forma descendente.
$(document).ready(function() {
var alturaMenu = $("#menu_vertical").height(),
alturaUltimasNoticias2 = $("#ultimas_noticias_2").height(),
alturaNoticiasDetalhe = $("#noticias_detalhe").height();
var alturas = new Array(alturaMenu, alturaNoticiasDetalhe, alturaUltimasNoticias2);
alturas = alturas.sort(function(a,b){return b-a});
console.log(alturas);
});
(function() {
var script,
scripts = document.getElementsByTagName('script')[0];
function load(url) {
script = document.createElement('script');
script.async = true;
script.src = url;
scripts.parentNode.insertBefore(script, scripts);
@wescleymatos
wescleymatos / image_preview.html
Created May 9, 2013 20:15
Este código exibe o preview de uma imagem e recupera seu tamanho original.
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="http://fancyapps.com/fancybox/source/jquery.fancybox.pack.js?v=2.1.4"></script>
<link rel="stylesheet" type="text/css" href="http://fancyapps.com/fancybox/source/jquery.fancybox.css?v=2.1.4" media="screen" />
<style type="text/css">
#imgPreview {width: 100px;}
</style>
<script>
var reader = new FileReader();
reader.onload = onLoadFile;
<?php
function xml2array($contents, $get_attributes=1, $priority = 'tag') {
if(!$contents) return array();
if(!function_exists('xml_parser_create')) {
//print "'xml_parser_create()' function not found!";
return array();
}
//Get the XML parser of PHP - PHP must have this module for the parser to work