Skip to content

Instantly share code, notes, and snippets.

View igoralves1's full-sized avatar

Igor Alves igoralves1

View GitHub Profile
@igoralves1
igoralves1 / gist:4a3d388f91e2c498e96020a9d87b5146
Created April 20, 2016 19:23
PHP - Data base Object. PDO - Mysql
/**
* Em desenvolvimento.
* Objeto para gerenciar uma
*conexão ao banco de dados Mysql
* @author Igor
*/
class db {
private $dsn;
private $username;
private $password;
$(function() {
timeout = setTimeout(function() {
window.location.href = "http://google.com";
}, 2500);//waiting 2,5s
});
$(document).on('mousemove', function() {
if (timeout !== null) {
clearTimeout(timeout);
}
@igoralves1
igoralves1 / gist:ad6ff439e0b4e36fa1b4db3deccdb854
Last active December 5, 2016 16:23
PHP - SATIC Data base Object. PDO - Mysql
<?php
//This class creates a connection with the databse and generates log files
class db {
public static $dsn;
public static $username;
public static $password;
public static $db;
public static $conn;
public static $arrConnAttr;//Array of connection attributes. Ex: ["PDO::ATTR_ERRMODE", "PDO::ERRMODE_EXCEPTION"]
@igoralves1
igoralves1 / gist:ec6c6dd92df8fcaaacd3d8c4a88e0628
Last active May 9, 2016 13:28
PHP - Autoload. Load CLasses if not found. Works with regular or static classes.
spl_autoload_register(function ($class_name) {
include './class/'.$class_name . '.php';
});
================== or ========================
function __autoload($className) {
$className = str_replace("..","", $className);
require_once ("./class/$className.php");
}
@igoralves1
igoralves1 / gist:bc3fb16742ec055b5066682e154c47de
Last active May 9, 2016 13:27
Clear HTML string from white spaces and new line character. It returns clean html string to be used inside JSON, AJAX etc.
//Eu tenho a seguinte string que representa um código html gerado dinamicamente por php.
//Preciso filtrar novas linhas e espaços em brancos para ser formatado corretamente num string JSON para
//Ser enviado através de AJAX.
<ul class="list-group sidebar-nav-v1 margin-bottom-40" id="menuHomeUserPrivate">
<li class="list-group-item active">
<a id="to_ProfileOverall" class="privateMenuLinkJS"><i class="fa fa-bar-chart-o"></i> Overall</a>
</li>
<li class="list-group-item list-toggle">
<a data-toggle="collapse" data-parent="#menuHomeUserPrivate" href="#collapse-MoneyManage" ><i class="fa fa-money"></i> Invoice</a>
@igoralves1
igoralves1 / gist:afc83f3a4cb9b7ad60b067904061b235
Created May 10, 2016 18:34
JS - Load some CSS file dinamically.
<script>
$(function(){
$('head').append('<link href="someFile.css" rel="stylesheet">');
});
</script>
@igoralves1
igoralves1 / gist:ddfb841abdd48e8a7fd3171f494d5c63
Last active May 12, 2016 15:44
Passar por cada radio de uma determinada classe e retornar a label associada com o que está selecionado
$('.rdShipMo').on( 'click', function() {
$('input:radio[class=rdShipMo]').each(function() {//Passar por cada radio da classe rdShipMo
if ($(this).is(':checked')) {
var idVal = $(this).attr("id");
alert($("label[for='"+idVal+"']").text());
}
});
});
https://jsfiddle.net/a5Lu0orb/1/
@igoralves1
igoralves1 / gist:7d8c6d62c20355593de76160e08d5a98
Created May 20, 2016 17:26
JS - Validação de campo utilizando tooltip -bootstrap
//Inserir o link para jQuery, js.bootstrap e css.bootstarp.
//O CSS exclusivo do tooltip está separado logo abaixo.
<textarea id='addItInfo' rows='4' cols='65%' name='prf[info][nm_additionalItInfo]' data-toggle='tooltip' data-placement='left'>$nm_additionalItInfo</textarea>
if($('#addItInfo').val()==''){
//alert("Must to fill the field 'REASON TO PRF REQUEST'");
//return false;
var msg ="Oops! This field must to be filled";
http://lamberta.github.io/html5-animation/
https://jsfiddle.net/ynj2kqmk/
https://jsfiddle.net/1wu1x8zj/
https://github.com/lamberta/html5-animation
//https://css-tricks.com/guide-svg-animations-smil/
<canvas id="canvas" width="400" height="400"></canvas>
http://888hack.com/2016/06/04/integracao-arduino-php-pelo-ubuntu/
CÓDIGO PHP
<?php
$porta = '/dev/ ttyACM0';
$numeroLido = $_REQUEST["numero"];
echo "Numero lido: $numeroLido";
$conexaoArduino = fopen($porta, 'w');
fwrite($conexaoArduino, $_REQUEST["numero"]);
fclose($conexaoArduino);