Skip to content

Instantly share code, notes, and snippets.

View Wigny's full-sized avatar

Wígny Almeida Wigny

View GitHub Profile
@rhcarvalho
rhcarvalho / batcher_demo.exs
Created August 29, 2024 09:20
Phoenix LiveView event batching
# Single-file Phoenix LiveView demo showing how to batch events to reduce/control the flow of UI updates.
#
# Run with `elixir batcher_demo.exs`, then open a browser at http://localhost:5001/.
#
# For comparison, the "inc" event is batched while the "dec" event is not.
#
# References
#
# https://github.com/phoenixframework/phoenix_live_view/blob/main/.github/single-file-samples/main.exs
# https://elixirforum.com/t/optimizing-liveview-for-realtime-applications-by-marlus-saraiva-elixirconf-eu-2023/59265?u=rhcarvalho
@chrismccord
chrismccord / dev.exs
Created May 8, 2024 20:06
Live Reload LiveView notify
config :wps, WPSWeb.Endpoint,
live_reload: [
notify: [
live_view: [
~r"lib/wps_web/core_components.ex$",
~r"lib/wps_web/(live|components)/.*(ex|heex)$"
]
],
patterns: [
~r"priv/static/(?!uploads/).*(js|css|png|jpeg|jpg|gif|svg)$",
Mix.install([:mint, :castore])
defmodule Main do
def run() do
total =
Stream.resource(
fn ->
{:ok, conn} = Mint.HTTP.connect(:https, "ftp.bit.nl", 443, mode: :passive)
{:ok, conn, _ref} = Mint.HTTP.request(conn, "GET", "/speedtest/10mb.bin", [], nil)
{conn, true}
@kamiaka
kamiaka / duration.ts
Last active September 29, 2024 05:38
Convert time durations on TypeScript (JavaScript)
export class DurationUnit {
constructor(public readonly value: number, public readonly name: string) {}
}
export const nanoSecond = new DurationUnit(1, 'ns');
export const microSecond = new DurationUnit(1000 * nanoSecond.value, 'µs');
export const milliSecond = new DurationUnit(1000 * microSecond.value, 'ms');
export const second = new DurationUnit(1000 * milliSecond.value, 's');
export const minute = new DurationUnit(60 * second.value, 'm');
export const hour = new DurationUnit(60 * minute.value, 'h');
@sharunkumar
sharunkumar / adb-dns.bat
Created February 7, 2020 07:08
Enabling / Disabling private DNS in android via ADB
rem to disable private dns
adb shell settings put global private_dns_mode off
rem to enable private dns with hostname (example with dns.adguard.com)
adb shell settings put global private_dns_mode hostname
adb shell settings put global private_dns_specifier dns.adguard.com
@char0n
char0n / api_data_structure.ex
Last active August 1, 2022 16:03
Model example how to use Ecto to validate nested JSON data in you API payloads
defmodule ApiDataStructure do
defmodule User do
use Ecto.Schema
import Ecto.Changeset
alias ApiDataStructure.Profile
embedded_schema do
field :username, :string
@seocam
seocam / csv2contabilizei_ofx.py
Last active December 28, 2024 21:20
Converte CSV para um arquivo OFX aceito pela contabilizei
#!/usr/bin/env python
import argparse
import calendar
import itertools as it
from datetime import datetime
from csv2ofx import utils
from csv2ofx.mappings.default import mapping
from csv2ofx.ofx import OFX
@qoomon
qoomon / conventional-commits-cheatsheet.md
Last active June 9, 2025 10:18
Conventional Commits Cheatsheet
@tzmartin
tzmartin / embedded-file-viewer.md
Last active June 8, 2025 17:52
Embedded File Viewer: Google Drive, OneDrive

Office Web Apps Viewer

('.ppt' '.pptx' '.doc', '.docx', '.xls', '.xlsx')

http://view.officeapps.live.com/op/view.aspx?src=[OFFICE_FILE_URL]

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=[OFFICE_FILE_URL]' width='px' height='px' frameborder='0'>
</iframe>

OneDrive Embed Links

@josevalim
josevalim / watcher.sh
Last active May 22, 2024 10:06
A 1LOC bash script for re-running tests whenever a lib/ or test/ file changes keeping the same VM instance
# You will need fswatch installed (available in homebrew and friends)
# The command below will run tests and wait until fswatch writes something.
# The --stale flag will only run stale entries, it requires Elixir v1.3.
fswatch lib/ test/ | mix test --stale --listen-on-stdin