Skip to content

Instantly share code, notes, and snippets.

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
namespace Microsoft.Extensions.Hosting
{
@ArtemAvramenko
ArtemAvramenko / vscode.settings.json
Created August 6, 2021 19:05
Visual Studio Code debug console background
{
"workbench.colorTheme": "Default Light+",
"workbench.colorCustomizations": {
"debugConsole.infoForeground": "#222222",
"debugConsole.errorForeground": "#cc0000",
"debugConsole.warningForeground": "#777700",
"debugConsole.sourceForeground": "#0088cc"
}
}
@ArtemAvramenko
ArtemAvramenko / localizeStub.ts
Created September 1, 2021 14:28
Angular $localize stub
function $localize(s: TemplateStringsArray) {
if (s.raw[0][0] === ':') {
const i = s[0].indexOf(':', 1)
if (i > 0) {
return s[0].substring(i + 1);
}
}
return s[0];
}
@ArtemAvramenko
ArtemAvramenko / openapi.yaml
Created September 1, 2021 14:50
OpenAPI inheritance
components:
schemas:
User:
title: User
description: User Model
type: object
properties:
id:
type: integer
firstName:
@ArtemAvramenko
ArtemAvramenko / install.js
Last active June 22, 2024 14:34
Fastest install script for npm 7.0+, speed up npm ci
// Fastest install script for npm 7.0+
// usage: node install
const fs = require('fs');
const readLockFile = path => {
if (fs.existsSync(path)) {
const text = fs.readFileSync(path, { encoding:'utf8', flag:'r' });
const lockFile = JSON.parse(text);
delete lockFile.dependencies;
@ArtemAvramenko
ArtemAvramenko / GetUniqueStringValue.cs
Created October 7, 2021 12:21
Get unique array of letters in C#
public static string GetUniqueStringValue(int size)
{
var data = new byte[size];
using var crypto = RandomNumberGenerator.Create();
crypto.GetBytes(data);
for (var i = 0; i < size; i++)
{
data[i] = (byte)('a' + data[i] % 26);
}
return Encoding.ASCII.GetString(data);
@ArtemAvramenko
ArtemAvramenko / gravatar.sql
Created February 8, 2022 11:15
T/SQL Generate Gravatar url from email
SELECT GravatarUrl =
'https://www.gravatar.com/avatar/' +
LOWER(CONVERT(VARCHAR(32), HashBytes('MD5', '[email protected]'), 2)) +
'?s=48&d=https%3A%2F%2Fmyserver.test%2Fdefault.png'
@ArtemAvramenko
ArtemAvramenko / truncate-object.js
Created October 18, 2022 11:07
Truncates long strings and arrays in object. It is useful for logging
const truncateObject = o => {
if (!o) {
return o;
}
if (typeof o === 'string') {
return o.substring(0, 64);
}
if (Array.isArray(o)) {
return o.slice(0, 5).map(x => truncateObject(x));
}
@ArtemAvramenko
ArtemAvramenko / ignoreWhitespaces.js
Last active January 23, 2024 09:25
Ignoring whitespaces in Javascript RegExp patterns
/**
* ignores comments and whitespaces in regexp patterns,
* similar to RegexOptions.IgnorePatternWhitespace in C#
* or Pattern.COMMENTS in Java.
* @example
* // returns /[a-z][0-9]+/i
* new RegExp(ignoreWhitespaces`
* [a-z] # any latin letter
* [0-9]+ # any number
* `, 'i');
@ArtemAvramenko
ArtemAvramenko / GetAllFiles.cs
Last active May 26, 2023 20:05
Get all files in all subfolders by regexp mask in C#
private const string BaseDir = @"C:\Users\username\Desktop\dir";
private static readonly Regex _files = new(
@".*\.(xml)$",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex _ignoredDir = new(
"^(node_modules|bin|obj)$",
RegexOptions.IgnoreCase | RegexOptions.Compiled);