Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / foreach.sql
Last active December 7, 2017 17:36
foreach t/sql
-- for each...
DECLARE @ItemId INT
DECLARE ItemCursor CURSOR FOR
SELECT ItemId
FROM Items
WHERE ...
OPEN ItemCursor
WHILE 1 = 1
BEGIN
FETCH NEXT FROM ItemCursor INTO @ItemId
public class TokenContainer
{
public string Access_token { get; set; }
}
var request = new RestRequest("/core/connect/token", Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("grant_type", "client_credentials");
request.AddParameter("client_id", "CLIENT_ID");
request.AddParameter("client_secret", "CLIENT_SECRET");
// cscript waitUrl.js http://alm-build/TimeTracker/dev/test/favicon.ico
var url = WScript.Arguments(0);
var status = 0;
var WinHttpReq = new ActiveXObject('WinHttp.WinHttpRequest.5.1');
for (var i = 0; i < 30; i++) {
WScript.Sleep(1000);
WinHttpReq.Open('GET', url, false);
WinHttpReq.Send();
status = WinHttpReq.Status;
SELECT o.name, i.name, ddius.* FROM sys.dm_db_index_usage_stats ddius
JOIN sys.indexes i ON ddius.object_id = i.object_id AND ddius.index_id = i.index_id
JOIN sys.objects o ON i.object_id = o.object_id
WHERE ddius.database_id = DB_ID()
@ArtemAvramenko
ArtemAvramenko / convert_array_to_dictionary.ts
Last active September 2, 2022 09:06
TypeScript convert array to dictionary
static toDictionary<TItem>(
array: TItem[],
getKey: (item: TItem) => number): { [id: number]: TItem };
static toDictionary<TItem, TValue>(
array: TItem[],
getKey: (item: TItem) => number,
getValue: (item: TItem) => TValue): { [id: number]: TValue };
static toDictionary<TItem>(
array: TItem[],
getKey: (item: TItem) => string): { [id: string]: TItem };