Skip to content

Instantly share code, notes, and snippets.

View zhangr4's full-sized avatar

zhangr4 zhangr4

View GitHub Profile
@zhangr4
zhangr4 / Code Complete 2 understanding.md
Last active May 24, 2023 06:41
Code Complete 2 understanding

Code Complete 2

High Quality Routines

Rountines includes functions(which has return value) and procedure(which has no return)

creating routine

  • the reason for creating routine
@zhangr4
zhangr4 / guard.cs
Last active December 18, 2023 13:39
guard usage
// refer to https://github.com/ardalis/GuardClauses/tree/main
public interface IGuardClause { }
public class Guard : IGuardClause
{
private Guard() { }
public static IGuardClause Against { get; } = new Guard();
}
// https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/ranges
#region Indexable Example
//System.Index
// use '^' operator: means read from end = true
// '^' operator requires type is countable and have indexer:
interface IIndexable<T>{
public int Length { get; } // need public property 'Length', which has get access
public T this[int index] { get; } // need public indexer, which takes a single int as the argument.
@zhangr4
zhangr4 / SimpleImplementationOfMiddlewarePipeline.cs
Last active March 9, 2023 08:21
a simple implementation like asp.net middleware pipeline
/*
* just for learning
* key concept, LinkedList
* refer https://blog.csdn.net/qq_16587307/article/details/104301877
* refer https://medium.com/@bonnotguillaume/software-architecture-the-pipeline-design-pattern-from-zero-to-hero-b5c43d8a4e60
*/
namespace pipeline
{
public class Program
@zhangr4
zhangr4 / Use of HttpClient C#.md
Created January 25, 2023 02:57
A Summary of how to use HttpClient in C#
@zhangr4
zhangr4 / dimainUserName.csx
Created December 5, 2022 09:45
csharp snippets
Console.WriteLine();
// <-- Keep this information secure! -->
Console.WriteLine("UserName: {0}", Environment.UserName);
//this one can get domain and user name
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
Console.WriteLine();
Console.WriteLine(userName);
@zhangr4
zhangr4 / commonScripts.ps1
Created November 25, 2022 04:13
windows PowerShell scripts
# get internal ip address
ipconfig
# get external ip address
Invoke-WebRequest ifconfig.me
@zhangr4
zhangr4 / stack_fibonacci
Created July 11, 2022 14:51
a trial on using stack implement fibonacci
import java.util.Stack;
class Program {
public static void main(String[] args) {
for(int i = 0; i <= 10; i++) {
System.out.print(fibonacci(i) + " ");
}
System.out.println();
for(int i = 0; i <= 10; i++) {
@zhangr4
zhangr4 / quickSort.java
Created June 27, 2022 14:49
quick sort_example
public class quickSort {
public static void main(String[] args) {
int[] test = new int[]{5,1,1,2,0,0};
quickSortArr(test, 0, test.length-1);
printArr(test);
}
public static void printArr(int[] arr) {
@zhangr4
zhangr4 / JavaStreamPredicateAndMapper.java
Created June 27, 2022 09:29
static functions for filter() and map() in Java 8 - stream
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import java.util.Arrays;
/* raw problem and better solution:
https://stackoverflow.com/questions/57836937/call-custom-static-functions-from-filter-and-map-in-java-8-stream
*/
class Solution {