Skip to content

Instantly share code, notes, and snippets.

View sonnguyen9800's full-sized avatar
💥
Doing Projects

Son Nguyen Hoang sonnguyen9800

💥
Doing Projects
View GitHub Profile
@sonnguyen9800
sonnguyen9800 / UIDialogTutorial.cs
Created September 2, 2025 10:10
[Unity] Auto height increase based on number of lineCount in TMP_Text
using UnityEngine;
using UnityEngine.UI;
using TMPro;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Game
{
@sonnguyen9800
sonnguyen9800 / SnapRectTransform.cs
Last active September 2, 2025 03:18
[Unity] Quickly snap rect to any target RectTransform
// The idea is super simple:
// 1. Set rect transform to be moved to be children of target Rect.
// 2. As a children -> Set local position to 0,0,0
// 3. Set parent of our transform to the old parent (again)
//
// This script is originally used for a HandTutorialObject, so that it points to correct UI Object. This is done because setting
// rectTransform.position proved to be incorrect when target Rect inside a LayoutGroup, ... etc.
using System.Collections;
using UnityEngine;
@sonnguyen9800
sonnguyen9800 / SampleDictionary.lua
Created July 17, 2024 04:36
Roblox, Lua, Sample of Dictionary
local SoulType = require(game.ReplicatedStorage.Shared.define.play).SpiritType
local UIConfigGlobal = {
}
UIConfigGlobal.StatsPanel = {
[SoulType.Red] = {
Name = "Hyper Star",
Color = Color3.fromRGB(255, 0, 127),
@sonnguyen9800
sonnguyen9800 / SieveOfEratosthenesOnPrime.cs
Created July 12, 2024 10:01
Sieve of Eratosthenes - An algorithm to find prime number
public static class SieveOfEratos {
private static int[] GenerateArray(int n) => Enumerable.Range(2, n-1).ToArray(); // generate from 2 -> n
private static bool[] GenerateArrayOfOnes(int n) => Enumerable.Repeat(true, n).ToArray();
public static int[] SieveofEratosAlgorithm(int upperLimited)
{
int[] allNumbers = GenerateArray(upperLimited);
bool[] allMarker = GenerateArrayOfOnes(allNumbers.Length);
int maxValue = allNumbers[allNumbers.Length - 1]; // last value (always the greatest)
for (int i = 0; i < allNumbers.Length; i++)
@sonnguyen9800
sonnguyen9800 / cgp.md
Created June 30, 2024 08:44 — forked from notnotrobby/cgp.md
List of free resources to study computer graphics programming.
@sonnguyen9800
sonnguyen9800 / BaseSingleton.cs
Created June 14, 2024 00:11
GodotSingleton
using Godot;
using System;
public abstract partial class BaseSingleton<T> : Node where T : Node
{
private static T _instance = null;
public static T Instance => _instance;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
@sonnguyen9800
sonnguyen9800 / Tool_ParseCSV.py
Created May 31, 2024 07:35
Tool_ParseCSV.py
import csv
def filter_and_print_columns(filename, column_names, filename_output):
"""
This function reads a CSV file, filters and prints data from specified columns.
Args:
filename: The path to the CSV file.
column_names: A list of column names to print data from.
@sonnguyen9800
sonnguyen9800 / file.cs
Created January 14, 2024 03:53
Batch Convert Unity Scene into Prefab
public class Tool: EditorWindow
{
[MenuItem("Tool/Create Prefab", false, -10)]
private static void CreatePrefab(UnityEditor.MenuCommand command)
{
GameObject selectedOb = (GameObject)command.context;
Transform selectedTransform = selectedOb.transform;
GameObject rootObject = selectedTransform.root.gameObject;
@sonnguyen9800
sonnguyen9800 / gist:96dbed6876a8f17fa8066a6bdde94de9
Created December 16, 2023 16:52
[Godot] Parse String to Enum.gd
func ParseStringToEnum(enum_type: Dictionary, string_value: String) -> int:
var clone = enum_type.duplicate()
var keys = clone.keys()
var index = keys.find(string_value)
if index != -1:
return index
else:
print("String not found in enum.")
return -1