Skip to content

Instantly share code, notes, and snippets.

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

Jorge Vilaça jorgevilaca82

🏠
Working from home
View GitHub Profile
function requestNotificationPermission() {
Notification.requestPermission().then(p => {
if (p === "granted") {
console.log("Thank you")
} else {
console.log("😔")
}
}).catch(function (err) {
console.log(err)
})
@jorgevilaca82
jorgevilaca82 / utils.ex
Created January 19, 2023 14:47
check for blank values
defmodule Utils do
def is_blank(nil), do: true
def is_blank(val) when val == %{}, do: true
def is_blank(val) when val == [], do: true
def is_blank(val) when is_binary(val), do: String.trim(val) == ""
def is_blank(val), do: false
end
@jorgevilaca82
jorgevilaca82 / currency_notification.js
Created January 18, 2023 15:22
Notifys you when a target value is reached
Notification.requestPermission()
const CURRENCY = "USD-BRL"
let myTargetValue = window.prompt("Targe value")
let intervalId = null
async function checkCurrency(targeValue, currency) {
let currencyKey = currency.replace("-", "")
let response = await fetch(`https://economia.awesomeapi.com.br/last/${currency}`)
pessoas = [
{ 'nome': 'João', "idade": 64 },
{ 'nome': 'Janete', "idade": 34 },
{ 'nome': 'Eduardo', "idade": 24 },
{ 'nome': 'Sara', "idade": 64 },
{ 'nome': 'José', "idade": 32 },
{ 'nome': 'Lisa', "idade": 34 },
{ 'nome': 'Mário', "idade": 99 },
]
select pg_terminate_backend(pid)
from pg_stat_activity
where datname='dbname';
drop database if exists "dbname";
@jorgevilaca82
jorgevilaca82 / sql-server-pagination.sql
Created April 8, 2017 01:03
Páginação SQL Server
SELECT * FROM Tabela
ORDER BY (SELECT NULL)
OFFSET 3 ROWS FETCH NEXT 1 ROWS ONLY;
-- numero de registros por página
declare @PERPAGE int = 1;
select ((select count(*) from sala) / @PERPAGE) as QTD_PAG;