Skip to content

Instantly share code, notes, and snippets.

View emersonbroga's full-sized avatar
:octocat:
Let's code!

Emerson Brôga emersonbroga

:octocat:
Let's code!
View GitHub Profile
function log($text)
{
if(is_array($text) || is_object($text)){
$text = http_build_query($text);
}
// open log file
$filename = "mylog.txt";
$fh = fopen($filename, "a") or die("Could not open log file.");
fwrite($fh, date("d-m-Y, H:i")." - $text\n") or die("Could not write file!");
fclose($fh);
@emersonbroga
emersonbroga / teste-bordas.php
Last active December 19, 2015 06:59
Teste de lógica em php dentro de loops em php. É um teste simples que aguça o raciocinio lógico.
<?php
/**
* Use os estilos .last e .last-row
* dentro do loop utiliando php
* para mostar os grupos conforme as imagens
* Grupo 1 : http://cl.ly/image/2r33391j2Q2w/grupo1.png
* Grupo 2 : http://cl.ly/image/0s1k0x1S1q2d/grupo2.png
* Grupo 3 : http://cl.ly/image/3D0g0a280d1Q/grupo3.png
*
@emersonbroga
emersonbroga / wp-config.php
Last active April 3, 2019 19:29
Wordpress wp-config.php with several environment configurations.
<?php
/**
* The base configurations of the WordPress.
*
* This file has the following configurations: MySQL settings, Table Prefix,
* Secret Keys, WordPress Language, and ABSPATH. You can find more information
* by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
* wp-config.php} Codex page. You can get the MySQL settings from your web host.
*
* This file is used by the wp-config.php creation script during the
<?php
// pasta onde se encontram os arquivos. Caminho completo ou relativo
$dir = './selecionadas/';
// total de arquivos a serem renomeados.
$total = 106;
// prefixo do nome do arquivo
$prefix = 'arquivo';
<?php
class MyClass
{
public function strToDate( $str )
{
return new \DateTime($str);
}
}
<?php
$notFloat = '8521';
//example 1:
var_dump(is_float($notFloat)); //bool(false)
//example 2:
var_dump(filter_var($notFloat, FILTER_VALIDATE_FLOAT)); //float(8521)
//example 3:
var_dump(is_float(filter_var($notFloat, FILTER_VALIDATE_FLOAT))); //bool(true)
<?php
$f = false;
$n = null;
$e = '';
$z = 0;
if ($f === false)
echo '<br/> $f === false';
if ($n === false)
echo '<br/> $n === false';
@emersonbroga
emersonbroga / save.txt
Created March 11, 2013 14:35
Salvando as imagens do PhotoStream para o computador.
Baixe o iphoto no iphone ou ipad.
abra o iphoto
conecte o aparelho no maca
abra o aplicativo image capture
no iphoto va em photo stream
clique no botao "share", selecione, save to camera roll
escolha as fotos (max 100) e mande salvar no camera roll
no imagecapture, mande salvar as fotos no computador.
repita o processo até salvar todas as fotos
@emersonbroga
emersonbroga / SimpleImage.php
Created March 5, 2013 01:26
Implementing a Force Crop to the SimpleImage Class. Original source http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/
<?php
/*
* File: SimpleImage.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 08/11/06
* Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php
*
* This program is free software; you can redistribute it and/or
@emersonbroga
emersonbroga / Cep.php
Created December 13, 2012 18:03
Cep Class for use with the republica virtual db.
class Cep
{
private $url = 'http://www.republicavirtual.com.br/web_cep.php?';
private $cep, $formato, $consulta;
public $uf, $cidade, $bairro, $tipo_logradouro, $logradouro, $header;
public $resultado;
public function __construct($cep, $formato='query_string')
{
$this->cep = preg_replace('([^0-9])', '', $cep);