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 / BinaryData.cs
Last active March 1, 2023 13:29
Quick C# bin Data. #C#, #LZ4
// <PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.3.5" />
public abstract class BaseNotifyPropertyChanged: INotifyPropertyChanged
{
#region Data Binding
public event PropertyChangedEventHandler PropertyChanged;
public virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
protected bool SetField<TType>(ref TType field, TType value, [CallerMemberName] string propertyName = null)
{
@chaojian-zhang
chaojian-zhang / gerstner_wave.cpp
Created February 8, 2023 04:04 — forked from yorung/gerstner_wave.cpp
Calc gerstner wave in C++.
struct Wave
{
Vec2 dir;
float amplitude;
float waveLength;
};
struct ImmutableCB
{
float waveSteepness;
@chaojian-zhang
chaojian-zhang / Perlin.cs
Created February 6, 2023 19:03 — forked from Kakusakov/Perlin.cs
Improved Perlin Noise Implementation in C#
// Clone of https://gist.github.com/Flafla2/1a0b9ebef678bbce3215 with more dimensions and seed generation.
public class PerlinGen
{
private readonly int[] p; // Randomly shuffled array of values from 0 to 255.
// Values are repeated up to size of 512 to avoid using modulo operator.
public PerlinGen(int seed)
{
// Generate p.
@chaojian-zhang
chaojian-zhang / Blazor Bizarre.md
Last active January 11, 2023 18:53
Blazor bizarre. #Blazor #C# #.Net Core

Blazor Bizarre

Blazor is NOT procedural. And you cannot define "functional components" - so all the shitty little layouts need to become a seperate component, which quickly makes project messy because each component needs some naming.

Blazor is entirely FUNCTIONAL despite what it looks like, and things like the below can happen that blew your mind:

// The code below depends on Blazorized for <Row> and <Column> definitions

// ProductGalerry.blazor
@chaojian-zhang
chaojian-zhang / CursorPos.cs
Created December 29, 2022 19:21
CursorPos #C#
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows; // Or use whatever point class you like for the implicit cast operator
namespace CursorPos
{
class Program
{
/// <summary>
@chaojian-zhang
chaojian-zhang / get-pip.py
Last active November 22, 2022 22:04 — forked from rgl/python-embedded.md
notes about python embedded in windows #Python
This file has been truncated, but you can view the full file.
#!/usr/bin/env python
#
# Hi There!
#
# You may be wondering what this giant blob of binary data here is, you might
# even be worried that we're up to something nefarious (good for you for being
# paranoid!). This is a base85 encoding of a zip file, this zip file contains
# an entire copy of pip (version 22.3.1).
#
# Pip is a thing that installs packages, pip itself is a package that someone
@chaojian-zhang
chaojian-zhang / Train.cs
Last active November 5, 2022 18:29
Interesting command line animation. #C#, #CSharp, #Utility
/*Dependency: Csv by Steven Hansen*/
using System.Drawing;
using Console = Colorful.Console;
namespace Utility
{
public class Train : IDisposable
{
#region Construction
@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.