Skip to content

Instantly share code, notes, and snippets.

@ricardodantas
ricardodantas / validacao+mascara.js
Last active February 12, 2025 20:08
Máscara e validação de RG, CNPJ, CPF, etc...
// JavaScript Document
// adiciona mascara para rg
// Cada estado têm regras e quantidades diferentes de números no registro. Por isso,
// não há uma maneira confiável de fazer a validação do mesmo.
function MascaraRg(v0,errChar='?'){
const v = v0.toUpperCase().replace(/[^\dX]/g,'');
return (v.length==8 || v.length==9)?
v.replace(/^(\d{1,2})(\d{3})(\d{3})([\dX])$/,'$1.$2.$3-$4'):
(errChar+v0)
@ricardodantas
ricardodantas / gmaps-lat-lon.js
Created March 11, 2014 18:35
Google Maps API - Pegar a latitude e longitude de um endereço
window.geocoder = new google.maps.ClientGeocoder();
geocoder.getLocations('rua xyz, sp', function(result){
var placemark = result.Placemark[0]; // Only use first result
var accuracy = placemark.AddressDetails.Accuracy;
var zoomLevel = 1;
var lon = placemark.Point.coordinates[0];
var lat = placemark.Point.coordinates[1];
gmap.setCenter(new google.maps.LatLng(lat, lon), zoomLevel);
});
@ricardodantas
ricardodantas / fullscreenapi.helper.js
Last active January 29, 2025 05:24
Javascript fullscreen API helper
var requestFullscreen = function (ele) {
if (ele.requestFullscreen) {
ele.requestFullscreen();
} else if (ele.webkitRequestFullscreen) {
ele.webkitRequestFullscreen();
} else if (ele.mozRequestFullScreen) {
ele.mozRequestFullScreen();
} else if (ele.msRequestFullscreen) {
ele.msRequestFullscreen();
} else {
@ricardodantas
ricardodantas / dbf2mysql.class.php
Created December 4, 2012 04:05
dbf2mysql.class.php
<?php
/**
** Convert DBF files to MySQL file
** contact: http://gschimpf.com/
**
** USAGE:
** $filename = "dir/file.dbf";
** // Show the result sql
** dbf2mysql::mostrarSQL($filename);
@ricardodantas
ricardodantas / my-favorite-dev-resources.md
Last active November 3, 2021 08:14
My favorite dev resources

My favorite tools and resources

🚧 Still in progress

Languages

  • Javascript/NodeJs/TypeScript

Databases

  • PostgreSQL
@ricardodantas
ricardodantas / install-docker-compose.sh
Created November 1, 2021 14:48
Install docker-compose
#!/bin/bash
if ! [ -x "$(command -v docker-compose)" ]; then
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-\$(uname -s)-\$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
fi
docker-compose --version
@ricardodantas
ricardodantas / check-servers-ready.sh
Last active October 27, 2021 12:36
Bash Script utility to check if the services are up and running.
#!/bin/bash
SERVICES_LIST=(http://localhost:3001/healthcheck http://localhost:3000/healthcheck)
isServiceReady(){
ping=$(curl -s -f -LI $1)
if [ -z "$ping" ]; then
false;
else
true;
@ricardodantas
ricardodantas / googleapis-fetch-user-groups.js
Created August 25, 2021 08:17
Fetch user groups using an impersonated Service Account from Google Admin drectory.
/*
* Fetch users groups through an impersonated Service Account
*/
const { google } = require('googleapis');
const credentials = require('../service-account-credentials.json')
const scopes = [
'https://www.googleapis.com/auth/admin.directory.user.readonly',
'https://www.googleapis.com/auth/admin.directory.group.readonly',
]
@ricardodantas
ricardodantas / firebase-cloud-function-notification-to-topic.js
Created October 24, 2017 16:34
Sample showing how to use Firebase Cloud Function to send push notification for a topic.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/messages/{pushId}/text').onWrite((event) => {
const data = event.data;
console.log('Message received');
if(!data.changed()){
console.log('Nothing changed');
return;
@ricardodantas
ricardodantas / Dockerfile
Created June 2, 2021 10:41
Dockerfile for a Nginx + React app
# Multi-stage
# 1) Node image for building frontend assets
# 2) nginx stage to serve frontend assets
# Name the node stage "builder"
FROM node:10 AS builder
# Set working directory
WORKDIR /app
# Copy all files from current directory to working dir in image
COPY . .