Skip to content

Instantly share code, notes, and snippets.

// 页面定时刷新
<head>
@if (ViewBag.RefreshSeconds != null && ViewBag.RefreshSeconds > 0)
{
<meta http-equiv="refresh" content="@ViewBag.RefreshSeconds">
}
</head>
@CleanCoder
CleanCoder / ExternalConfigurationManager From MS.txt
Last active December 13, 2017 01:52
ExternalConfigurationManager From MS
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace ExternalConfigurationStore.Cloud
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
@CleanCoder
CleanCoder / DB
Created January 23, 2018 01:33
DB
using EntityFramework;
using EntityFramework.Mapping;
using EntityFramework.Reflection;
using Next.Dal.Entity;
using Next.Dal.Repertory;
using Next.Dal.Repertory.DbRepertory;
using Next.Dal.Repertory.MemoryRepertory;
using Spring.Reflection.Dynamic;
using System;
using System.Collections.Generic;
internal sealed class DynamicEqualityComparer<T> : IEqualityComparer<T>
where T : class
{
private readonly Func<T, T, bool> _func;
public DynamicEqualityComparer(Func<T, T, bool> func)
{
DebugCheck.NotNull(func);
_func = func;
internal static class TaskHelper
{
internal static Task<T> FromException<T>(Exception ex)
{
var completion = new TaskCompletionSource<T>();
completion.SetException(ex);
return completion.Task;
}
internal static Task<T> FromCancellation<T>()
// 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)
{
clear # clean screen
netstat -tulpn | grep LISTEN # check the listening ports and applications
@CleanCoder
CleanCoder / ObjectPool
Created July 20, 2018 02:31
Object Pool
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 });
@CleanCoder
CleanCoder / MySQL
Last active July 27, 2018 07:24
MySQL
# 索引
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,
@CleanCoder
CleanCoder / MISC
Created August 24, 2018 02:55
MISC
// Rethrow exception with original callstack
ExceptionDispatchInfo.Capture(ret.Exception).Throw()