Skip to content

Instantly share code, notes, and snippets.

View robertopc's full-sized avatar

Roberto Pereira da Costa robertopc

View GitHub Profile
@robertopc
robertopc / str_ireplace_array.php
Created May 7, 2020 20:10 — forked from adhocore/str_ireplace_array.php
A str_replace_array for PHP
<?php
/**
* A str_ireplace_array for PHP
*
* Case insensitive version of str_replace_array
* See https://wiki.php.net/rfc/cyclic-replace
*
* @author Jitendra Adhikari | adhocore <[email protected]>
*
@robertopc
robertopc / .htaccess
Created March 5, 2021 22:43
Cordova web app htaccess
RewriteEngine on
# Don’t rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow HTML5 state links
RewriteRule ^ index.html [L]
@robertopc
robertopc / git-pull-all
Created July 19, 2022 18:30 — forked from grimzy/git-pull-all
Git pull all remote branches
#!/usr/bin/env bash
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
@robertopc
robertopc / valida-cpf.js
Last active September 13, 2022 20:42
Validação de CPF Javascript
//valida o CPF digitado
function validarCPF(cpf){
cpf = cpf.toString().replace(/\.|\-/g, '' );
if(cpf.match(/^(1+|2+|3+|4+|5+|6+|7+|8+|9+|0+)$/) || cpf.length != 11)
return false;
soma = 0;
for(i = 0; i < 9; i ++) {
soma += parseInt(cpf.charAt(i)) * (10 - i);
}
@robertopc
robertopc / validar-nome-completo.js
Created September 13, 2022 21:11
Valida Nome Completo Javascript
// valida nome completo
function validarNome(nome) {
return nome.match(/^[A-Za-záàâãéèêíïóôõöúüçñÁÀÂÃÉÈÍÏÓÔÕÖÚÜÇÑ' ]+$/);
}
@robertopc
robertopc / nginxproxy.md
Created March 18, 2023 20:21 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@robertopc
robertopc / docker-adminer.sh
Last active March 29, 2023 19:38
Docker Adminer menu color theme chooser
#!/bin/bash
# ADMINER DOCKER MENU COLOR CHOOSER
# if not passed color, show the menu with colors
if [ -z "$1" ]; then
printf "ADMINER DOCKER SCRIPT
Available colors:
@robertopc
robertopc / dbtest.php
Created April 11, 2023 20:09
Test PostgreSQL and MySQL/MariaDB connectivity with PHP
<?php
$servername = "localhost";
$username = "user";
$password = "password";
echo"Postgre connection test<br>";
try {
$conn = new PDO("pgsql:host=$servername;dbname=test", $username, $password);
// set the PDO error mode to exception
@robertopc
robertopc / envread.php
Last active May 2, 2023 14:53
Read .env files in PHP
<?php
$consts = parse_ini_file('.env');
foreach($consts as $k => $i){
if(!defined($k))
define($k, $i);
}
@robertopc
robertopc / DatabaseSeeder.php
Last active October 26, 2023 17:07
Laravel DatabaseSeeder estados(ufs) e municipios brasileiros
<?php
namespace Database\Seeders;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class DatabaseSeeder extends Seeder
{