Skip to content

Instantly share code, notes, and snippets.

View dkuku's full-sized avatar

Daniel Kukula dkuku

View GitHub Profile
@dkuku
dkuku / proto_decoder.livemd
Created June 25, 2024 16:35
protobuf decoder

Untitled notebook

Section

defmodule ProtobufParser do
  import Bitwise
  require Logger

  def parse(binary) do
@dkuku
dkuku / test.exs
Last active June 17, 2024 05:48
Debugging flaky tests in elixir:
file_path = "/Users/you/debug"
# open file
{:ok, io_device} = File.open(file_path, [:append])
# get all schemas
:code.all_loaded()
|> Enum.map(&elem(&1, 0))
|> Enum.filter(&(to_string(&1) =~ "Schemas"))
|> Enum.map(fn schema ->
# KinoCurl
```elixir
Mix.install([
{:kino, "~> 0.12.3"},
{:req, "~> 0.4.14"}
])
```
## Sectionw
@dkuku
dkuku / keyword_guard.ex
Created February 29, 2024 23:40
keyword guard in elixir
# Abusing defguard for keyword lists
```elixir
Mix.install([
{:benchee, "~> 1.3"}
])
```
## Section
previous_fun = Inspect.Opts.default_inspect_fun()
hexdump = fn
value, opts when not is_binary(value) ->
# change base to hex - this way it will show binary numbers in instead of decimal
previous_fun.(value, %{opts | base: :hex})
value, opts ->
{:ok, string_io} = StringIO.open(value)

Untitled notebook

Mix.install([
  {:kino_explorer, "~> 0.1.11"},
  {:unzip, "~> 0.9.0"}
])
@dkuku
dkuku / repo.ex
Created December 2, 2023 07:36
Sqlcommenter with ecto examples
defmodule AdventureWorks.TracedRepo do
use Ecto.Repo,
otp_app: :adventure_works,
adapter: Ecto.Adapters.Postgres
def all_traced(queryable, opts \\ []) do
{metadata, opts} = Keyword.pop(opts, :metadata, %{})
{:current_stacktrace, stacktrace} = Process.info(self(), :current_stacktrace)
stacktrace =
@dkuku
dkuku / wb250f.livemd
Last active November 30, 2023 20:47
Fun with samsung cameras in livebook wb250f wb350f nx100 nx200 nx300 nx500 nx1000

WB250F remote access

Mix.install([
  {:req, "~> 0.4.5"},2
  {:xml_json, "~> 0.4.2"},
  {:kino, "~> 0.11.3"}
])
@dkuku
dkuku / howto.sh
Created November 3, 2023 18:44
script to use chatgpt as a command line helper
#!/bin/bash
if [ "$#" -eq 0 ]; then
echo "Usage: $0 <word1> <word2> <word3> ..."
exit 1
fi
API_KEY="$OPENAI_API_KEY"
USER_INPUT="$*"
code payment_plan payment_period_unit payment_period_multiplier fixed_price variable_price variable_price_from key_driver trial_days
GB subscription monthly 1 0 7.95 9.99 team_members 14
CH subscription monthly 1 0 8.95 11.99 team_members 14
CZ subscription monthly 1 0 219.95 249.99 team_members 14
HU subscription monthly 1 0 3499.95 4999.99 team_members 14