Skip to content

Instantly share code, notes, and snippets.

@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
@rhcarvalho
rhcarvalho / test.yml
Created August 3, 2022 10:46
Building golangci-lint from source in a GitHub Workflow
# .github/workflows/test.yml
# ...
jobs:
# ...
lint-go:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
@rhcarvalho
rhcarvalho / ctx.py
Created June 28, 2021 11:50
Python ContextVars don't propagate across exception handling boundaries
# coding: utf-8
import contextvars
import sys
v = contextvars.ContextVar('v')
v.set('global default')
def code():
print(f'before: v={v.get()}')
@rhcarvalho
rhcarvalho / main.go
Created June 15, 2021 15:02
Sentry Go SDK - how to manually propagate traces in arbitrary programs
// This is an example program that demonstrates how to continue a Sentry trace
// for a hypothetical and arbitrary job runner, not a typical web server.
//
// Try it by running:
//
// go run main.go new
// go run main.go 55c41d7f4727204c592c87974aa1eedb-01ae7746826ce117-1
//
// To actually report events to Sentry, set the DSN either by editing the
// appropriate line below or setting the environment variable SENTRY_DSN to
@rhcarvalho
rhcarvalho / main.go
Created September 3, 2020 10:12
Smart timestamps in Go: decode/encode JSON from Unix timestamp numbers or RFC3339 strings
// https://play.golang.org/p/wSZvxQbT3KY
package main
import (
"encoding/json"
"fmt"
"os"
"strconv"
"text/tabwriter"
@rhcarvalho
rhcarvalho / go.mod
Last active October 21, 2024 13:37
Example of using sentry-go and go-chi
module sentry.io/go/chi-example
go 1.13
require (
github.com/getsentry/sentry-go v0.4.0
github.com/go-chi/chi v4.0.3+incompatible
)
@rhcarvalho
rhcarvalho / main.go
Created December 6, 2019 14:24
Go cannot capture panics in arbitrary goroutines - https://play.golang.org/p/_YUfKreCkeY
package main
import (
"fmt"
)
func main() {
done := make(chan int)
defer func() {
<-done
@rhcarvalho
rhcarvalho / main.dart
Created February 11, 2019 10:40
Dart constructors are not really functions
class Greeter {
final String name;
Greeter(this.name);
Greeter.withName(this.name);
static Greeter staticWithName(String name) {
return Greeter(name);
}
void greet(String who) {
@rhcarvalho
rhcarvalho / README.md
Created February 2, 2017 09:04
DojoTimer helper for Linux

DojoTimer helper for Linux

This script is used to launch DojoTimer on Linux/Mono.

Place both dojotimer and dojotimer.exe in one of the directories in your $PATH. I place then in ~/bin.

Now, from the working directory of your dojo, where you will have your tests and implementation, run:

dojotimer .
@rhcarvalho
rhcarvalho / .gitconfig
Created November 6, 2016 09:36
Git config for large repositories
# This file represents part of the .git/config file for a given repository.
# The settings below allow git-pack-objects to work on large repositories (e.g., Kubernetes, OpenShift Origin, ...).
[core]
packedGitLimit = 4g
[pack]
windowMemory = 256m
# packSizeLimit = ...