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 / .bash_functions
Created June 26, 2024 14:31
Turn "snap refresh" into "snap update"
snap() {
if [[ $@ == "update" ]]; then
command snap refresh
else
command snap "$@"
fi
}
import 'cordova-plugin-purchase';
document.addEventListener('deviceready', onDeviceReady);
let log: CdvPurchase.Logger;
let statusMessage: null | string = null;
function setStatusMessage(value: null | string) {
if (statusMessage !== value) {
statusMessage = value;
renderStatusUI();
@robertopc
robertopc / index.ts
Created October 27, 2023 20:44 — forked from j3k0/index.ts
cordova-purchase-plugin v13 - micro example
document.addEventListener('deviceready', onDeviceReady);
function onDeviceReady() {
const store = CdvPurchase.store;
const { ProductType, Platform, LogLevel, Product, VerifiedReceipt } = CdvPurchase; // shortcuts
// We should first register all our products or we cannot use them in the app.
store.register([{
id: 'demo_monthly_basic',
@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
{
@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 / 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 / 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 / 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 / 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 / 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);
}