Skip to content

Instantly share code, notes, and snippets.

@timgabrhel
timgabrhel / CloudConfigurationManagerHelper
Last active August 29, 2015 14:08
CloudConfigurationManager.GetSetting Helper
public static bool GetSetting<T>(string key, ref T output)
{
var value = CloudConfigurationManager.GetSetting(key);
if (string.IsNullOrWhiteSpace(value) == false)
{
try
{
output = (T) Convert.ChangeType(value, typeof (T));
return true;
}
@timgabrhel
timgabrhel / WintsyMenuFlyoutPresenter
Created November 14, 2014 15:09
MenuFlyoutPresenter Style
<Style TargetType="MenuFlyoutPresenter" x:Key="WintsyMenuFlyoutPresenterStyle">
<Setter Property="Background" Value="{ThemeResource WintsyFlyoutBackground}" />
<Setter Property="Foreground" Value="{ThemeResource WintsyFlyoutForeground}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.IsHorizontalRailEnabled" Value="False" />
<Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="False" />
@timgabrhel
timgabrhel / FlyoutBase.AttachedFlyout
Created November 14, 2014 15:10
FlyoutBase.AttachedFlyout
<StackPanel x:Name="ListingPreviewStackPanel"
IsHoldingEnabled="True"
Holding="ListingPreview_Holding"
FlyoutBase.AttachedFlyout="{StaticResource WintsyListingPreviewFlyout}"
Tapped="ListingPreview_Tapped">
</StackPanel>
@timgabrhel
timgabrhel / MenuFlyout
Created November 14, 2014 15:10
MenuFlyout
<MenuFlyout x:Key="WintsyListingPreviewFlyout"
MenuFlyoutPresenterStyle="{StaticResource WintsyMenuFlyoutPresenterStyle}"
Placement="Bottom">
<MenuFlyoutItem Text="favorite"
Command="{Binding FavoriteListingCommand, Mode=OneWay}" />
<MenuFlyoutItem Text="view shop" />
</MenuFlyout>
@timgabrhel
timgabrhel / FlyoutBase.ShowAttachedFlyout
Created November 14, 2014 15:11
FlyoutBase.ShowAttachedFlyout
private void ListingPreview_Holding(object sender, HoldingRoutedEventArgs e)
{
FlyoutBase.ShowAttachedFlyout(ListingPreviewStackPanel);
}
@timgabrhel
timgabrhel / Logger.cs
Created February 24, 2016 18:53
Application Insights basic logger
public class Logger
{
private static TelemetryClient telemetry = null;
public Logger(string instrumentationKey)
{
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
telemetry = new TelemetryClient();
telemetry.Context.InstrumentationKey = instrumentationKey;
}
@timgabrhel
timgabrhel / example.cs
Created March 12, 2016 02:39
Mini Redis Cache Transient Exception Handling
/// <summary>
/// A simple implementation to automatically retry transient connection error's to cache. Runs for a maximum of 10 seconds before timing out.
/// </summary>
protected TResult AttemptCacheCall<TResult>(Func<TResult> codeFunc)
{
var timeout = false;
var timer = new Timer(10000);
timer.Elapsed += (sender, args) => timeout = true;
timer.AutoReset = false;
timer.Start();
@timgabrhel
timgabrhel / links.txt
Created March 12, 2016 03:15
NEWCodeCamp2016 Resources
@timgabrhel
timgabrhel / web.config
Created April 19, 2016 13:54
redis asp.net session provider
<system.web>
<sessionState mode="Custom" customProvider="RedisSessionProvider">
<providers>
<add name="RedisSessionProvider"
type="Microsoft.Web.Redis.RedisSessionStateProvider"
port="6379"
host="abc.redis.cache.windows.net"
accessKey="abc"
ssl="false"
connectionTimeoutInMilliseconds="15000"
private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect("{redis connection string}");
});
public static ConnectionMultiplexer Connection => lazyConnection.Value;
private static IDatabase Cache => Connection.GetDatabase();
private T getCacheObj<T>(string key)
{