Skip to content

Instantly share code, notes, and snippets.

@ArtemAvramenko
ArtemAvramenko / get-software-list.ps1
Created April 18, 2025 09:45
A one-line script that displays all installed software on the PC
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* , HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | ForEach-Object { if ($_.DisplayName -eq $null) {$_.PSChildName} else {$_.DisplayName} } | Sort-Object
@ArtemAvramenko
ArtemAvramenko / SciTEUser.properties
Created November 26, 2024 18:24
SciTE text editor config
# https://www.scintilla.org/SciTEDoc.html
# Encoding (UTF-8) and line feed
code.page=65001
eol.mode=LF
eol.auto=1
# Indentation: 4 spaces
tabsize=4
indent.size=4
@ArtemAvramenko
ArtemAvramenko / decimal-rounding.ts
Last active August 19, 2024 19:36
A method of rounding decimals in JavaScript that is aimed to correct inaccurate calculations
// Copyright (c) Artem Avramenko. All rights reserved.
// Licensed under the MIT license. See license.txt for details.
/**
* Returns an integer power of ten with maximum accuracy and performance
*/
const pow10 = (() => {
const precalc = [] as number[];
for (let i = -323; i < 309; i++) {
precalc.push(+('1e' + i));
@ArtemAvramenko
ArtemAvramenko / x-headers-example.txt
Last active May 20, 2024 11:46
widely used private http x-headers
X-Frame-Options
X-Http-Method-Override
X-Csrf-Token
X-Real-IP
X-Forwarded-For
X-Forwarded-Host
X-Forwarded-Proto
X-Original-For
X-Original-Host
X-Original-Proto
@ArtemAvramenko
ArtemAvramenko / TemporaryQueue.cs
Created May 13, 2024 15:25
Queue/cache of items that are stored for a limited period of time
using System;
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
namespace ArtemAvramenko.Collections;
/// <summary>
/// Queue/cache of items that are stored for a limited period of time.
/// </summary>
@ArtemAvramenko
ArtemAvramenko / read-text-from-file.js
Last active June 16, 2024 11:32
JavaScript code to read unicode text from a file on the browser side
function readTextFromFile(file, maxMegabytes = 1) {
const reader = new FileReader();
return new Promise(resolve => {
// check file size
if (!file || !file.size) {
resolve({ error: `The file cannot be empty` });
return;
}
if (file.size > maxMegabytes * 0x100000) {
@ArtemAvramenko
ArtemAvramenko / restore-indexes.sql
Last active September 18, 2024 19:30
The T/SQL script solves the problem with is_not_trusted indexes after moving data to another Azure db without using the sp_MSforeachtable proc
DECLARE
@Schema NVARCHAR(MAX),
@Name NVARCHAR(MAX),
@Sql NVARCHAR(MAX)
DECLARE TableCursor CURSOR FOR
SELECT TABLE_SCHEMA, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
OPEN TableCursor
WHILE 1 = 1
@ArtemAvramenko
ArtemAvramenko / basic-plural.js
Last active March 13, 2024 22:38
The simplest pluralizer according to English rules. It doesn't contain a list of exceptions, so it will return 'mouses' instead of 'mice', 'mans' instead of 'men', etc.
module.exports = function getPlural(name) {
const match = (r, n, e) => r.test(name) && (n ? name.slice(0, -n) : name) + e;
return match(/sis$/, 2, 'es') // analyses, diagnoses
|| match(/(?:[^fgmq][aeoi]|[fglm][eio]|[^aeijoqsuvxz])s$/, 0, '') // physics, stairs
|| match(/(?:s|x|z|[cs]h|ato)$/, 0, 'es') // kisses, tomatoes
|| match(/(?:[^aeiou]|qu)y$/, 1, 'ies') // ladies, tries
|| match(/[^ch][ieo][ln]ey$/, 2, 'ies') // smilies, monies
|| match(/(?:[aeou]l|[eo]a|ar)f$/, 1, 'ves') // scarves, shelves
|| match(/[^defr]ife$/, 2, 'ves') // knives, wives
|| name + 's';
@ArtemAvramenko
ArtemAvramenko / failure-probability.md
Last active April 17, 2025 08:41
Probability of failure of a complex system
Number of elements Failure probability of every single element Reliability Overall probability of failure
100 1 / 100    99% >60%
1000 1 / 1 000    99.9% >60%
10000 1 / 10 000   99.99% >60%
Number of elements Failure probability of every single element Reliability Overall probability of failure
100 1 / 10 000 99.99% <1%