We can get unexpected trailing zeros when we serialzie an object with decimal properties, normally it will not hurt. However, it does hurt when we want to compare two objects by serializing them to JSON string. I tried a few solutions and finally find the following one is the best.
public static decimal Normalize(this decimal value)
{
return value/1.000000000000000000000000000000000m;
}
Reference
Game scripting mastery 是一本不可多得的好书,除了写得啰嗦。
豆瓣网友 全棧法師张解靈 2018-08-01 16:37:13 写道:
说实话,难看。 但是内容完全没问题,就是实在太啰嗦了,即使英语原著也是...看得有点难受,想跳呢又怕错过好东西,想慢慢看呢又...还是慢慢啃吧 如果谁重排一个脱水版,我绝对打满分
另一个网友 TerryX 2017-01-06 18:44:19 写道:
这本书可以说是被严重低估,可能因为这个专职院校味道的书名。从第9章开始简直不能再好,从编译器底层到高级虚拟机一气呵成。这本书真不仅仅是教你做游戏,而是教你怎么成为master。
所以我启动了这个脱水版项目:初步计划是从第8章开始到全书结束,借助chatGPT神力完成这个项目,希望不要烂尾。
哦,点击本文标题,或者这里,查看第八章全文。
对了,这个项目在gitHub上。如果你发现有可改进之处,欢迎改进并提交PR。
We use Graylog to log everything, on Windows machines we also log into EventLog. I recently noticed for every exception in C# I got two items in EventViewer, one is Logged by our code, and the other is logged by the .net runtime I guess. It is a little bit annoying. TLDR; here's the answer:
public override void OnException(ExceptionContext actionExecutedContext)
{
_logger.Error(actionExecutedContext.Exception);
+ actionExecutedContext.ExceptionHandled = true;
actionExecutedContext.HttpContext.Response.StatusCode = StatusCodes.Status500InternalServerError;
actionExecutedContext.Result = new ObjectResult(new ErrorResponse()
{
StatusCode = (HttpStatusCode) StatusCodes.Status500InternalServerError,
Message = actionExecutedContext.Exception.Message,
});
base.OnException(actionExecutedContext);
}
The key is this line actionExecutedContext.ExceptionHandled = true;
.
Reference
Occasionally, we will need to define local used functions
in a public procedure or a function. Fortunately, PL/SQL supports embedded functions. I spent more than an hour trying to find the correct way to use this feature. Yes. forgive me, I am a little dumb. According to my retries, the best position to put your local functions is sharp before the BEGIN
symbol. And here's a sample.
set serveroutput on;
CREATE OR REPLACE PROCEDURE tmp12345(v_full_name IN VARCHAR2) AS
localv varchar2(100);
-- local function definitaions start ---
FUNCTION FETCH_REAL_NAME(v_statement_name IN VARCHAR2) RETURN VARCHAR2
AS
pattern VARCHAR2(100) := '^(Dr|Ms|Mx|Mr|Mrs)\s+';
full_name varchar2(100);
BEGIN
-- replace possible multiple spaces to one space
full_name := TRIM(REGEXP_REPLACE(v_statement_name, '\s+', ' '));
IF (REGEXP_LIKE(full_name, pattern, 'i')) THEN
-- REGEXP_REPLACE(string, pattern [, replacement_string [, start_position [, nth_appearance [, match_parameter ] ] ] ])
RETURN REGEXP_REPLACE(full_name, pattern, '', 1, 0, 'i');
ELSE
RETURN full_name;
END IF;
END;
FUNCTION FETCH_MIDDLE_NAME(full_name IN VARCHAR) RETURN VARCHAR AS
middle_name VARCHAR2(100);
BEGIN
middle_name := SUBSTR(full_name, INSTR(full_name, ' ') + 1, INSTR(full_name, ' ', 1, 2) - INSTR(full_name, ' ') - 1);
IF (LENGTH(middle_name) > 10) THEN
-- return initial instead
RETURN SUBSTR(middle_name, 1, 1);
ELSE
RETURN middle_name;
END IF;
END;
-- local functions definitaions end ---
BEGIN
-- main logic here
localv := v_full_name;
DBMS_OUTPUT.PUT_LINE(localv);
DBMS_OUTPUT.PUT_LINE(FETCH_MIDDLE_NAME(FETCH_REAL_NAME(v_full_name)));
END;
/
Just record a few tips here:
[UseApprovalSubdirectory("Approvals")]
can be used to set up the directory that saves the approval results.
It can be used for a test class or a test method.
Links
ApprovalTests.Net Project