Skip to content

Instantly share code, notes, and snippets.

View hieuwu's full-sized avatar

Hieu Vu hieuwu

View GitHub Profile
hieuwu / promotion_solution_knapsack_01.cpp
Last active May 20, 2021 23:28
Solution for promotion for EPOS C++
View promotion_solution_knapsack_01.cpp
#include <bits/stdc++.h>
using namespace std;
//1. Sort the list by input descending
//2. Get all inputs of the list item after sorted
//3. Get indexes list of item want to pick
//4. For each index in the list, get item at that index
//Time complexcity Worst case: O(N * Sum). N is the length of the array. Sum is the total value of the array
hieuwu / promotion_solution_knapsack_01.cs
Last active May 24, 2021 02:07
Solution for promotion for EPOS C#
View promotion_solution_knapsack_01.cs
using System;
using System.Collections.Generic;
using System.Linq;
namespace KnapsackForPromotion
//1. Sort the list by input descending (this is for the case we found (7,5) and (6,6) but we pick (6,6))
//2. Get all inputs of the list item after sorted
//3. Get indexes list of item want to pick
View CountTripletsSolution.kt
// Complete the countTriplets function below.
fun countTriplets(arr: Array<Long>, r: Long): Long {
var befMap = HashMap<Long, Int>()
var aftMap = HashMap<Long, Int>()
for(num in arr) {
if(aftMap.containsKey(num)) aftMap[num] = aftMap[num]!! + 1
else aftMap[num] = 1
hieuwu / FluentBindingAdapterMvxRecyclerView.cs
Last active January 24, 2022 09:35
Customized fluent binding with adapter, view holder for MvxRecyclerView
View FluentBindingAdapterMvxRecyclerView.cs
public class PersonItemAdapter : MvxRecyclerAdapter
public PersonItemAdapter(IMvxAndroidBindingContext bindingContext)
: base(bindingContext)
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
var itemBindingContext = new MvxAndroidBindingContext(parent.Context, BindingContext.LayoutInflaterHolder);
hieuwu / product.kt
Last active March 21, 2022 14:37
Product Entity
View product.kt
@Entity(tableName = "products")
data class Product(
@ColumnInfo(name = "productId")
val id: String,
@ColumnInfo(name = "name")
var name: String?,
hieuwu / LineItem.kt
Last active March 21, 2022 14:41
Line item entity
View LineItem.kt
@Entity(tableName = "line_items")
data class LineItem(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "lineItemId")
val id: Long,
@ColumnInfo(name = "productId")
val productId: String,
@ColumnInfo(name = "orderId")
hieuwu / order.kt
Created March 21, 2022 14:41
Order Entity
View order.kt
@Entity(tableName = "orders")
data class Order(
@ColumnInfo(name = "orderId")
val id: String,
@ColumnInfo(name = "status")
var status: String,
@ColumnInfo(name = "address")
hieuwu / LineItemAndProduct.kt
Created March 21, 2022 14:53
Line Item and Product One to one relationship
View LineItemAndProduct.kt
data class LineItemAndProduct(
@Embedded val lineItem: LineItem?,
parentColumn = "productId",
entityColumn = "productId",
entity = Product::class
val product: Product?
hieuwu / OrderWithLineItem.kt
Created March 21, 2022 14:54
Order and Line Item Many to one relationship
View OrderWithLineItem.kt
data class OrderWithLineItems(
@Embedded var order: Order,
parentColumn = "orderId",
entityColumn = "orderId",
entity = LineItem::class
val lineItemList: MutableList<LineItemAndProduct>
hieuwu / LineItemDao.kt
Last active March 21, 2022 15:01
Line Item dao
View LineItemDao.kt
interface LineItemDao {
//Get all line item in along with its product
@Query("SELECT * FROM line_items ")
fun getAll(): Flow<List<LineItemAndProduct>>
//Get line item in an order by orderId
@Query("SELECT * FROM line_items WHERE orderId = :orderId")