Skip to content

Instantly share code, notes, and snippets.

View Wigny's full-sized avatar

Wígny Almeida Wigny

  • Up Learn
  • Ji-Paraná - RO
  • 08:44 (UTC -04:00)
View GitHub Profile
@Wigny
Wigny / filereader-to-rxjs.ts
Last active June 5, 2020 13:31
FileReader for RxJS
private readFile = (blob: Blob): Observable<string> => new Observable((obs: Subscriber<string>) => {
if (!(blob instanceof Blob)) {
obs.error(new Error('`blob` must be an instance of File or Blob.'));
return;
}
const reader = new FileReader();
reader.onerror = err => obs.error(err);
reader.onabort = err => obs.error(err);
class Aluno {
String nome;
int idade;
Aluno(String nome, int idade) {
this.nome = nome;
this.idade = idade;
}
}
void main() {
var n = <int>[54, 1, 30, 4, 0];
for (var i = 0; i < n.length; i++) {
for (var j = 0; j < n.length - 1; j++) {
var maior = 0;
if (n[j] > n[j + 1]) {
maior = n[j];
n[j] = n[j + 1];

Step 1

Run on terminal

heroku create --buildpack hashnuke/elixir

Step 2

Create file elixir_buildpack.config with content:

elixir_version=<VERSION>
defmodule Example.Authorization do
defprotocol Store do
def allowed?(resource, actor, action)
end
defmacro defauthorized(fun, opts) do
quote bind_quoted: [fun: Macro.escape(fun, unquote: true), opts: opts], location: :keep do
{fun_name, fun_args} = Macro.decompose_call(fun)
resource = List.first(fun_args)
action = Keyword.get(opts, :action)
@Wigny
Wigny / uploader.ex
Last active May 17, 2023 17:31
Phoenix external upload to GCS
Application.put_env(:uploader, Uploader.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 4001],
server: true,
render_errors: [
formats: [html: Uploader.ErrorHTML],
layout: false
],
live_view: [signing_salt: "aaaaaaaa"],
secret_key_base: String.duplicate("a", 64)
)
docker run -d --restart unless-stopped --name parking_lot_database -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=parking_lot -p 5432:5432 -v postgres:/var/lib/postgresql/data postgres
echo 'DATABASE_URL=ecto://postgres:postgres@172.17.0.1:5432/parking_lot' >> ~/parking_lot.env
echo 'SECRET_KEY_BASE=my_ramdom_secure_and_at_least_64_bits_long_secret_______________' >> ~/parking_lot.env
echo 'PHX_HOST=127.0.0.1' >> ~/parking_lot.env
echo 'CACHE_DIR=/data' >> ~/parking_lot.env
docker pull ghcr.io/wigny/parking_lot:latest
docker run --env-file ~/parking_lot.env -it ghcr.io/wigny/parking_lot bin/migrate
docker run --name parking_lot --restart unless-stopped --env-file ~/parking_lot.env -p 4000:4000 -v /tmp:/data -itd ghcr.io/wigny/parking_lot
Mix.install([evision: "~> 0.1"],
system_env: [
EVISION_PREFER_PRECOMPILED: "false",
CMAKE_OPENCV_OPTIONS: "-D WITH_FFMPEG=ON"
]
)
alias Evision.VideoCapture
url = "rtsp://172.28.6.108:8554/mystream"
defmodule DefBang do
defmacro def!(call, do: block) do
quote bind_quoted: [call: Macro.escape(call, unquote: true), block: Macro.escape(block)], location: :keep do
{name, args} = Macro.decompose_call(call)
def unquote(name)(unquote_splicing(args)) do
unquote(block)
end
def unquote(:"#{name}!")(unquote_splicing(args)) do
defmodule DefMaybe do
defmacro defmaybe(fun) do
quote bind_quoted: [fun: Macro.escape(fun, unquote: true)], location: :keep do
{fun_name, fun_args} = Macro.decompose_call(fun)
resource = List.first(fun_args)
action = Keyword.get(opts, :action)
def unquote(:"maybe_#{fun_name}")({:ok, unquote_splicing(fun_args)}) do
{:ok, unquote(fun_name)(unquote_splicing(fun_args))}
end