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 class LargeBitArray | |
{ | |
private readonly int _bucketSize; | |
private readonly long _capacity; | |
public LargeBitArray(long capacity = int.MaxValue) // ~272 MB for 2^31 values | |
{ | |
if (capacity < 1 || capacity > (long)2e18) | |
{ | |
throw new ArgumentException("Capacity is out of range"); |
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
/** | |
* This small function allows you to distribute your script as a single file, without | |
* requiring a separate package.json. When running a script through a node, the dependencies | |
* that are installed will not affect neighboring scripts or global packages. | |
* @summary Installs dependencies in the local dotfiles folder | |
*/ | |
const installDependencies = dependencies => { | |
const fs = require('fs'); | |
const dependenciesPath = './.npm-' + __filename.match(/[^\\/]+$/)[0]; | |
fs.existsSync(dependenciesPath) || fs.mkdirSync(dependenciesPath); |
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://stackoverflow.com/questions/17975609/lazy-load-properties-with-async/41141728#41141728 | |
#nullable enable | |
public class AsyncLazy<T> | |
{ | |
private Func<Task<T>>? _valueFactory; | |
private volatile SemaphoreSlim? _semaphore = new(1, 1); | |
private volatile Boxed? _boxed; |
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
Windows Registry Editor Version 5.00 | |
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize] | |
"AppsUseLightTheme"=dword:00000000 | |
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 toBasicLatin = (function() { | |
// see https://gist.github.com/ArtemAvramenko/ec3b5358221f8b6e9f3e9efe1d0a3066 | |
const data = | |
'AαаAEæBβбCHчDđðδдDJђDZѕDZHџEεηеэFƒфFIfiFLflGγгґGJѓIıιиіIAяIEєIOёIUюJјKκкKHχхKJќLłλл'+ | |
'LJљMμмNνнNJњOøοωоOEœPπпPHφPSψRρрSσςсSHшSHCHщSSßTτтTHþθTSцTSHћUµυуVвXξYыYIїZζзZHж'; | |
let map = {}; | |
for(const x of data.matchAll(/([A-Z]+)([^A-Z]+)/g)) { | |
const latValue = x[1].toLowerCase(); |
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 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) | |
=> encodings.Any(e => e.GetString(e.GetBytes(s)) == s); |
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
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
// 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
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 }; | |
}; |