Skip to content

Instantly share code, notes, and snippets.

@ksysiekj
ksysiekj / list empty tables.sql
Last active November 30, 2016 21:46
T-SQL script listing all empty tables on SQL Server
USE master
DECLARE @dbName nvarchar(128);
DECLARE @sqlTableQuery nvarchar(max);
DECLARE dbsCursor CURSOR
LOCAL STATIC READ_ONLY FORWARD_ONLY
FOR
SELECT
name
FROM master.dbo.sysdatabases
@ksysiekj
ksysiekj / JilMediaTypeFormatter.cs
Created February 24, 2017 00:26
JilMediaTypeFormatter
public sealed class JilMediaTypeFormatter : MediaTypeFormatter
{
private static readonly MediaTypeHeaderValue _applicationJsonMediaType = new MediaTypeHeaderValue("application/json");
private static readonly MediaTypeHeaderValue _textJsonMediaType = new MediaTypeHeaderValue("text/json");
private static readonly Task<bool> _done = Task.FromResult(true);
private static readonly Options _options;
static JilMediaTypeFormatter()
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
config.ConfigureJSONFormatter();
public sealed class JilSerializationAttribute : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
// Register JilMediaTypeFormatter for controller
controllerSettings.Formatters.Insert(0, new JilMediaTypeFormatter());
}
}
public sealed class JilSerializationAttribute : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
// Register JilMediaTypeFormatter for controller
controllerSettings.Formatters.Insert(0, new JilMediaTypeFormatter());
}
}
[JilSerialization]
public sealed class JilValuesController : ApiController
{
// GET api/values
public IHttpActionResult Get()
{
return Ok(ValueServices.Values);
}
}
public static void Retry<TException>(Action action, int maxAttempts, TimeSpan delay,
Func<TException, bool> shouldRetry = null, Action<TException> exceptionLogger = null)
where TException : Exception
{
Assert.Positive(maxAttempts, nameof(maxAttempts));
Assert.NotNull(action, nameof(action));
bool shouldRetryNotNull = shouldRetry != null;
RetryHandler.Retry<WebException>(() =>
{
string content = DownloadContent();
Console.Write(content);
}, 6, 500, httpRequestException => httpRequestException.Status == WebExceptionStatus.Timeout
|| httpRequestException.Status == WebExceptionStatus.ConnectFailure, Logger);
public static void RetryFor<TException>(Action action, TimeSpan duration, TimeSpan delay,
Func<TException, bool> shouldRetry = null, Action<TException> exceptionLogger = null)
where TException : Exception
{
Assert.NotNull(action, nameof(action));
bool shouldRetryNotNull = shouldRetry != null;
double durationTotalMs = duration.TotalMilliseconds;
DateTime startDateTime = DateTime.Now;
RetryHandler.RetryFor<WebException>(() =>
{
string content = DownloadContent();
Console.Write(content);
}, TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(2), httpRequestException => httpRequestException.Status == WebExceptionStatus.Timeout
|| httpRequestException.Status == WebExceptionStatus.ConnectFailure, Logger);