This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Runtime.InteropServices; | |
| using System.Text; | |
| namespace App.Encoding | |
| { | |
| class Program | |
| { | |
| [DllImport("kernel32.dll")] | |
| static extern int GetSystemDefaultLCID(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const isDevMode = () => true; | |
| type ValidatedString<T extends string> = string & { | |
| [K in keyof string] : K extends `as${string}String` ? never : string[K] | |
| } & { | |
| readonly __format: T | |
| }; | |
| /* | |
| eslint-disable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void ExtractZip(string zipPath, string folderPath) | |
| { | |
| using var zip = ZipFile.Open(zipPath, ZipArchiveMode.Read); | |
| foreach (var entry in zip.Entries) | |
| { | |
| var correctPath = entry.FullName.Replace("\\", "/"); | |
| var extractedFileInfo = new FileInfo(Path.Combine(folderPath, correctPath)); | |
| var entryDirectory = extractedFileInfo.Directory!.FullName; | |
| if (!Directory.Exists(entryDirectory)) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function parseTime(s, pmByDefault) { | |
| const match = (s || '').toLowerCase().match(/^[^0-9]*([0-9]+)([^0-9]*([0-9]*)(.*))$/); | |
| if (!match) { | |
| return null; | |
| } | |
| let mins = 0; | |
| let hours = 0; | |
| if (match[3]) { // strings like '12:34' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** Masks email, e.g. [email protected] as j•••e@g•••m **/ | |
| function maskEmail(email) { | |
| function mask(segment) { | |
| const hider = '•••'; | |
| let result = ''; | |
| if (segment) { | |
| result = segment[0] + hider; | |
| if (segment.length > 2) { | |
| result += segment[segment.length - 1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |