Skip to content

Instantly share code, notes, and snippets.

View songzheng45's full-sized avatar

Robin Song songzheng45

  • Beijing
View GitHub Profile
@songzheng45
songzheng45 / aspnetcore-http-logging-middleware.cs
Last active June 4, 2023 06:23
ASP.NET Core Http Logging middleware
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.IO;
// https://exceptionnotfound.net/using-middleware-to-log-requests-and-responses-in-asp-net-core/
// https://gist.github.com/elanderson/c50b2107de8ee2ed856353dfed9168a2
@songzheng45
songzheng45 / filebeat_sample.yml
Created June 20, 2019 06:41
elk filebeat config sample
#=========================== Filebeat inputs =============================
filebeat.inputs:
- type: log
enabled: true
fields:
_recharge_api: true
paths:
@songzheng45
songzheng45 / generate-random-string-num.cs
Last active October 16, 2021 05:12
生成不重复的随机数 (验证码、随机密码等)
using System;
public class Program
{
private const string VCHAR = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
private const string VNUM = "0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9";
public static void Main()
{
Console.WriteLine(RndNum(16));
@songzheng45
songzheng45 / strip-utf8-bom.cs
Last active October 31, 2018 06:53
C# strip utf8 bpm
using System;
using System.Text;
using System.IO;
namespace ConsoleApp
{
// 将 UTF-8 Bom 转换为 UTF-8 的几种方法
class Program
{
@songzheng45
songzheng45 / random-get-prize.md
Last active September 17, 2018 03:20
get lucy prize 随机抽奖品
[Serializable]
public class PrizeDetail:ICloneable
{
    public string Id { get; set; }
    /// <summary>
    /// 奖品名称
    /// </summary>
    public string PrizeName { get; set; }
    /// <summary>
@songzheng45
songzheng45 / vs-enable-transforms-configuration.md
Last active September 12, 2018 06:20
VS enable transforms configuration

利用 transform Configuration, 用来解决不同环境(如开发、生产环境)使用不同配置的情况, 只需切换DebugRelease或其它自定义配置, 最终生成相应的配置文件.

目录结构:

| App_Config
|   Web.Base.config
|   Web.Debug.config
|   Web.Release.config
@songzheng45
songzheng45 / get-user-profile-folder.md
Last active December 23, 2023 23:47
C# - get user profile folder
using System.IO;


string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
// output : C:\Users\robin

string myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
// output : C:\Users\robin\Documents
@songzheng45
songzheng45 / IpConverter.cs
Last active September 12, 2018 06:03
C# ip converter
static long ToInt(string addr)
{
// careful of sign extension: convert to uint first;
// unsigned NetworkToHostOrder ought to be provided.
return (long) (uint) IPAddress.NetworkToHostOrder(
(int) IPAddress.Parse(addr).Address);
}
static string ToAddr(long address)
{
@songzheng45
songzheng45 / copy-external-dlls-to-output-dir.md
Last active September 12, 2018 06:04
VS Copy External dlls to output directory

Visual Studio 如何将 WIN32 dll 复制到输出目录?

打开项目属性,选择“Build Events”,在“编译前事件命令行”文本框中输入以下命令(假设外部dll放在项目根目录下的 ExternalDlls 目录下):

xcopy /y /d "$(ProjectDir)ExternalDlls\*.dll" "$(ProjectDir)$(OutDir)"

参数说明:

$(ProjectDir) : 项目所在目录
$(OutDir) : 编译后输出目录

@songzheng45
songzheng45 / C#-generate-a-z-letter.cs
Last active September 12, 2018 06:04
C# generate letters
using System.Text;
StringBuilder builder = new StringBuilder();
// ASCII 中, 65表示A, 90表示Z
for(int i = 65; i<=90; i++)
{
builder.Append((char)i);
}