Skip to content

Instantly share code, notes, and snippets.

View bernardolm's full-sized avatar
🧘‍♂️

Bernardo Loureiro bernardolm

🧘‍♂️
View GitHub Profile
import "regexp"
// Basic regular expressions for validating strings
const (
Email string = "^(((([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(([a-zA-Z]|[\\
@bernardolm
bernardolm / StreamToString.go
Created October 10, 2017 22:36 — forked from tejainece/StreamToString.go
Golang: io.Reader stream to string or byte slice
import "bytes"
func StreamToByte(stream io.Reader) []byte {
buf := new(bytes.Buffer)
buf.ReadFrom(stream)
return buf.Bytes()
}
func StreamToString(stream io.Reader) string {
buf := new(bytes.Buffer)
@bernardolm
bernardolm / sortmap.go
Created October 10, 2017 22:37 — forked from ikbear/sortmap.go
Sort Map(golang)
package main
// sort a map's keys in descending order of its values.
import "sort"
type sortedMap struct {
m map[string]int
s []string
}
@bernardolm
bernardolm / unique elements in a slice
Created April 25, 2018 00:19 — forked from johnwesonga/unique elements in a slice
Go code that ensures elements in a slice are unique
package main
import "fmt"
func uniqueNonEmptyElementsOf(s []string) []string {
unique := make(map[string]bool, len(s))
us := make([]string, len(unique))
for _, elem := range s {
if len(elem) != 0 {
if !unique[elem] {
@bernardolm
bernardolm / github-digest.py
Created September 16, 2019 23:14 — forked from yagotome/github-digest.py
Resumo do arquivo de logs do github, rode esse script com python3 e com o pandas instalado (pip install pandas)
import sys
import pandas as pd
def parse_line(line):
return list(map(lambda l: l.strip(), line.split('|')))
with open(sys.argv[1], 'r', encoding='utf8') as f:
lines = f.readlines()
[header, _, *rows] = lines
@bernardolm
bernardolm / workerpool.go
Last active August 12, 2020 23:19 — forked from alexrios/workerpool.go
Golang Worker Pool
package main
import (
"fmt"
"strconv"
"sync"
"time"
)
type Job struct {
package main
import (
"encoding/json"
"fmt"
)
type amenity struct {
Category string `json:"category"`
Name string `json:"name"`
input=(73 foobar)
rg="^[+\-]{0,1}[0-9]+$"
for num in "${input[@]}"; do
(echo "${num//[^\-+0-9]/}" | grep -Eq $rg) \
&& echo "$num is a number" \
|| echo "$num is not a number";
nnum="-"$num
(echo "${nnum//[^\-+0-9]/}" | grep -Eq $rg) \
@bernardolm
bernardolm / a2dp
Created October 26, 2022 00:34 — forked from takeseem/a2dp
Fixing bluetooth headset problem in xubuntu 16.04.
#!/bin/bash
# headset mac
mac="00:1D:DF:67:0A:29"
profile="a2dp"
# Special Bluetooth controller
btMac=""
# connect|disconnect wait time
waitTime=5
macId="${mac//:/_}"
title:jpcd12 - 2023-06-22
description:https://youtu.be/EJLkdqAKgIA?si=rCmxgO-Dv3fkduML
// Raconteur (pve)
//notes: tags:pve
dimwishlist:item=45643573&perks=1583705720,124408337
dimwishlist:item=45643573&perks=1583705720,1171887445
dimwishlist:item=45643573&perks=1409206216,124408337
dimwishlist:item=45643573&perks=1409206216,1171887445