This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select pg_terminate_backend(pid) | |
from pg_stat_activity | |
where datname='dbname'; | |
drop database if exists "dbname"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function requestNotificationPermission() { | |
Notification.requestPermission().then(p => { | |
if (p === "granted") { | |
console.log("Thank you") | |
} else { | |
console.log("😔") | |
} | |
}).catch(function (err) { | |
console.log(err) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule T do | |
import Ecto.Query | |
alias MyApp.Repo | |
def test() do | |
from(s in "users", select: [:id]) |> Repo.one() | |
rescue | |
Ecto.MultipleResultsError -> IO.puts("Sorry. Things didn't go well.") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule ServiceSwitcher do | |
defmacro __using__(opts \\ []) do | |
service_module_mapping = opts[:service_module_mapping] | |
quote do | |
@service_module_mapping unquote(service_module_mapping) | |
@services Keyword.keys(@service_module_mapping) | |
def get_service_module(service) when is_binary(service), | |
do: service |> String.to_atom() |> get_service_module() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shopping_cart = [ | |
{"item": "Apple", "price": 0.5, "quantity": 10}, | |
{"item": "Milk", "price": 1.5, "quantity": 2}, | |
{"item": "Bread", "price": 2.0, "quantity": 1} | |
] | |
def item_cost(item): | |
return item["price"] * item["quantity"] | |
sum(map(item_cost, shopping_cart)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule UserMapperFunctions do | |
def map_my_address(%{ | |
address: address, | |
city: city, | |
province: province, | |
country: country, | |
postalCode: postalCode | |
}) do | |
"#{address}, #{city}, #{province}, #{country}, #{postalCode}" | |
end |