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
| 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
| 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
| 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
| 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 expect = actual => { | |
| const toBe = expected => { | |
| let [a, b] = [actual, expected].map(JSON.stringify); | |
| if (a !== b) { | |
| console.error(a + ' should be ' + b); | |
| } | |
| }; | |
| return { toBe, toEqual: toBe }; | |
| }; |
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
| // type numberFormat = | |
| 'dot_with_comma_grouping' | // en-US | |
| 'dot_with_indian_grouping' | // en-IN | |
| 'dot_with_apostrophe_grouping' | // de-CH | |
| 'comma_with_dot_grouping' | // it-IT | |
| 'comma_with_space_grouping'; // pt-PT | |
| // 100,000.50 - DEFAULT FORMAT except for Europe (en-US) | |
| ["United Kingdom", "Malta"] |
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
| var amount = 900m; | |
| var currency = "μBTC"; | |
| // https://en.wikipedia.org/wiki/Micro- | |
| int prefixIndex = currency.Length > 3 ? "mμnpf".IndexOf(currency[0]) : -1; | |
| if (prefixIndex >= 0) | |
| { | |
| currency = currency[1..]; | |
| amount /= (decimal)Math.Pow(1000, prefixIndex + 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
| // In practical scenarios, such a transformation speeds up the search by dozens of times: | |
| // Apple, Apricot, Banana => (?:Ap(?:ple|ricot)|Banana) | |
| private static void GenerateRegex(StringBuilder result, IList<string> words, int level = 0) | |
| { | |
| const int minPrefix = 1; | |
| const int maxLevel = 300; | |
| void AppendLevel() | |
| { | |
| // sb.Append('\n'); |
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
| // https://github.com/anyascii/anyascii/blob/master/unidecode/unidecode.tsv | |
| var unidecodeLines = File.ReadAllLines(@"C:\Users\username\Desktop\Unidecode\unidecode.tsv"); | |
| var outputFile = @"C:\Users\username\Desktop\Unidecode\onlyletters.tsv"; | |
| Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); | |
| var encodings = new[] { | |
| 10000, 10006, 10007, 10010, 10017, 10029, 10079, 10081, 10082, | |
| 1250, 1251, 1252, 1253, 1254, 1257, 1258 | |
| }.Select(i => Encoding.GetEncoding(i)).ToArray(); | |
| bool isSupportedEncoding(string s) |