Skip to content

Instantly share code, notes, and snippets.

@tupunco
tupunco / rand.go
Last active May 2, 2018 12:29
golang Weight Rand Helper
package utils
import (
"crypto/rand"
"errors"
"math/big"
prand "math/rand"
"time"
)
@tupunco
tupunco / IRng.cs
Created April 25, 2016 14:00
Weight Rand Helper
public interface IRng
{
int Next(int maxValue);
int Next(int minValue, int maxValue);
int Next();
void NextBytes(byte[] buffer);
double NextDouble();
}
@tupunco
tupunco / vs-dark-hdpi.css
Last active June 27, 2017 01:18
LiteIDE_vs-dark-hdpi.qss.Skin
/* ===add file: \liteide\share\liteide\liteapp\qss\vs-dark-hdpi.qss ===*/
/* ===FROM: https://gist.github.com/tupunco/fdb713ec9c6189a877e5eb003bd0457d ===*/
/* === Shared === */
QStackedWidget, QLabel, QPushButton, QRadioButton, QCheckBox,
QGroupBox, QStatusBar, QToolButton, QComboBox, QDialog, QListView,
QTabBar, QMenu, QMenuBar, QWidget::window {
background-color: #252526;
color: #F1F1F1;
}
@tupunco
tupunco / golang_学习.go
Last active May 17, 2017 02:40
golang_学习
package main
import (
//"encoding/json"
"fmt"
//"os"
"sync"
"time"
)
@tupunco
tupunco / BizResult.cs
Created December 18, 2015 01:05
业务逻辑 返回结果
/// <summary>
/// 业务逻辑 返回结果
/// </summary>
/// <remarks>
/// 建议以本类型为返回对象的方法, 不要返回 null 对象.
///
/// 提供三种方法创建本实例:
/// 直接实例:
/// new BizResult<Dish>(...);
///
@tupunco
tupunco / SerializableDictionary.cs
Created December 14, 2015 07:38
XML Serializable Collections, 可 XML 序列化的 字典/HashSet 类型
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace Tup.Utilities
{
/// <summary>
/// 支持XML序列化的泛型Dictionary类
@tupunco
tupunco / DbTransactionConnection.cs
Last active October 17, 2019 06:44
Dapper extensions (For SQLServer/MySQL/SQLite)
using XHEdu;
namespace System.Data
{
/// <summary>
/// 包含 `已创建事务` 的 DbConnection
/// </summary>
public class DbTransactionConnection : IDbConnection
{
private IDbTransaction innerDbTransaction = null;
@tupunco
tupunco / ExecuteAction.cs
Last active December 14, 2015 07:39
C# 同步/异步执行 控制台 命令
/// <summary>
/// Async Execute Command Action
/// </summary>
/// <param name="startFileName"></param>
/// <param name="startFileArg"></param>
/// <param name="msgAction"></param>
/// <returns></returns>
public static Task<bool> ExecuteActionAsync(string startFileName, string startFileArg, Action<string> msgAction)
{
ThrowHelper.ThrowIfNull(msgAction, "msgAction");
@tupunco
tupunco / ConsistentHashing.cs
Last active March 26, 2020 07:46
Consistent Hashing C#, 一致性HASH
/// <summary>
/// 一致性 Hash 算法
/// </summary>
class ConsistentHashing
{
List<KeyValuePair<uint, string>> _serList = new List<KeyValuePair<uint, string>>();
public ConsistentHashing(string[] serList)
{
if (serList == null || serList.Length == 0)
public class Tree
{
/// <summary>
/// store the tree's root
/// </summary>
private Node _root;
/// <summary>
/// construct a new tree with it's root
/// </summary>