Skip to content

Instantly share code, notes, and snippets.

View ogiovannyoliveira's full-sized avatar
🔥
Focusing

Giovanny Oliveira ogiovannyoliveira

🔥
Focusing
View GitHub Profile
@ogiovannyoliveira
ogiovannyoliveira / transformSeconds.dart
Last active April 9, 2020 14:14
Transformando segundos em dias, horas, minutos e segundos
int segundos = 86400;
int days = (segundos / 86400).floor();
int hours = ((segundos - (days * 86400)) / 3600).floor();
int minutes;
int seconds;
minutes = ((segundos - (days * 86400) - (hours * 3600)) / 60).floor();
seconds = (segundos - (days * 86400) - (hours * 3600) - (minutes * 60)).floor();
@ogiovannyoliveira
ogiovannyoliveira / accumulative.sql
Last active April 9, 2020 14:10
Consulta SQL com valor acumulativo.
SELECT
sum(sum(column)) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as accumulated
FROM
table
WHERE id_foo = ?
@ogiovannyoliveira
ogiovannyoliveira / previewImage.vue
Last active April 9, 2020 14:07
File example for preview of images before upload
<template>
<div>
<input ref="inputFile" type="file" accept="image/*" hidden @change="upload">
<button @click="openInputFile">Upload</button>
<div>
<div v-show="view">
<img id="imgFile" style="width: 600px; height: 400px" />
<button @click="cleanInputFile"><i>&times;</i></button>
</div>
</div>
@ogiovannyoliveira
ogiovannyoliveira / locale.sql
Created April 9, 2020 14:13
Pegar todos os dados em um raio de X km de acordo com as coordenadas
SELECT
*
FROM
geo_located_data
WHERE
111.195 * sqrt(power(latitude-($1),2) + power(cos(pi()/180*($2))*(longitude-($2)),2)) < $3
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)
@ogiovannyoliveira
ogiovannyoliveira / dockerUpWithoutCache.sh
Last active July 5, 2020 18:30
Docker command for up a container without use the cache and in detached mode
sudo docker-compose -f docker-compose.yml build --no-cache --force-rm
&& sudo docker-compose -f docker-compose.yml up -d
&& sudo docker image prune -a -f
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee
/etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn
@ogiovannyoliveira
ogiovannyoliveira / capturePercentual.ts
Created July 31, 2020 14:12
Function that returns the percentage of the time elapsed between two dates
export const capturarPercentualTempoDecorridoPasso = (data_inicial: Date | null, data_final: Date | null, tempo_padrao: number): number => {
if (!data_inicial) {
return 0
}
const hs3 = 10800
const segundosTotal = tempo_padrao * 60 * 60
const inicio = moment(data_inicial).unix() - hs3
const fim = moment(data_final).unix() - hs3
@ogiovannyoliveira
ogiovannyoliveira / makeSlug.ts
Last active November 26, 2023 04:29
Make a slug from string
function makeSlug(value: string, separator?: string = '_'): string {
const mapAccentsHex: any = {
a : /[\xE0-\xE6]/g,
A : /[\xC0-\xC6]/g,
e : /[\xE8-\xEB]/g,
E : /[\xC8-\xCB]/g,
i : /[\xEC-\xEF]/g,
I : /[\xCC-\xCF]/g,
o : /[\xF2-\xF6]/g,
O : /[\xD2-\xD6]/g,
@ogiovannyoliveira
ogiovannyoliveira / lastSevenDaysData.sql
Created August 6, 2020 18:42
Searching and grouping datas per date, and formatting the date to day/month.
SELECT
count(*) as total,
TO_CHAR(the_date_here, 'DD/MM') as create_at
FROM
tabela
WHERE
the_date_here::date > CURRENT_DATE - 7
GROUP BY create_at
ORDER BY create_at ASC