Skip to content

Instantly share code, notes, and snippets.

View zhangr4's full-sized avatar

zhangr4 zhangr4

View GitHub Profile
@zhangr4
zhangr4 / commit-msg.sample
Created June 22, 2022 16:18
hooks: check commit message match convention
#!/usr/bin/env bash
REGEX_COMMIT_MSG='^(feat|fix|docs|style|refactor|perf|test|workflow|build|ci|chore|release|workflow)(\(.+\))?: .{1,50}';
# https://www.conventiona
if [[ $(<"$1") =~ $REGEX_COMMIT_MSG ]]
then
echo "commit message match convention";
exit 0;
fi
import pandas as pd
a = pd.DataFrame([1,2,2,3,3,3,1,1,2])
b = a.loc[:,0]
c = b.loc[b.shift()!=b]
print(c.tolist())
// https://stackoverflow.com/questions/19463985/pandas-drop-consecutive-duplicates
@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 {
@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 / 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 / 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 / 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 / Use of HttpClient C#.md
Created January 25, 2023 02:57
A Summary of how to use HttpClient in C#
@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
// 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.