Skip to content

Instantly share code, notes, and snippets.

View joubertredrat's full-sized avatar

Joubert RedRat joubertredrat

View GitHub Profile
@joubertredrat
joubertredrat / fork.php
Created November 27, 2013 19:20
Error SQLSTATE[HY000]: General error
<?php
$pdo = false;
function load_database() {
global $pdo;
try {
$options = array();
$options[PDO::ATTR_PERSISTENT] = true;
$options[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true;
$options[PDO::ATTR_EMULATE_PREPARES] = true;
@joubertredrat
joubertredrat / gist:7824003
Last active December 30, 2015 11:39
Experimental switch regex
<?php
$errno = 1;
$bool = $errno == E_CORE_ERROR || $errno == E_ERROR || $errno == E_USER_WARNING || $errno == E_COMPILE_ERROR;
var_dump($bool);
$bool = $errno == x(E_CORE_ERROR || E_ERROR || E_USER_WARNING || E_COMPILE_ERROR);
$bool = $errno == ||(E_CORE_ERROR, E_ERROR, E_USER_WARNING, E_COMPILE_ERROR);
@joubertredrat
joubertredrat / gist:7824139
Created December 6, 2013 13:52
Desse jeito funciona
<?php
$str = '[0710:020602938:7041]';
switch(true) {
case preg_match('/^(\[)[A-Z0-9]{4}:(' . rand(10000,29999) . '|' . rand(50000,99999) . '):[A-z]{3}(\])(.*)+/', $str);
echo 'a';
break;
case preg_match('/^(\[)[A-Z0-9]{4}:[0-9]{9}:[0-9]{4}(\])+/', $str);
echo 'b';
break;
@joubertredrat
joubertredrat / gist:7894852
Created December 10, 2013 17:46
Conceitual idea about switch and regex
<?php
$str = '[0710:020602938:7041]';
preg_switch($str) {
case '/^(\[)[A-Z0-9]{4}:(' . rand(10000,29999) . '|' . rand(50000,99999) . '):[A-z]{3}(\])(.*)+/':
/* ... */
break;
case '/^(\[)[A-Z0-9]{4}:[0-9]{9}:[0-9]{4}(\])+/':
/* ... */
break;
@joubertredrat
joubertredrat / teste.php
Created September 2, 2014 20:02
Um simples conceito para debate
<?php
// como é atualmente
$a = ['um', 'dois', 'tres', 'quatro'];
echo implode (',', $a);
// Conceito 1
// $params = new paramClass();
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
@joubertredrat
joubertredrat / autoload.php
Created October 6, 2014 12:01
Exemplo autoload
<?php
function __autoload($classe)
{
if(file_exists(APP_PATH.'/core/classes'.$classe.'.php'))
{
require(APP_PATH.'/core/classes'.$classe.'.php');
add_log_event(SUCCESS, 'Classe '.$classe.' instanciada com sucesso pelo core');
}
else if(file_exists(APP_PATH.'/libs/'.$classe.'.php'))
@joubertredrat
joubertredrat / .htaccess
Created October 31, 2014 11:17
Redirect domain
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]
@joubertredrat
joubertredrat / counter.php
Last active August 29, 2015 14:10
Simple pageview counter
<?php
/**
* Simple pageview class.
*
* Usage:
* \Counter::register();
* \Counter::getStatus();
*
* @author Joubert <me@redrat.com.br>
*/
015-01-07 01:03:12.611+0000: starting up
LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin QEMU_AUDIO_DRV=none /usr/libexec/qemu-kvm -name instance-00000003 -S -machine pc-i440fx-rhel7.0.0,accel=kvm,usb=off -cpu SandyBridge,+erms,+smep,+fsgsbase,+rdrand,+f16c,+osxsave,+pcid,+pdcm,+xtpr,+tm2,+est,+smx,+vmx,+ds_cpl,+monitor,+dtes64,+pbe,+tm,+ht,+ss,+acpi,+ds,+vme -m 512 -realtime mlock=off -smp 1,sockets=1,cores=1,threads=1 -uuid 87f92892-e39c-4c3a-a0e6-f38d2546b6f0 -smbios type=1,manufacturer=Fedora Project,product=OpenStack Nova,version=2014.2.1-1.el7.centos,serial=2d406ad2-c45e-4e1b-86f1-1fa56e394d32,uuid=87f92892-e39c-4c3a-a0e6-f38d2546b6f0 -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/instance-00000003.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew -no-kvm-pit-reinjection -no-hpet -no-shutdown -boot strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/var/lib/nova/instances/87f92