Skip to content

Instantly share code, notes, and snippets.

View hucancode's full-sized avatar
🐼

Bang Nguyen Huu hucancode

🐼
View GitHub Profile
@hucancode
hucancode / segment-tree.cpp
Last active September 21, 2023 23:34
Segment Tree
class SegmentTree {
private:
vector<int> data;
int n;
public:
SegmentTree() {
}
void resize(int len) {
n = len;
data.resize(4*n, 0);
@hucancode
hucancode / output.log
Created September 15, 2023 02:33
Learn RefCell with recursive struct
John: RefCell { value: Person { name: "John", partner: Some((Weak)) } }
John's partner: Some("Susan")
Susan: RefCell { value: Person { name: "Susan", partner: Some((Weak)) } }
Susan's partner: Some("John")
John's partner after dropping Susan:
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/main.rs:16:51
@hucancode
hucancode / linked_list.rs
Last active September 15, 2023 07:00
Learn Rust Option<Box<T>>(which is Recursivable Nullable Single Owner Object) by implementing a linked list
use std::fmt::Debug;
#[derive(Debug)]
struct Node {
value: i32,
next: Option<Box<Node>>,
}
impl Node {
fn new(x: i32) -> Self {
Self {
import { useState, useEffect } from "react";
import {useSelector, useDispatch} from 'react-redux'
import { v4 as uuidv4 } from 'uuid';
import moment from "moment";
function Payment() {
const [current, setCurrent] = useState({})
const [done, setDone] = useState(false)
const [total, setTotal] = useState(0)
const cartList = JSON.parse(localStorage.getItem('CART'))
useEffect(() => {
@hucancode
hucancode / like.html
Last active February 23, 2023 06:13
like/heart animation. see it live here https://play.tailwindcss.com/x9sf8kkuqy
<div class="grid min-h-screen min-w-full place-items-center">
<div class="relative grid place-items-center">
<input type="checkbox" id="liked" class="peer appearance-none text-4xl text-gray-400 duration-200 before:content-['🤍'] checked:text-red-500 checked:before:content-['❤'] active:scale-75" />
<p class="absolute -bottom-full w-max opacity-0 duration-200 peer-checked:opacity-100">This button does nothing</p>
<label for="liked" class="absolute aspect-square origin-center rounded-full border-fuchsia-400 peer-checked:animate-bubble-expand" />
</div>
</div>
@tailwind base;
@tailwind components;
@tailwind utilities;
.gradient-text {
background: linear-gradient(
141.27deg,
#ff904e -4.24%,
#ff5982 21.25%,
#ec68f4 44.33%,
@hucancode
hucancode / dijkstra.cpp
Last active October 20, 2022 11:46
quick implementation of dijkstra
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, int> pli;
vl dijkstra(int n, map<int, vector<pli>>& adj, int start) {
vl dist(n, -1);
dist[start] = 0;
@hucancode
hucancode / codeforces.cpp
Created October 12, 2022 13:14
codeforces template
#include <bits/stdc++.h>
using namespace std;
void solve() {
}
int main() {
int t;
cin>>t;
@hucancode
hucancode / overlap.cpp
Last active September 14, 2022 02:21
check if 2 sorted lists of string have any overlaping item in O(logn)
// precondition: a & b are both sorted
bool overlap(vector<string>& a, vector<string>& b) {
auto i = a.begin();
auto j = b.begin();
auto n = upper_bound(i, a.end(), *b.rbegin());
auto m = upper_bound(j, b.end(), *a.rbegin());
while(i < n && j < m) {
if(*i == *j) {
return true;
}
@hucancode
hucancode / insertion_sort.cpp
Created September 6, 2022 00:36
insert into a sorted vector
void insertion_sort(vector<int>& a, int& value) {
a.insert(upper_bound(a.begin(), a.end(), value), value);
}