这里记录我的一周分享,通常在周六发布。
马冇冇 手工作品之所以珍贵,是因为有人把他生命中的一段时间物化了给你。
米饭 有时候觉得小孩不懂事,不收拾东西,不爱惜衣服。但是,小孩懂事的时候,就是要离开父母的时候。
《里根日记》
里根非常善于写总结。作为演说家,他习惯在放在胸袋里的卡片上用速记做笔记。他的日记写作风格与此类似。从小时候起,写作就帮助他理清思路。数十年来,他自己撰写演讲稿、广播稿和报纸专栏。他曾说,写作让他"思路格外清晰"。担任总统期间,他仍亲自写(或修改)了许多演讲稿,而且他会亲自回复信件。1981年,他从白宫给一位公民回信说:"既然你要求我亲自回复,那我来了。"他喜欢阅读各类书籍。从第一篇到最后一篇日记,他的行文都充满活力,可见写日记对里根来说从来不是负担。
…more
... skipping 1000 words about bad solutions ...
The Clean/Best Solution
Here's a pattern that elegantly handles this situation:
public void RefreshGrid()
{
// 1. Store the current entity before refresh
SomeEntity currentEntity = null;
if (dataGrid.ActiveRow != null)
{
currentEntity = dataGrid.ActiveRow.ListObject as SomeEntity;
}
// 2. Refresh the grid
dataGrid.RefreshData();
// 3. Restore selection using entity ID
if (currentEntity != null)
{
dataGrid.ActiveRow = dataGrid.Rows.FirstOrDefault(r =>
((SomeEntity)r.ListObject).Id == currentEntity.Id);
}
}
Why This Pattern Is Best Practice
- Type Safety: Using the strongly-typed entity object instead of raw values
- Identity-Based: Uses unique IDs instead of volatile row positions
- Null-Safe: Handles cases where no row is selected
- Concise: LINQ makes the code readable and maintainable
- Reliable: Works even if data order changes or rows are filtered
安子 尽量多发现身边那些笑点很低,很容易满足,无论何时看起来都是喜洋洋的人,并且尽量多的跟他们在一起,你会感觉到被滋养,被激发,被启迪。它们像炭火一样煲养你的生命,给你力量,带来喜悦,他们是真正的人间天使。(更重要的,只要你贴他们足够近,他们还有能力把你转化成他们的同类)
碧螺姑娘 突然间真实感受到了“人生是旷野”的具体意义。虽然风刀霜剑严相催,但就是要热热闹闹地去活着。
奧匈帝國小説家弗朗茨·卡夫卡(Franz Kafka)寫過一則微型小説叫《法律門前》。小説講的是:有個鄉下人走到一處敞開的大門前,但是看門人不讓他進去。鄉下人問,那他以後可不可以進去呢?看門人跟他説,以後有可能,但是現在不行。看門人還暗示他說,如果他實在想進去,可以試一試,不過裏面還有更多看門人守著其他大門,這些看門人一個比一個難纏。後來這個鄉下人就在這個大門前等了一輩子,就等有機會允許他進去。等到自己快要死的時候,鄉下人問:爲什麽一直沒有其他人要求進這個大門?看門人跟他說:因爲這個大門就是專門給你一個人開的,等你死了,大門就會關起來。
人生若梦为欢几何 有句话说的很好,你把生活当游戏,把周围所有的人当npc,就不会内耗了。
CarrieZ 人类之所以进步,是因为下一代不听上一代的话。
…more
Wen working with QuickFix/n ibrary , efficient logging is crucial for troubleshooting. Here's how to implement a custom logging solution that routes QuickFix logs through NLog to your ELK stack.
Key Components
- NLogAdapter: A custom adapter that implements QuickFix's
ILog
interface:
public class NLogAdapter(ILogger logger) : ILog
{
private const string HeartbeatPattern = @"\x0135=0\x01";
private static readonly Regex HeartbeatRegex = new(HeartbeatPattern, RegexOptions.Compiled);
private static bool IsHeartBeat(string message) => HeartbeatRegex.IsMatch(message);
public void OnIncoming(string message)
{
if (!IsHeartBeat(message))
{
logger.Info("Incoming: {Message}", message);
}
}
// ... other implementations
}
- NLogQuickFixLogFactory: A factory class to create log instances:
public class NLogQuickFixLogFactory(ILog logger) : ILogFactory
{
public ILog Create(SessionID sessionId) => logger;
public ILog CreateNonSessionLog() => logger;
}
Implementation Steps
- Register Dependencies in your DI container:
builder.Services.AddSingleton<NLog.ILogger>(_ => LogManager.GetCurrentClassLogger());
builder.Services.AddSingleton<ILog, NLogAdapter>();
builder.Services.AddSingleton<ILogFactory, NLogQuickFixLogFactory>();
- Configure QuickFix to use the custom logger:
var initiator = new SocketInitiator(
clientApp,
storeFactory,
sessionSettings,
new NLogQuickFixLogFactory(quickfixLogger) // Use custom logger injeted by ILog here
);
Key Features
- Heartbeat Filtering: Reduces log noise by filtering out FIX heartbeat messages
- Structured Logging: Uses NLog's structured logging format for better parsing in ELK
- Separation of Concerns: Cleanly separates QuickFix logging from application logging
Benefits
- Centralized logging in ELK stack
- Better debugging apabilities
- Reduced log volume through heartbeat filtering
- Consistent logging format across your application