Skip to content

Instantly share code, notes, and snippets.

View chaojian-zhang's full-sized avatar
🏯
When I am doing programming: I want to be God.

Charles Zhang chaojian-zhang

🏯
When I am doing programming: I want to be God.
View GitHub Profile
@chaojian-zhang
chaojian-zhang / StringHelper.cs
Last active November 5, 2022 18:58
Useful stuff borrowed from [The Matrix](https://github.com/Charles-Zhang-Project-Nine/TheMatrix) project. #C#, #CSharp, #Utility
/*Dependency: Csv by Steven Hansen*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Utility
@chaojian-zhang
chaojian-zhang / CurrentAssembly.cs
Created November 5, 2022 18:05
A snippet for reading embedded resource. #C# #CSharp #Utility #EmbeddedResource
public string ReadResource(string name)
{
// Determine path
var assembly = Assembly.GetExecutingAssembly();
string resourcePath = name;
// Format: "{Namespace}.{Folder}.{filename}.{Extension}"
if (!name.StartsWith(nameof(YourAssemblyName)))
{
resourcePath = assembly.GetManifestResourceNames()
.Single(str => str.EndsWith(name));
@chaojian-zhang
chaojian-zhang / Github (Gist) (Management) Tricks.md
Created September 22, 2022 17:17
Github tricks. #Github, #Gist
  • Gist: Use #hashtags in descriptions, then search using user:username #hashtag to find the item.
@chaojian-zhang
chaojian-zhang / greedyvoxelmeshing.cs
Created September 15, 2022 02:47 — forked from Vercidium/greedyvoxelmeshing
Greedy Voxel Meshing ported to C#
// Code ported from https://0fps.net/2012/06/30/meshing-in-a-minecraft-game/
// Note this implementation does not support different block types or block normals
// The original author describes how to do this here: https://0fps.net/2012/07/07/meshing-minecraft-part-2/
const int CHUNK_SIZE = 32;
// These variables store the location of the chunk in the world, e.g. (0,0,0), (32,0,0), (64,0,0)
@chaojian-zhang
chaojian-zhang / Template.ps1
Created September 9, 2022 14:01
Self-elevate script access priviledge.
# Self-elevate the script - put this at beginning of file
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process pwsh.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; Exit }
# Example of a command that requires admin priviledge
[Environment]::SetEnvironmentVariable("MY_ENV_PATH", "$PSScriptRoot", "Machine")
@chaojian-zhang
chaojian-zhang / SFMLOpenTKProgram.cs
Last active August 13, 2022 14:36
SFML window with OpenTK GL context - this allows using both SFML 2D routines and OpenTK for 3D stuff; Be cautious with potential conflicts.
// dotnet add package SFML.Net --version 2.5.0
// dotnet add package OpenTK --version 4.0.0-pre9.1
using OpenTK.Graphics.OpenGL;
using OpenTK.Windowing.Desktop;
using SFML.Graphics;
using SFML.Window;
namespace CSharpSFMLWithOpenTK
{

Troubleshooting

  • Type or namespace could not be found even after AddReference: There are a few potential causes - 1) Dynamic assembly won't work e.g. Single Executable option in publish; 2) Be careful you are actually passing the assembly reference to AddReferences() not as the third "global" object to CSharpScript.RunAsync(); 3) During publishing, might want to "Delete existing files" because old assemblies can mess up with assembly references.
  • By the way the differences between "Add" and "With" is the latter replaces everything, while the former adds to the list; And "Imports" is equivalent to "using" in code.
@chaojian-zhang
chaojian-zhang / settings.json
Created May 11, 2022 23:01
Visual Studio Code - Settings & Customizations
{
# Put the following into user settings JSON file to change the sick annoying default bright red preformatted code text foreground color for Monokai Dimmed color theme
"editor.tokenColorCustomizations": {
"[Monokai Dimmed]": {
"textMateRules": [
{
"scope": "markup.inline.raw",
"settings": {
"foreground": "#675b5b",
}
@chaojian-zhang
chaojian-zhang / 202203 Books Sale.md
Last active March 24, 2022 04:02
Textbook information

(List is up-to-date per 20220322)

Overview

All prices negotiable; LIST PRICE MAY CHANGE (and become higher); Most of my books are either new or almost new because I always keep my books in very good conditions. Some even have insightful notes.

Most books are purchased within the past 4 years.

[Bundles]

@chaojian-zhang
chaojian-zhang / index.html
Created March 6, 2022 15:53
Clean empty HTML5 template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Enter Title Here</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="description" content="Starter Template">
<meta name="author" content="Charles Zhang">
<link href="style.css" rel="stylesheet" />