Skip to content

Instantly share code, notes, and snippets.

View rafaelbernard's full-sized avatar

Rafael Bernard Araújo rafaelbernard

View GitHub Profile
@rafaelbernard
rafaelbernard / substitui_win1252_html.sql
Created June 16, 2011 18:23
substitui_win1252_html
-- DROP FUNCTION substitui_win1252_html(texto);
CREATE OR REPLACE FUNCTION substitui_win1252_html(texto text)
RETURNS text AS
$$
BEGIN
texto := replace(replace(replace(replace(replace(texto, '’', '’'), '“', '“'), '”', '”'), '•','•'), '–', '–')::text;
RETURN texto;
@rafaelbernard
rafaelbernard / substitui_win1252.sql
Created June 16, 2011 18:34
Substitui caracteres win1252 por UTF-8
-- DROP FUNCTION substitui_win1252(texto);
CREATE OR REPLACE FUNCTION substitui_win1252(texto text)
RETURNS text AS
$$
BEGIN
texto := replace(replace(replace(replace(replace(texto, '’', ''''), '“', '"'), '”', '"'), '•','•'), '–', '-')::text;
RETURN texto;
@rafaelbernard
rafaelbernard / enviando-phpmailer.php
Created July 20, 2011 16:59
Enviando mensagens com o PHPMailer
<?php
require_once("/pasta/do/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "mail.seudominio"; //seu servidor SMTP
$mail->SMTPAuth = true; // 'true' para autenticação
$mail->Username = "usuario@seudominio"; // usuário de SMTP
$mail->Password = "senhaxxx"; // senha de SMTP
$mail->From = "de@seudominio";
@rafaelbernard
rafaelbernard / desacentua_string.php
Created August 12, 2011 19:01
Remove acentos de uma string
<?php
/**
* Desacentua uma string
* @param string $str String a ser desacentuada
* @return string String desacentuada
*/
function desacentua($str) {
$a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų',
@rafaelbernard
rafaelbernard / uteis.sql
Created November 10, 2011 20:50
úteis no oracle
Select * from dba_users;
Select * from dba_directories;
Select * from user_tables;
Select * from user_tab_columns;
@rafaelbernard
rafaelbernard / pg_random_1000_rows_table.sql
Created April 19, 2012 18:49
Generate table of 1000 random rows - PostgreSQL
SELECT i, clock_timestamp() t1, random() r1, random() r2, random() r3, clock_timestamp() + (round(random()*1000)::text || ' days')::interval d1
FROM generate_series(1,1000) i(i);
@rafaelbernard
rafaelbernard / bac_all_db_pg.sh
Created June 21, 2012 14:24
Backup de todos os bancos de dados do seu servidor PostgreSQL
#!/bin/bash
# Baseado em http://mig5.net/content/mysql-postgresql-all-databases-backup-script
# Rafael Bernard Rodrigues Araujo - 14/06/2012
today=$(date +%y%m%d)
# local dir where the backups go
myDir='/disk2/backup/pg'
# this is for PostgreSQL. If you don't need it, you
<?php
function exception_error_handler($severity, $message, $filename, $lineno) {
if (error_reporting() == 0) {
return;
}
if (error_reporting() & $severity) {
throw new ErrorException($message, 0, $severity, $filename, $lineno);
}
}
@rafaelbernard
rafaelbernard / saba_delete_registrations.sql
Last active December 28, 2015 23:48
Remover inscrições baseado em critério. Deve-se subsituir "trim(custom9) is not null" (meu critério escolhido) pelo critério da situação em que se encontrar.
-- zerando historico
select *
from tpt_registration
where trim(custom9) is not null;
select * from all_tables where table_name like '%ACTION%' AND OWNER='TP8';
select *
from tpt_offering_action
where id in (
@rafaelbernard
rafaelbernard / pg_default_utf8.sql
Last active August 29, 2015 14:01
PostgreSQL default template UTF-8
UPDATE pg_database SET datistemplate=FALSE WHERE datname='template1';
DROP DATABASE template1;
CREATE DATABASE template1
WITH owner=postgres template=template0 encoding='UTF8' LC_COLLATE='C' LC_CTYPE='C';
UPDATE pg_database SET datistemplate=TRUE WHERE datname='template1';