Skip to content

Instantly share code, notes, and snippets.

@relyky
relyky / form_invalid_event.html
Last active October 8, 2021 01:42
HTML, form validation event
///
/// HTML原生的 validation
/// ref→[Constraint validation interfaces](https://developer.mozilla.org/en-US/docs/Web/API/Constraint_validation#element.setcustomvalidity(message))
/// ref→[HTMLObjectElement.validationMessage](https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validationMessage)
/// ref→[HTMLObjectElement.validity](https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity)
/// ref→[validityState.badInput](https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/badInput)
///
<!DOCTYPE html>
<html>
@relyky
relyky / switch_pattern_matching.cs
Last active October 6, 2021 01:15
C# switch expression, pattern matching 語法整理, ref→[The evolution of Pattern Matching in C# (from version 6 to 10)](https://www.youtube.com/watch?v=MzNHMJCyU40&ab_channel=NickChapsas)
///
/// C# switch pattern 語法整理
/// ref→[The evolution of Pattern Matching in C# (from version 6 to 10)](https://www.youtube.com/watch?v=MzNHMJCyU40&ab_channel=NickChapsas)
/// ref→[Pattern matching overview](https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching)
/// ref→[Patterns (C# reference)](https://docs.microsoft.com/zh-tw/dotnet/csharp/language-reference/operators/patterns)
///
using System;
using System.Collections.Generic;
@relyky
relyky / scrollToOffset.js
Created September 17, 2021 01:26
JavaScript, window.scrollTo, offset
function scrollToOffset(element, offset /* int */)
{
//ref→https://newbedev.com/javascript-scrollintoview-smooth-scroll-and-offset
const bodyRect = document.body.getBoundingClientRect().top;
const elementRect = element.getBoundingClientRect().top;
const elementPosition = elementRect - bodyRect;
const offsetPosition = elementPosition - offset;
window.scrollTo({
top: offsetPosition,
behavior: "smooth"
@relyky
relyky / jqeury.mics.js
Last active July 3, 2023 02:41
jquery, 取得版本, version
/// 取得 jquery 版本
jQuery().jquery
/// 或
$.fn.jquery
@relyky
relyky / DisplayName_For_Property.cs
Last active August 14, 2024 11:31
C#, get property Display Name of DisplayAttribute, DataAnnotations, MemberExpression
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Linq.Expressions;
/// <summary>
/// global type handling helper
/// </summary>
public static class GT<TModel>
{
@relyky
relyky / basic.data.repo.cs
Last active July 30, 2021 02:27
C#, Task, basic data, 非同步取得基本資料。
using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/// 專門載入基本資料。如:下拉選單 Select 或 AutoComplete 的項目清單。
/// C#9.0
namespace YourProject.DB.BasicData
@relyky
relyky / Get_DisplayName.cs
Last active July 29, 2021 07:27
c#, data annotation, 取得類別屬性(attribute) Display Name,
using System;
using System.Linq;
using System.ComponentModel.DataAnnotations;
public static class DBHelperClassExtensions
{
public static string DisplayNameOf(Type ty, string propertyName)
{
var field = ty.GetProperty(propertyName);
var attr = field.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault() as DisplayAttribute;
@relyky
relyky / Benchmark.sample.cs
Last active July 27, 2021 15:39
Benchmark sample, BenchmarkDotNet
///
/// BenchmarkDotNet v0.13.0
/// ref→[Getting started](https://benchmarkdotnet.org/articles/guides/getting-started.html)
///
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
class Program
@relyky
relyky / CatchHandling.cs
Last active November 13, 2023 03:22
C#, Catch and retry, CatchAndHandling, Aspect, AOP
Task HandleQuery() => CatchHandling(async () =>
{
var qryArgs = new TodoQryAgs
{
Msg = f_testFail ? "測試邏輯失敗" : "今天天氣真好",
Amt = 999
};
dataList = await bizApi.QryDataListAsync(qryArgs);
});
@relyky
relyky / checkout_conn.sql
Last active October 26, 2022 04:19
SQL Server, T-SQL, cmd, 常用指令, 查看連線數, 取出 procedure schema, tabled-valued function
-- 查看連線數
USE master
SELECT cntr_value AS User_Connections FROM sys.sysperfinfo AS sp
WHERE sp.object_name='SQLServer:General Statistics'
AND sp.counter_name='User Connections'
GO
-- 查看連線明細
USE master
SELECT c.session_id, c.connect_time, s.login_time, c.client_net_address, s.login_name, s.status