Skip to content

Instantly share code, notes, and snippets.

View utilForever's full-sized avatar

Chris Ohk utilForever

View GitHub Profile
@utilForever
utilForever / protobuf_parsing.rs
Created January 23, 2024 05:26
Exercise - Protobuf Parsing
use std::convert::TryFrom;
use thiserror::Error;
#[derive(Debug, Error)]
enum Error {
#[error("Invalid varint")]
InvalidVarint,
#[error("Invalid wire-type")]
InvalidWireType,
#[error("Unexpected EOF")]
@utilForever
utilForever / health_statistics.rs
Created January 23, 2024 05:25
Exercise - Health Statistics
// TODO: remove this when you're done with your implementation.
#![allow(unused_variables, dead_code)]
#![allow(dead_code)]
pub struct User {
name: String,
age: u32,
height: f32,
visit_count: usize,
@utilForever
utilForever / binary_tree.rs
Created January 23, 2024 05:20
Exercise - Binary Tree
/// A node in the binary tree.
#[derive(Debug)]
struct Node<T: Ord> {
value: T,
left: Subtree<T>,
right: Subtree<T>,
}
/// A possibly-empty subtree.
#[derive(Debug)]
@utilForever
utilForever / FSM.cpp
Created September 2, 2016 11:34
Finite State Machine Example
#include <iostream>
#include <string>
enum States { IDLE, MOVE, YUMYUM, EAT, DIE, CLEAR, FINISH };
void RunLogic(States);
int main()
{
// FSM : Finite State Machine (유한 상태 기계)
@utilForever
utilForever / SimpleReflection.cpp
Created August 25, 2016 01:54
Simple reflection on C++17 [Very simple approach to convert any struct (up to N members) to a tuple using C++17 structured bindings and the idea from Boost.DI]
#include <tuple>
#include <type_traits>
#include <cassert>
template <class T, class... TArgs> decltype(void(T{std::declval<TArgs>()...}), std::true_type{}) test_is_braces_constructible(int);
template <class, class...> std::false_type test_is_braces_constructible(...);
template <class T, class... TArgs> using is_braces_constructible = decltype(test_is_braces_constructible<T, TArgs...>(0));
struct any_type {
template<class T>
@utilForever
utilForever / split.cpp
Created April 1, 2021 15:46
Split String in C++
//! Splits a string \p str using \p delim.
//! \param str An original string.
//! \param delim A string delimiter to split.
//! \return A splitted string.
inline std::vector<std::string> SplitString(const std::string& str,
const std::string& delim)
{
std::vector<std::string> tokens;
std::size_t prev = 0, pos;
@utilForever
utilForever / SimplePointer.hpp
Created November 25, 2020 14:16
Simple pointer
#include<iostream>
#include<stdexcept>
template <class T>
class SimplePointer {
T* ptr;
int size;
void boundarychk(int idx);
public:
SimplePointer();
@utilForever
utilForever / DRG_321.cpp
Created March 28, 2020 10:29
The logic of card 'Rolling Fireball' (DRG_321)
// ------------------------------------------- SPELL - MAGE
// [DRG_321] Rolling Fireball - COST:5
// - Set: Dragons, Rarity: Epic
// --------------------------------------------------------
// Text: Deal 8 damage to a minion. Any excess damage
// continues to the left or right.
// --------------------------------------------------------
// GameTag:
// - ImmuneToSpellpower = 1
// --------------------------------------------------------
@utilForever
utilForever / DRG_306.cpp
Created March 27, 2020 12:39
The logic of card 'Envoy of Lazul' (DRG_306)
// ---------------------------------------- MINION - PRIEST
// [DRG_306] Envoy of Lazul - COST:2 [ATK:2/HP:2]
// - Set: Dragons, Rarity: Epic
// --------------------------------------------------------
// Text: <b>Battlecry:</b> Look at 3 cards.
// Guess which one is in your opponent's hand
// to get a copy of it.
// --------------------------------------------------------
// GameTag:
// - BATTLECRY = 1
@utilForever
utilForever / unique_ptr.h
Created January 14, 2020 09:07
Simple unique_ptr Test
class A
{
public:
static std::unique_ptr<IEffect> AttackN(int n)
{
return B::Attack(n);
}
static std::unique_ptr<IEffect> HealthN(int n)
{