Skip to content

Instantly share code, notes, and snippets.

@ArtemAvramenko
ArtemAvramenko / HtmlToPlainText.cs
Last active April 9, 2024 15:07
Convert HTML to plain text in C#
private static readonly Regex[] _htmlReplaces = new[] {
new Regex(@"<script\b[^<]*(?:(?!</script>)<[^<]*)*</script>", RegexOptions.Compiled | RegexOptions.Singleline, TimeSpan.FromSeconds(1)),
new Regex(@"<style\b[^<]*(?:(?!</style>)<[^<]*)*</style>", RegexOptions.Compiled | RegexOptions.Singleline, TimeSpan.FromSeconds(1)),
new Regex(@"<[^>]*>", RegexOptions.Compiled),
new Regex(@" +", RegexOptions.Compiled)
};
public static string HtmlToPlainText(string html)
{
foreach (var r in _htmlReplaces)
@ArtemAvramenko
ArtemAvramenko / searchParamsParser.ts
Created September 23, 2019 12:32
URLSearchParams to object
function objToParams(obj: any) {
let params = new URLSearchParams();
for (let name in obj) {
let value = obj[name];
if (Array.isArray(value)) {
for (let item of value) {
params.append(name, item);
}
} else {
params.set(name, value)
@ArtemAvramenko
ArtemAvramenko / localization.cs
Last active December 18, 2019 14:08
JSON localization to C# objects
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
@ArtemAvramenko
ArtemAvramenko / bindingRedirect.js
Created June 19, 2020 15:15
Creates binding redirect xml from failed msbuild log
msBuildLog.replace(/^.*"([\w\.]+), Culture=(\w+), PublicKeyToken=(\w+)".*to Version "([\d\.]+)".*/gm,
`<dependentAssembly>
<assemblyIdentity name="$1" publicKeyToken="$3" culture="$2" />
<bindingRedirect oldVersion="0.0.0.0-$4" newVersion="$4" />
</dependentAssembly>`)
SELECT
sum(ddps.row_count)
FROM sys.indexes AS i
INNER JOIN sys.objects AS o ON i.OBJECT_ID = o.OBJECT_ID
INNER JOIN sys.dm_db_partition_stats AS ddps ON i.OBJECT_ID = ddps.OBJECT_ID
AND i.index_id = ddps.index_id
WHERE i.index_id < 2 AND o.is_ms_shipped = 0
@ArtemAvramenko
ArtemAvramenko / CamelCaseConverter.cs
Created October 27, 2020 10:53
C# camel case coverter
public static string ToCamelCase(string text)
{
if (text != null)
{
var upperCount = 0;
while (upperCount < text.Length && char.IsUpper(text, upperCount))
{
upperCount++;
}
if (upperCount > 1 && upperCount < text.Length && char.IsLower(text, upperCount))
@ArtemAvramenko
ArtemAvramenko / max-integer-values.txt
Last active March 26, 2025 16:45
Max integer values
int 2 147 483 647 (2^32 / 2) - 2 billions
double 9 007 199 254 740 992 (2^53) - 9 quadrillions (millions of billions)
long 9 223 372 036 854 775 807 (2^64 / 2) - 9 quintillions (billions of billions)
decimal 79 228162514 264337593 543950335 (2^96) - 79 octillions (billions of billions of billions)
t/sql money 922 337 203 685 477 (2^63 / 1e4) - 900 trillions (millions of millions)
t/sql smallmoney 214 748 (2^31 / 1e4) - 200 thousands
t/sql numeric(38,4) 999999999..99 (1e34 - 1) - 9 decillion (millions of billions of billions of billions)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
namespace tztest
{
class Program
{
private static XmlDocument LoadCldrXml(string path)
@ArtemAvramenko
ArtemAvramenko / copy-url.user.js
Last active August 27, 2024 11:01
Copy URL UserScript
// ==UserScript==
// @include *
// @noframes
// @grant unsafeWindow
// @grant GM_registerMenuCommand
// @grant GM_setClipboard
// ==/UserScript==
GM_registerMenuCommand('Copy URL', () => {