Looking at these side-by-side randomly generated visualizations, neither of them seem substantively different from a distribution perspective. All to say, when generating a random color palette, there probably wasn't any need for me to use the Crypto module—I probably should have just stuck with Math. It's much faster and feels to be just as random. I'll leave the Crypto stuff to any client-side cryptography work (which I've never had to do).
مقایسه کارآیی #C در مقابل Rust و Go
From this benchmark, we are able to understand that Rust has consistent performance and is almost always faster than C# and Go. But that is to be expected as Rust runs on the metal. Between C# and Go the performance seems to be nuanced. As C# and Go seems to outperform each other in difference scenarios.
مراحل تنظیم Let's Encrypt در IIS
یک نکتهی تکمیلی
ACME V1 تا چند ماه دیگر به پایان خواهد رسید:In June of 2020 we will stop allowing new domains to validate via ACMEv1.
A simple Windows ACMEv2 client (WACS) Software version 2.1.3.671 (RELEASE, PLUGGABLE) IIS version 7.5 Running with administrator credentials Scheduled task not configured yet Please report issues at https://github.com/PKISharp/win-acme N: Create new certificate (simple for IIS) M: Create new certificate (full options) L: List scheduled renewals R: Renew scheduled S: Renew specific A: Renew *all* O: More options... Q: Quit Please choose from the menu: m Running in mode: Interactive, Advanced Please specify how the list of domain names that will be included in the certificate should be determined. If you choose for one of the "all bindings" options, the list will automatically be updated for future renewals to reflect the bindings at that time. 1: IIS 2: Manual input 3: CSR created by another program C: Abort How shall we determine the domain(s) to include in the certificate?: 1 Please select which website(s) should be scanned for host names. You may input one or more site identifiers (comma separated) to filter by those sites, or alternatively leave the input empty to scan *all* websites. 1: Default Web Site (2 bindings) Site identifier(s) or <ENTER> to choose all: 1 1: dotnettips.info (Site 1) 2: www.dotnettips.info (Site 1) You may either choose to include all listed bindings as host names in your certificate, or apply an additional filter. Different types of filters are available. 1: Pick specific bindings from the list 2: Pick bindings based on a search pattern 3: Pick bindings based on a regular expression 4: Pick *all* bindings How do you want to pick the bindings?: 4 1: dotnettips.info (Site 1) 2: www.dotnettips.info (Site 1) Please pick the most important host name from the list. This will be displayed to your users as the subject of the certificate. Common name: 2 1: dotnettips.info (Site 1) 2: www.dotnettips.info (Site 1) Continue with this selection? (y*/n) - yes Target generated using plugin IIS: www.dotnettips.info and 1 alternatives Suggested friendly name '[IIS] Default Web Site, (any host)', press <ENTER> to accept or type an alternative: <Enter> The ACME server will need to verify that you are the owner of the domain names that you are requesting the certificate for. This happens both during initial setup *and* for every future renewal. There are two main methods of doing so: answering specific http requests (http-01) or create specific dns records (dns-01). For wildcard domains the latter is the only option. Various additional plugins are available from https://github.com/PKISharp/win-acme/. 1: [http-01] Save verification files on (network) path 2: [http-01] Serve verification files from memory (recommended) 3: [http-01] Upload verification files via FTP(S) 4: [http-01] Upload verification files via SSH-FTP 5: [http-01] Upload verification files via WebDav 6: [dns-01] Create verification records manually (auto-renew not possible) 7: [dns-01] Create verification records with acme-dns (https://github.com/joohoi/acme-dns) 8: [dns-01] Create verification records with your own script 9: [tls-alpn-01] Answer TLS verification request from win-acme C: Abort How would you like prove ownership for the domain(s) in the certificate?: 2 After ownership of the domain(s) has been proven, we will create a Certificate Signing Request (CSR) to obtain the actual certificate. The CSR determines properties of the certificate like which (type of) key to use. If you are not sure what to pick here, RSA is the safe default. 1: Elliptic Curve key 2: RSA key What kind of private key should be used for the certificate?: 2 When we have the certificate, you can store in one or more ways to make it accessible to your applications. The Windows Certificate Store is the default location for IIS (unless you are managing a cluster of them). 1: IIS Central Certificate Store (.pfx per domain) 2: PEM encoded files (Apache, nginx, etc.) 3: Windows Certificate Store C: Abort How would you like to store the certificate?: 3 1: IIS Central Certificate Store (.pfx per domain) 2: PEM encoded files (Apache, nginx, etc.) 3: No additional storage steps required C: Abort Would you like to store it in another way too?: 3 With the certificate saved to the store(s) of your choice, you may choose one or more steps to update your applications, e.g. to configure the new thumbprint, or to update bindings. 1: Create or update https bindings in IIS 2: Create or update ftps bindings in IIS 3: Start external script or program 4: Do not run any (extra) installation steps Which installation step should run first?: 1 Use different site for installation? (y/n*) - no 1: Create or update ftps bindings in IIS 2: Start external script or program 3: Do not run any (extra) installation steps Add another installation step?: 3 Enter email(s) for notifications about problems and abuse (comma seperated): name@site.com Terms of service: C:\ProgramData\win-acme\acme-v02.api.letsencrypt.org\LE-SA-v1.2-November-15-2017.pdf Open in default application? (y/n*) - no Do you agree with the terms? (y*/n) - yes Authorize identifier: dotnettips.info Authorizing dotnettips.info using http-01 validation (SelfHosting) Authorization result: valid Authorize identifier: www.dotnettips.info Authorizing www.dotnettips.info using http-01 validation (SelfHosting) Authorization result: valid Requesting certificate [IIS] Default Web Site, (any host) Store with CertificateStore... Installing certificate in the certificate store Adding certificate [IIS] Default Web Site, (any host) @ 2020/2/1 9:43:55 to store My Installing with IIS... Updating existing https binding www.dotnettips.info:443 (flags: 0) Updating existing https binding dotnettips.info:443 (flags: 0) Committing 2 https binding changes to IIS Adding Task Scheduler entry with the following settings - Name win-acme renew (acme-v02.api.letsencrypt.org) - Path C:\Programs\win-acme.v2.1.3.671.x64.pluggable - Command wacs.exe --renew --baseuri "https://acme-v02.api.letsencrypt.org/" - Start at 09:00:00 - Time limit 02:00:00 Do you want to specify the user the task will run as? (y/n*) - no
Did you know that DotVVM can be used to incrementally modernize old ASP.NET Web Forms applications and lift them to .NET Core? It is much easier than doing a full rewrite, and the application can be deployed at any time during the entire process.
- Install DotVVM NuGet package in your Web Forms site
- Create a DotVVM master page using the same CSS
- Start converting ASPX pages to DotHTML syntax, one at a time
- When all the Web Forms pages are gone, change your CSPROJ to use .NET Core
انتشار هندبوک جدید TypeScript
تفاوت Using Directives و Using Block
PGlite is a WASM (Webassembly) based TypeScript/JavaScript client library which helps to run PostgreSQL locally in Browser or in NodeJS / Bun. It does not include any dependencies. It is very light weight and it's size is 3 MB Gzipped. It supports many Postgres extensions like pgvector, live queries, bloom, btree, earthdistance, fuzzymatch and lot morebun.
defaultChecks() { const author = { firstName: "Vahid", lastName: "N" }; console.log(author.lastname); author.lastName.trimStart(); author.firstName.charCodeAt("1"); }
- خاصیت lastname در شیء author وجود خارجی ندارد.
- نوع رشتهای، به همراه متد trimStart نیست.
- متد charCodeAt یک عدد را به عنوان پارامتر قبول میکند.
اما باید درنظر داشت که بسیاری از قابلیتهای بررسی کد TypeScript، به صورت پیشفرض فعال نیستند که در ادامه آنها را برای یافتن پیش از موعود بسیاری از مشکلات، فعالسازی خواهیم کرد.
نصب افزونهی TSLint در VSCode
جهت مشاهدهی بهتر خطاهای کامپایلر TypeScript، پیش از کامپایل نهایی کدها، میتوان از افزونهی TSLint استفاده کرد. برای نصب آن، ابتدا باید بستهی ذیل را نصب کرد:
> npm install -g tslint typescript
کار TSLint انجام static code analysis است؛ چیزی شبیه به افزونههایی مانند ریشارپر در ویژوال استودیو که راهنماهایی را در مورد بهتر کردن کیفیت کدهای نوشته شده ارائه میدهد.
فعالسازی بررسی نال و نوعهای نال پذیر
strictNullChecks یکی از مهمترین پرچمهای تنظیمات کامپایلر تایپاسکریپت است. برای افزودن آن، به فایل tsconfig.json مراجعه کرده و پرچم آنرا به true تنظیم کنید:
{ "compilerOptions": { "strictNullChecks": true } }
برای مثال، متد ذیل را در نظر بگیرید:
getSessionItem(key: string): any { const data = window.sessionStorage.getItem(key); return JSON.parse(data); }
[ts] Argument of type 'string | null' is not assignable to parameter of type 'string'. Type 'null' is not assignable to type 'string'. const data: string | null
برای رفع این مشکل تنها کافی است بررسی کنیم که آیا data نال است یا خیر؟ و اگر خیر، آنگاه آنرا به متد JSON.parse ارسال کنیم:
getSessionItem(key: string): any { const data = window.sessionStorage.getItem(key); if (data) { return JSON.parse(data); } else { return null; } }
گزارش returnهای فراموش شده
در متد ذیل، یک return فراموش شده وجود دارد و تمام شرطهای برنامه به یک خروجی مشخص، منتهی نمیشوند:
noImplicitReturns(a: number) { if (a > 10) { return a; } // No return in this branch }
{ "compilerOptions": { "noImplicitReturns": true } }
[ts] Not all code paths return a value.
تشخیص کدهای مرده
قطعه کدی که پس از یک return قرار بگیرد، یک کد مرده نامیده میشود. با تنظیم پرچم allowUnreachableCode در فایل tsconfig.json به false، میتوان کامپایلر TypeScript را وادار کرد تا اینگونه موارد را به عنوان خطا گزارش کند:
{ "compilerOptions": { "allowUnreachableCode": false } }
allowUnreachableCode() { if (false) { console.log("Unreachable code"); } const a = 1; if (a > 0) { return 10; // reachable code } return 0; console.log("Unreachable code"); }
تشخیص پارامترها و متغیرهای استفاده نشده
دو متد ذیل را درنظر بگیرید:
unusedLocals() { const a = "foo"; // Error: 'a' is declared but its value is never read return "bar"; } unusedParameters(n: number) { n = 0; // Never read }
برای فعالسازی بررسی یک چنین مواردی باید دو پرچم ذیل را در فایل tsconfig.json به true تنظیم کرد:
{ "compilerOptions": { "noUnusedLocals": true, "noUnusedParameters": true } }
[ts] 'a' is declared but its value is never read. [ts] 'n' is declared but its value is never read.
یافتن خواصی که نباید در یک شیء وجود داشته باشند
در مثال ذیل، خاصیت baz در تعاریف اصلی نوعهای x و y وجود ندارد:
excessPropertyForObjectLiterals() { let x: { foo: number }; x = { foo: 1, baz: 2 }; // Error, excess property 'baz' let y: { foo: number, bar?: number }; y = { foo: 1, baz: 2 }; // Error, excess property 'baz' }
{ "compilerOptions": { "suppressExcessPropertyErrors": false } }
[ts] Type '{ foo: number; baz: number; }' is not assignable to type '{ foo: number; }'. Object literal may only specify known properties, and 'baz' does not exist in type '{ foo: number; }'. (property) baz: number
یافتن breakهای فراموش شده در عبارات switch
در مثال زیر، یک break فراموش شدهاست:
fallthroughCasesInSwitchStatement(a: number) { switch (a) { case 0: break; case 1: a += 1; case 2: a += 2; break; } }
{ "compilerOptions": { "noFallthroughCasesInSwitch": true } }
یافتن ایندکسهای تعریف نشدهی در اشیاء
در مثال زیر، شیء x دارای خاصیت b نیست؛ اما دقیقا با این ایندکس مورد استفاده قرار گرفتهاست:
indexingObjectsLackingIndexSignatures() { const x = { a: 0 }; x["a"] = 1; // ok x["b"] = 1; // Error, type '{ a: number; }' has no index signature. }
{ "compilerOptions": { "suppressImplicitAnyIndexErrors": false } }
[ts] Element implicitly has an 'any' type because type '{ a: number; }' has no index signature.
اجبار به تعریف صریح نوعها در TypeScript
عمدهی قابلیت TypeScript در یافتن خطاها به تعاریف نوعها و راهنمایی کامپایلر آن در این زمینه بر میگردد. اما چون این زبان سازگاری کاملی را با JavaScript دارد، تعریف نوعها در آن اجباری نیست و در این حالت اگر نوعی تعریف نشده باشد، به any تفسیر میشود. جهت اجبار به تعریف نوعها در TypeScript میتوان پرچم noImplicitAny را در فایل tsconfig.json به true تنظیم کرد:
{ "compilerOptions": { "noImplicitAny": true } }
noImplicitAny(args) { // Error: Parameter 'args' implicitly has an 'any' type. console.log(args); }
noImplicitAnyArgs(args: string[]) { // ok with the type information console.log(args); }
یک نکتهی تکمیلی
اگر از دستور ng build --watch برای ساخت برنامههای Angular استفاده میکنید، تغییرات فوق زمانی تاثیر داده خواهند شد که یکبار این برنامه را بسته و مجددا اجرا کنید.
StructureMap 4.1 منتشر شد
- The assembly discovery mechanism in type scanning has new methods to scan for “.exe” files as Assembly candidates. I had removed “.exe” file searching in 4.0 thinking that it was more problematic than helpful, then several users asked for it back.
- The assembly discovery handles the PrivateBinPath of the AppDomain in all (known) cases now
- Child container creation is thread safe now