Skip to content

Instantly share code, notes, and snippets.

@ArtemAvramenko
ArtemAvramenko / angular_digest_performance.ts
Created April 27, 2017 12:22
Angular digest performance logging
let oldDigest = GlobalServices.rootScope.$digest;
GlobalServices.rootScope.$digest = function () {
let stack = (<any>Error()).stack;
let t = new Date().getTime();
oldDigest.call(this);
t = new Date().getTime() - t;
if (t > 250) {
console.log(`$digest: ${t} ms`)
console.log(stack);
}
@ArtemAvramenko
ArtemAvramenko / FromUriNullableAttribute.cs
Created May 15, 2017 18:47
Interpret query string 'null' as null for specified properties
using System;
using System.Collections.Generic;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.ValueProviders;
using System.Web.Http.ValueProviders.Providers;
using System.Globalization;
using System.Net.Http;
using System.Web.Http.ModelBinding;
@ArtemAvramenko
ArtemAvramenko / DataProtectorTokenProviderEx.cs
Created May 26, 2017 12:33
ASP.NET Identity: Add ability to have different token lifespan for different purposes
using System;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.Owin.Security.DataProtection;
/// <summary>
/// Token provider that uses an IDataProtector to generate encrypted tokens based off of the security stamp
@ArtemAvramenko
ArtemAvramenko / getDateTimeFormats.js
Last active July 5, 2024 19:45
Determine date and time formats in JavaScript
// https://en.wikipedia.org/wiki/Date_format_by_country
// MM/DD/YYYY USA
// DD/MM/YYYY Great Britain
// DD.MM.YYYY Germany
// DD-MM-YYYY Netherlands
// YYYY-MM-DD Canada
// YYYY/MM/DD South Africa
// YYYY.MM.DD Hungary
function getDateTimeFormats(/** @type {string | undefined} */ locale) {
@ArtemAvramenko
ArtemAvramenko / CopyUnicodeUrl.js
Last active January 30, 2018 14:19
Copy Unicode Url in browser
javascript:void(prompt('Press%20Ctrl+C',decodeURIComponent(window.location.href).replace(/%20/g,'%2520')))
@ArtemAvramenko
ArtemAvramenko / RawString.cs
Last active May 3, 2018 22:17
Use Microsoft.AspNetCore.Mvc.Razor to generate emails
namespace Razor.Mail
{
public class RawString
{
private readonly string _text;
public RawString(string text) => _text = text;
public override string ToString()
{
@ArtemAvramenko
ArtemAvramenko / mixins.ts
Last active November 29, 2018 10:01
TypeScript mixins
const MixinHello = <T extends new (...args: any[]) => A>(base: T) =>
class extends base {
hello() { }
};
class A {
a() { }
}
class B extends A {
@ArtemAvramenko
ArtemAvramenko / AsyncHelper.cs
Created January 30, 2019 14:48
C# run async method synchronously
public static class AsyncHelper
{
public static T RunSync<T>(Func<Task<T>> action)
{
try
{
var result = default(T);
Task.Run(async () =>
{
result = await action();
@ArtemAvramenko
ArtemAvramenko / Reorganize_all_indexes.sql
Last active April 5, 2019 15:52
SQL Server - reorganize all indexes
DECLARE @Indexes table (TableName nvarchar(MAX), IndexName nvarchar(MAX), Value int)
INSERT INTO @Indexes
SELECT
QuoteName(s.name) + '.' + QuoteName(t.name) as TableName,
QuoteName(i.name) as IndexName,
avg_fragmentation_in_percent as Value
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS ips
INNER JOIN sys.tables t on t.object_id = ips.object_id
INNER JOIN sys.schemas s on t.schema_id = s.schema_id
INNER JOIN sys.indexes AS i ON i.object_id = ips.object_id
@ArtemAvramenko
ArtemAvramenko / current-sql-server-connections.sql
Last active April 12, 2019 12:45
Query current SQL Server connections
select
count = count(*),
db_name = db_name(database_id),
status,
login_name,
host_name,
program_name
from sys.dm_exec_sessions
where is_user_process = 1
group by database_id, status, login_name, host_name, program_name