Skip to content

Instantly share code, notes, and snippets.

@haodt
haodt / metrics-post.json
Created April 18, 2026 06:27
sidebar-material-icons-layout-push-20260418 verification metrics
{
"mode": "post",
"tokenPresent": false,
"collapsedFlyout": {
"navigatedPathname": "/order/status"
},
"lightTheme": {
"pathname": "/home"
},
"routes": {
@haodt
haodt / resume.pdf
Last active April 4, 2023 07:30
Resume
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@haodt
haodt / pattern-matching.ex
Last active February 10, 2022 04:45
Elixir cheatsheet
# Pin variable from previous match
with %{account_id: account_id} <- conn.assigns.current_user,
customer = %{account_id: ^account_id} <-
Customers.get_customer!(id, preloads) do
assign(conn, :current_customer, customer)
else
_ -> ChatApiWeb.FallbackController.call(conn, {:error, :not_found}) |> halt()
end
# Match on same value
@haodt
haodt / hoc.tsx
Last active January 13, 2022 10:56
React tips and tricks
// How to extract components to HOC
// Think of HoC as vue slots, we leverage it to makeing views mostly
// identical to each other except few things like text on bottom or extra images
// or swapping some children components
// https://www.patterns.dev/posts/hoc-pattern/
// step 1
@haodt
haodt / facebook.svg
Last active March 18, 2021 10:46
assets
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@haodt
haodt / joi.js
Created December 23, 2020 07:22
Schema validation tricks
schema = Joi.array().items(
Joi.object({
status: Joi.any().valid("ACTIVE").strip(),
id: Joi.string(),
}),
Joi.object({
status: Joi.any().valid("DEACTIVATED"),
id: Joi.string(),
}).strip()
)
@haodt
haodt / repo.ex
Created August 21, 2020 03:29
UUID guard
defmacro is_uuid(value) do
quote do
is_binary(unquote(value)) and byte_size(unquote(value)) == 36 and
binary_part(unquote(value), 8, 1) == "-" and binary_part(unquote(value), 13, 1) == "-" and
binary_part(unquote(value), 18, 1) == "-" and
binary_part(unquote(value), 23, 1) == "-"
end
end
@haodt
haodt / repo.ex
Last active August 17, 2020 06:33
Jason encode for ecto.schema
defmodule YourApp.Repo.Schema do
@moduledoc """
Example:
def YourApp.Blog do
use YourApp.Repo.Schema
end
iex> %YourApp{} |> Jason.encode!()
"""
@haodt
haodt / print_linked_list_reverse.php
Created August 20, 2017 19:28
Print linked list in reverse order
Print a linked list reverse
- Using recursive loop to reach the end, then print value
<?php
function print_node($node) {
if ($node->next) {
print_node($node->next);
}
var_dump($node->value);
}
@haodt
haodt / crossing_the_bridge.php
Created August 20, 2017 19:26
Crossing bridge
Given a list of people [A,B,C,D,E]
- with an average speed to cross a bridge [1,3,5,7,9]
- only 2 people can go at a same time
- they have to take a flashlight when crossing the bridge(which mean after crossing, one must run back)
Calculate the shortest time it takes for the whole group to go to other side of the bridge
<?php
/**