Skip to content

Instantly share code, notes, and snippets.

import {map} from 'rxjs/operators';
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {AuthenticationService} from './services/authentication.service';
import {CurrentUserService} from './services/current-user.service';
@Injectable()
export class AuthenticationGuard implements CanActivate {
constructor(private _router: Router,
public class Startup
{
private readonly IConfiguration _configuration;
private readonly IHostingEnvironment _env;
private readonly LoggingLevelSwitch _logLevelSwitch;
public Startup(IConfiguration configuration, IHostingEnvironment env)
{
_configuration = configuration;
_env = env;
@CodingGorilla
CodingGorilla / Program.cs
Created September 17, 2018 20:51
Marten Compiled Query error
class Program
{
private static DocumentStore _documentStore;
static void Main(string[] args)
{
var connectionString =
$"SCRUBBED";
_documentStore = DocumentStore.For(_ =>
{
@CodingGorilla
CodingGorilla / SO-9019961.cs
Created January 26, 2012 16:13
Code sample for StackOverflow question 9019961
public class Com<T>
{
private Thread dispatcher;
private Queue<T> queue;
private int waitTime;
private Object locker;
private Timer timer;
private ManualResetEvent event;
public event EventHandler EmptyQueueEvent;
@CodingGorilla
CodingGorilla / WpfPopupError.xaml
Created January 24, 2012 21:22
Uses the Validation.ErrorTemplate to create a popup error indicator on a WPF TextBox control
<Style TargetType="{x:Type TextBox}">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<Grid>
<Border BorderBrush="#FFCB2E2E" BorderThickness="1" Background="#11FF0000" IsHitTestVisible="False" x:Name="errorBorder"/>
<AdornedElementPlaceholder x:Name="placeholder" />
<Popup AllowsTransparency="True" HorizontalAlignment="Right" HorizontalOffset="0" VerticalOffset="0" PopupAnimation="Fade" Placement="Right"
PlacementTarget="{Binding ElementName=errorBorder}" IsOpen="{Binding ElementName=placeholder, Path=AdornedElement.IsFocused, Mode=OneWay}">
<StackPanel Orientation="Horizontal">
@CodingGorilla
CodingGorilla / EventAggregator.cs
Created January 11, 2011 15:00
Receives events and passes them along to subscribers
public sealed class EventAggregator
{
public static readonly EventAgregator Instance = new EventAggregator();
private EventAggregator
{
}
public event EventHandler PlayerDied;
@CodingGorilla
CodingGorilla / Singleton-Sample.cs
Created January 11, 2011 14:48
Demonstrates the singleton pattern
public class MySingleton
{
public static readonly MySingleton Instance = new MySingleton();
/* Private or protected constructor so only this class can instantiate itself */
private MySingleton()
{
}
}
@CodingGorilla
CodingGorilla / Lambo-LinqToXml.cs
Created January 10, 2011 21:02
Quick LINQ to XML sample for Lambo
XDocument doc = XDocument.Load("my-xml-file.xml");
foreach(XElement el in doc.Descendants("row")
{
test.actual = el.Descendants("var").Where( x => (string)x.Attribute("name") == "account" ).Single().Attribute("value").Value;
test.actual = el.Descendants("var").Where( x => (string)x.Attribute("name") == "commitment").Single().Attribute("value").Value;
/* Repeat the above as need for additional 'var' element values */
}