Skip to content

Instantly share code, notes, and snippets.

View qhwa's full-sized avatar

Qiu Hua qhwa

View GitHub Profile
@qhwa
qhwa / quiz.md
Last active February 29, 2024 18:42
Virtual Delivery Windows

Daily Delivery Window Calculation

Background

In Zubale, each delivery order is assigned a specific time window during which the delivery must be completed. These windows typically span a few hours within the same day, for example, from 2:00 PM to 5:00 PM on 2nd March, 2024. Such windows have defined start and end times.

However, some orders may have delivery windows that span across multiple days. For instance:

start time end time
@qhwa
qhwa / init.lua
Last active July 30, 2022 23:34
Neovim config
-- file: lua/init.lua
local execute = vim.api.nvim_command
local fn = vim.fn
local fmt = string.format
local pack_path = fn.stdpath("data") .. "/site/pack"
-- ensure a given plugin from github.com/<user>/<repo> is cloned in the pack/packer/start directory
local function ensure (user, repo)
local install_path = fmt("%s/packer/start/%s", pack_path, repo)
@qhwa
qhwa / representation.livemd
Last active February 11, 2022 22:13
Representation: A Rule Service in Elixir

A Rule Service in Elixir

Agenda

  1. A Rule Engine, What & Why?
  2. Formular: Elixir As DSL
@qhwa
qhwa / quest.json
Last active January 6, 2022 23:35
Quest data structure
{
"id": "61d77681feda7600019c9822",
"storeLocation": {
"latitude": 19.4418277,
"longitude": -99.2069606
},
"dropOffLocation": {
"latitude": 19.4266579,
"longitude": -99.17311339
}
@qhwa
qhwa / quiz.md
Last active October 6, 2021 23:17
quiz

Problem

Rich text in apps like Notion are represented in a JSON-based format for consistency and specificity. A simplified version for a nested list might look something like this:

[
  { "text": "One",   "indent": 0, "type": "ordered" },
  { "text": "Two",   "indent": 0, "type": "ordered" },
  { "text": "Alpha", "indent": 1, "type": "bullet"  },
@qhwa
qhwa / test.exs
Created August 15, 2021 23:39
Sum of owest two numbers
defmodule TwoLowest do
def sum_of_two_lowest(numbers) do
numbers
|> lowest_two()
|> IO.inspect(label: :lowest_two)
|> sum()
|> IO.inspect(label: :sum)
end
defp lowest_two(numbers, found \\ [])
defmodule MyRegister do
@enforce_keys [:email]
defstruct [:email, valid?: true, errors: nil]
def register_user_email(email) do
%__MODULE__{email: email}
|> ok_then(&ensure_not_nil/1)
|> ok_then(&downcase/1)
|> ok_then(&validate_format/1)
@qhwa
qhwa / even_numbers.exs
Created July 30, 2020 11:02
Check numbers
use Bitwise
even? = fn number ->
(number &&& 1) == 0
end
0..20
|> Enum.filter(even?)
@qhwa
qhwa / hit_rate.exs
Created June 5, 2020 02:25
hit_rate
defmodule HitRate do
@moduledoc """
Documentation for `HitRate`.
"""
def calc(file_path) do
file_path
|> stream()
|> Enum.to_list()
|> IO.inspect(label: :stream)
@qhwa
qhwa / charlist.exs
Created May 10, 2020 12:53
Elixir Charlist
iex> 'l🍭p'
[108, 127853, 112]