Skip to content

Instantly share code, notes, and snippets.

View FrankApiyo's full-sized avatar
:shipit:
Crafting clean code, one commit at a time.

Frankline Apiyo FrankApiyo

:shipit:
Crafting clean code, one commit at a time.
View GitHub Profile
@FrankApiyo
FrankApiyo / timex_timezone_converstion.ex
Created May 1, 2025 08:19
Timex timezone conversion
result =
case Timex.parse(datetime_str, "{ISO:Extended}") do
{:ok, datetime} ->
datetime
|> Timex.to_datetime(from_tz)
|> Timex.Timezone.convert(to_tz)
|> Timex.format!("%Y-%m-%d %H:%M:%S %Z", :strftime)
_ ->
"Invalid datetime format"
@FrankApiyo
FrankApiyo / regex.ex
Created April 27, 2025 13:37
Regular expression to check if a string is base 64 in elixir
~r/^[A-Za-z0-9]+$/
~r/^[A-Za-z0-9]{6}$/
@FrankApiyo
FrankApiyo / sample_lv_test.ex
Last active April 28, 2025 04:57
Sample LV test
defmodule AppNameWeb.LvLiveTest do
use UrlshortenerWeb.ConnCase, async: true
import Phoenix.LiveViewTest
describe "LV test" do
test "we can render the view", %{conn: conn} do
{:ok, _lv, html} = live(conn, ~p"/")
# open_browser(lv)
@FrankApiyo
FrankApiyo / phoenix.md
Last active April 26, 2025 15:53
Steps for scaffolding a demo phoenix app
mix phx.new --binary-id budgie
# add docker-compose.yml below
mix setup
mix phx.gen.auth Accounts User users --hashing-lib argon2

Edit mix.ex

defp deps do
@FrankApiyo
FrankApiyo / guards.ex
Created April 25, 2025 05:56
UUID route guard
defmodule MyApp.Guards do
defguard is_uuid(value)
when is_binary(value) and byte_size(value) == 36 and
binary_part(value, 1, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and
binary_part(value, 2, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and
binary_part(value, 3, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and
binary_part(value, 4, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and
binary_part(value, 5, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and
binary_part(value, 6, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and
binary_part(value, 7, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and
@FrankApiyo
FrankApiyo / gist:0e94be3eac63f94d7a99fb01714f1e48
Last active November 19, 2024 06:30
Configure sops differ with git
git config diff.sopsdiffer.textconv "sops --decrypt --config /dev/null"
@FrankApiyo
FrankApiyo / utils.sql
Created January 6, 2024 12:00 — forked from parallelo3301/utils.sql
PostgreSQL utils
-- v5
----------------------------------------------------------- basic instance info
-- show db version
SELECT version();
-- uptime
SELECT pg_postmaster_start_time();
-- show connections
{
"data": {"values":
[
{"_submitted_by": "dalli",
"INTRO_DISTRICT": [
"Afgooye"
],
"count": 1
},
{"_submitted_by": "dalli",
@FrankApiyo
FrankApiyo / Generators.md
Last active June 20, 2021 09:34
Generators[python]

Generators are implemented with syntax very similar to functions, but instead of returning values, a yield statement is executed to indicate each element in the series

Consider the goal of computing all factors of a positive integer. A traditional function might return a list contating all factors, implemeted as follows:

def factors(n):            # traditional function that computes factors
  results = []             # store factors in a new list
  for k in range(1, n+1):
    if n % k == 0:         # divides evenly, thus k is a factor
 results.append(k) # add k to the list of factors