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 / 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" />
  • Convert images to video: ffmpeg -framerate 4 -start_number 51 -i _DSC12%d.jpg -c:v libx264 -r 4 output.mp4 (Recommendataion) Use Screen2Gif's editor instead.
  • Convert video into gif
  • Convert video into image sequence:
  • Crop video: ffmpeg -i in.mp4 -vf crop=w:h:x:y out.mp4
  • Change video frame rate:
  • Scale video resolution: ffmpeg -i input.avi -vf scale=320:240 output.avi
  • Scaleing while keeping aspect ratio: ffmpeg -i input.jpg -vf scale=320:-1 output_320.png
  • Scale images: ffmpeg -i input.jpg -vf scale=320:240 output_320x240.png
  • Multiple filters (separate using comma): ffmpeg -i 1.mp4 -vf "crop=720:720:264:0, scale=320:-1" 1.gif
  • Trim/Cut video: ffmpeg -i input.mp4 -ss 00:05:20 -t 00:10:00 -c:v copy -c:a copy output1.mp4
@chaojian-zhang
chaojian-zhang / Debian - Basic Host.k.md
Last active July 26, 2022 21:21
Digital Ocean Debian Server Configurations; What commands to run from a clean slate
@chaojian-zhang
chaojian-zhang / Test1.c
Created October 28, 2021 03:17
Basic Lectures on C
int main()
{
int a = 5;
int* b = &a;
int c[] = {1, 2, 3, 4, 5};
return 0;
}