Skip to content

Instantly share code, notes, and snippets.

View williaanlopes's full-sized avatar
🏠
Working from home

Williaan Lopes williaanlopes

🏠
Working from home
View GitHub Profile
@williaanlopes
williaanlopes / email_regex.txt
Created October 19, 2023 01:05
Regex email validator
^(((?![A-Za-z]+$)[0-9A-Za-z]+(\.(?![A-Za-z]+$)[0-9A-Za-z]+)*)|(\".+\")){2,}@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$
@williaanlopes
williaanlopes / AndroidManifest.xml
Last active September 24, 2022 05:12
New Android registerForActivityResult camera photo
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" tools:remove="android:maxSdkVersion"/>
<application
android:allowBackup="true"
@williaanlopes
williaanlopes / text-transfor.js
Last active October 30, 2020 00:42
jQuery helper functions like PHP (ucwords, strtoupper, strtolower) functions
$('.capitalize').on('keyup', function(e) {
if (e.target.value && e.target.value != "") {
$(this).val(e.target.value.toUpperCase());
}
});
$('.capitalize-first').on('keyup', function(e) {
if (e.target.value && e.target.value != "") {
$(this).val(e.target.value.replace(/(^\w{1})|(\s{1}\w{1})/g, match => match.toUpperCase()));
}
@williaanlopes
williaanlopes / adb.txt
Created August 27, 2020 20:20
Debugging with Android Studio stuck at "Waiting For Debugger" forever
adb shell am clear-debug-app
@williaanlopes
williaanlopes / renavam.validator.js
Last active September 29, 2022 13:12
JavaScript para Validação de Renavam
/*
* Essa função foi retirada do seguinte site: https://victorjabur.com/2010/05/28/renavam_veiculos_java/
**/
function isValidRenavam(renavam) {
if (Number.isInteger(renavam)) {
renavam = `${renavam}`;
}
var length = 11;
@williaanlopes
williaanlopes / cliente.html
Created June 15, 2020 23:54
Exemplo de socket.io com multiplos namespaces e rooms entre clientes
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
<script type="text/javascript">
var socket = io.connect('http://localhost:3000/api/v1', {
query: new URLSearchParams({token: 'asdad', room: '123'}).toString()
@williaanlopes
williaanlopes / queue.js
Last active May 16, 2020 03:44
JavaScript ES queue
class Queue extends Array {
enqueue(val) {
this.push(val);
}
dequeue() {
return this.shift();
}
peek() {
@williaanlopes
williaanlopes / MyPlaces.java
Created August 1, 2019 02:05
Android: find current user place using Google Places library 16.1.+
private final List<com.google.android.libraries.places.api.model.Place.Field> placeFields = Arrays.asList(
com.google.android.libraries.places.api.model.Place.Field.ID,
com.google.android.libraries.places.api.model.Place.Field.NAME,
com.google.android.libraries.places.api.model.Place.Field.ADDRESS,
com.google.android.libraries.places.api.model.Place.Field.LAT_LNG
);
FindCurrentPlaceRequest request = FindCurrentPlaceRequest.builder(placeFields).build();
Task<FindCurrentPlaceResponse> placeResponse = placesClient.findCurrentPlace(request);
@williaanlopes
williaanlopes / CpfValidator.hs
Created November 23, 2018 15:59
Validando CPF com Haskell (Validating CPF with Haskell)
{--
Exemplo de CPF 546.471.429-49
Tutorial no link: https://www.devmedia.com.br/validando-o-cpf-em-uma-aplicacao-java/22097
--}
module Util.CpfValidator where
import Data.Char
{--
@williaanlopes
williaanlopes / get.js
Created October 13, 2018 17:27
Making requests with pure Javascript and promise (Fazendo requisições com Javascript puro e promise)
// promise example
function get(url) {
// Return a new promise.
return new Promise(function(resolve, reject) {
// Do the usual XHR stuff
var req = new XMLHttpRequest();
req.open('GET', url);
req.onload = function() {
// This is called even on 404 etc