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 / 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)
{
@utilForever
utilForever / TriangleMesh.cpp
Created August 19, 2019 07:20
Create PxShape using PxTriangleMesh
physx::PxVec3* pPxVerts = new physx::PxVec3[list.vertexCount];
for (int i = 0; i < list.vertexCount; i++)
{
ConvertPosToPhysX(list.pVerts[i], pPxVerts[i]);
}
physx::PxU32* pPxIndices = new physx::PxU32[list.triangleCount * 3];
for (int i = 0; i < list.triangleCount * 3; ++i)
@utilForever
utilForever / localtime.hpp
Created June 16, 2019 07:39
Comparison between localtime_r and localtime_s
#include <ctime>
#include <iostream>
int is_morning_good() {
const time_t now_seconds = time(NULL);
struct tm now;
localtime_r(&now_seconds, &now);
return (now.tm_hour < 12);
}