View Reflaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. A General Fast Method Invoker (https://www.codeproject.com/Articles/14593/A-General-Fast-Method-Invoker) | |
public static FastInvokeHandler GetMethodInvoker(MethodInfo methodInfo) | |
{ | |
DynamicMethod dynamicMethod = new DynamicMethod(string.Empty, | |
typeof(object), new Type[] { typeof(object), | |
typeof(object[]) }, | |
methodInfo.DeclaringType.Module); | |
ILGenerator il = dynamicMethod.GetILGenerator(); | |
ParameterInfo[] ps = methodInfo.GetParameters(); | |
Type[] paramTypes = new Type[ps.Length]; |
View MISC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Rethrow exception with original callstack | |
ExceptionDispatchInfo.Capture(ret.Exception).Throw() |
View Production Issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#自动抓取Dump, 当异常信息包含特定字符串 | |
1. procdump.exe -ma -e 1 -f <Exception Content> <PID> | |
.i.e. procdump.exe -ma -e 1 -f "Commands ouy of sync" 3368 | |
-ma Write a dump file with all process memory. The default dump format only includes thread and handle information. | |
-e Write a dump when the process encounters an unhandled exception. Include the 1 to create dump on first chance exceptions. | |
-f Filter the first chance exceptions. Wildcards (*) are supported. To just display the names without dumping, use a blank ("") filter. | |
C:\>procdump -e 1 -f "" w3wp.exe | |
Display without writing a dump, the exception codes/names of w3wp.exe |
View MySQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 索引 | |
1)索引必须按照“idx_字段名称_字段名称[_字段名]”进行命名。 | |
2)唯一索引必须按照“uniq_字段名称_字段名称[_字段名]”进行命名。 | |
3)名称必须使用小写。 | |
4)中的字段数建议不超过5个,索引毕竟也占空间,请谨慎使用 | |
5)主键是最左边一列是id,id不做业务使用,建表的时候必须有索引,不建议创建这个结构的表 | |
# Create Table If Not Exists | |
CREATE TABLE IF NOT EXISTS `shares` ( | |
`id` int(64) NOT NULL auto_increment, |
View ObjectPool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ObjectPoolAsync<T> : IDisposable | |
{ | |
private readonly BufferBlock<T> buffer; | |
private readonly Func<T> factory; | |
private readonly int msecTimeout; | |
public ObjectPoolAsync (int initialCount, Func<T> factory, CancellationToken cts, int msecTimeout = 0) | |
{ | |
this.msecTimeout = msecTimeout; | |
buffer = new BufferBlock<T> ( new DataflowBlockOptions { CancellationToken = cts }); |
View FP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Result<T> { | |
public T Ok { get; } | |
public Exception Error { get; } | |
public bool IsFailed { get => Error != null; } | |
public bool IsOk => !IsFailed; | |
public Result (T ok) { | |
Ok = ok; | |
Error = default (Exception); | |
} |
View Task Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static async Task<T> Otherwise<T> (this Task<T> task, Func<Task<T>> orTask) { | |
task.ContinueWith (async innerTask => { | |
if (innerTask.Status == TaskStatus.Faulted) | |
return await orTask (); | |
return await Task.FromResult<T> (innerTask.Result); | |
}).Unwrap (); | |
} | |
static async Task<T> Retry<T> (Func<Task<T>> task, int retries, TimeSpan delay, CancellationToken cts = default (CancellationToken)) { |
View Bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear # clean screen | |
netstat -tulpn | grep LISTEN # check the listening ports and applications |
View Generic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dynamic Invoke Generic Method | |
MethodInfo methodInfo = typeof(MyClass).GetMethod("TestProc"); | |
MethodInfo genericMethod = methodInfo.MakeGenericMethod(new[] { typeof(string) }); | |
genericMethod.Invoke(null, new[] { "Hello" }); // the first parameter is null, means it is a static method | |
https://www.codeproject.com/Articles/584720/ExpressionplusbasedplusPropertyplusGettersplusandp | |
// returns property getter | |
public static Func<TObject, TProperty> GetPropGetter<TObject, TProperty>(string propertyName) | |
{ |
View WinDBG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) 准备工作 | |
.loadby sos clr | |
.cordll -ve -u -l | |
.load <<path>>\sosex.dll | |
.load <<path>>\mex.dll | |
.symfix | |
.reload | |
2) 常用方法 | |
!pe [<exceptionAddr>] most recent exception data (don’t forget the external stack) |
NewerOlder