Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Guilherme Branco Stracini guibranco

🏠
Working from home
View GitHub Profile
View exemplo.php
<?php
//código que eu não vi no print...
$historicoDeOperacoes = [];
switch($operacao){
case "saque":
$_SESSION["saldo"] -= $valor;
@guibranco
guibranco / diasDaSemana.js
Last active Apr 24, 2021
Exibe quantos dias da semana tem entre duas datas - Facebook - NodeJS Brasil - https://www.facebook.com/groups/1407602962733165/permalink/2136557383171049
View diasDaSemana.js
var startDate = new Date(2021, 3, 1);
var endDate = new Date(2021, 4, 1);
var diffTime = Math.abs(endDate - startDate);
var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
var totalWeeks = Math.round(diffDays / 7);
var remainingDays = diffDays % 7;
//se quiser considerar o dia final também, descomente a linha abaixo:
@guibranco
guibranco / Dockerfile
Last active Apr 21, 2021
Docker file for PHP 7.4 with Apache, MySQLi extension, GD2 and Apache mod_rewrite enabled
View Dockerfile
FROM php:7.4-apache
RUN apt-get update
RUN apt-get install --yes --force-yes cron g++ gettext libicu-dev openssl libc-client-dev libkrb5-dev libxml2-dev libfreetype6-dev libgd-dev libmcrypt-dev bzip2 libbz2-dev libtidy-dev libcurl4-openssl-dev libz-dev libmemcached-dev libxslt-dev
RUN a2enmod rewrite
RUN docker-php-ext-install mysqli
RUN docker-php-ext-enable mysqli
@guibranco
guibranco / docker-compose.yml
Created Mar 31, 2021
ELK cluster with 3 ES instances and 1 Kibana
View docker-compose.yml
version: '3.4'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
@guibranco
guibranco / docker-compose.yml
Created Mar 14, 2021
Docker compose file for AMP stack: Apache, MySQL, PHP and PHPMyAdmin
View docker-compose.yml
version: "3.1"
services:
www:
build: .
ports:
- "8001:80"
volumes:
- ./:/var/www/html/
networks:
@guibranco
guibranco / Dockerfile
Last active Apr 21, 2021
Docker file for PHP 5.6 with Apache, MySQL extension, GD2 and Apache mod_rewrite enabled
View Dockerfile
FROM php:5.6-apache
RUN apt-get update
RUN apt-get install --yes --force-yes cron g++ gettext libicu-dev openssl libc-client-dev libkrb5-dev libxml2-dev libfreetype6-dev libgd-dev libmcrypt-dev bzip2 libbz2-dev libtidy-dev libcurl4-openssl-dev libz-dev libmemcached-dev libxslt-dev
RUN a2enmod rewrite
RUN docker-php-ext-install mysql
RUN docker-php-ext-enable mysql
View showImage.php
<?php
$isAuthorized = isUserAuthorized(); //sua lógica para validar se o usuário está ou não autorizado.
if(!$isAuthorized)
die(header("Location: index.php")); //se o usuário não tiver autorização, redireciona ele pra index e encerra o script com die()
// aqui ele tá autorizado, então bora servir a imagem...
$image = $_GET["image"]; //supondo que a URL foi acessada via: showImage.php?image=foto123.png
View heranca.php
<?php
class A {
private $x;
public function __construct(){
$this->x = "testando";
}
public function __toString(){
View agrupamento.php
<?php
$soma = 0;
$fornecedor = "";
while($mostrar = mysql_fetch_row($result)){
if($fornecedor == "")
$fornecedor = $mostrar[3];
if($fornecedor != $mostrar[3]){
@guibranco
guibranco / opcao.php
Created Aug 29, 2020
Switch para PHP conforme opção a ser executada - PHP Brasil - Facebook - https://www.facebook.com/groups/142151625841770/?post_id=3358921867498047
View opcao.php
<?php
$data = $_SERVER['REQUEST_METHOD'] == "POST" ? $_POST : $_GET;
$option = $data["opc"];
switch($option){
case "inserir":
$sql = "INSERT INTO tabela (campoA, campoB, campoC, campoN) VALUES (?, ?, ?, ?)";
//código para processar os dados enviados do front, e presentes na $data.