Skip to content

Instantly share code, notes, and snippets.

@Flayed
Flayed / ConcurrentHashSet.cs
Last active November 2, 2017 15:15
ConcurrentHashSet<T>
public class ConcurrentHashSet<T> : ICollection<T>, IEnumerable<T>, IEnumerable, IReadOnlyCollection<T>
{
private readonly ConcurrentDictionary<T, byte> _dictionary = new ConcurrentDictionary<T, byte>();
public int Count => _dictionary.Keys.Count;
public bool IsReadOnly => false;
public void Add(T item)
{
_dictionary.TryAdd(item, 0);
}
public void Clear()
@Flayed
Flayed / startup.cs
Created November 2, 2017 18:13
Angular startup
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404 &&
!Path.HasExtension(context.Request.Path.Value) &&
!context.Request.Path.Value.StartsWith("/api/"))
{
context.Request.Path = "/index.html";
await next();
}
@Flayed
Flayed / startup.cs
Created November 2, 2017 18:14
Default Startup
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseDefaultFiles();
app.UseStaticFiles();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
@Flayed
Flayed / styles.scss
Created November 6, 2017 20:54
Adding border-*-# width to Bootstrap 4
@import "~bootstrap/scss/bootstrap";
@each $size, $length in $spacers {
.border-left-#{$size} {
border-width: #{$size}px !important;
}
.border-top-#{$size} {
border-width: #{$size}px !important;
}
.border-bottom-#{$size} {
@Flayed
Flayed / my.service.ts
Last active November 13, 2017 21:50
Service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
@Injectible()
export class MyService {
public constructor(private _http: HttpClient) {
}
public GetValue(id: number): Observable<string> {
@Flayed
Flayed / my.component.ts
Created November 13, 2017 21:36
Component
import { Component } from '@angular/core';
import { MyService } from './my.service';
@Component({
selector: 'app-my-component',
template: `<div>{{myValue}}</div>`
})
export class MyComponent {
public myValue: string;
@Flayed
Flayed / my.component.spec.ts
Created November 13, 2017 21:46
my.component.spec.ts
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { MyComponent } from './my.component';
import { MyService } from './my.service';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
describe('MyComponent', () => {
let component = MyComponent;
let fixture = ComponentFixture<MyComponent>;
@Flayed
Flayed / Constants.cs
Last active December 16, 2017 12:35
Enumerate Class Constants
public static class MagicStrings
{
public const string Potato = "Potato";
public const string Tomato = "Tomato";
private static string[] _strings;
public static string[] Strings
{
get
{
@Flayed
Flayed / my-component.spec.ts
Created December 20, 2017 21:30
Satisfy @input variables
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MyComponent } from './my-component.component';
import { MyCoolClass } from '../classes/MyCoolClass.service';
describe('MyComponent', () => {
let component: MyComponent;
let fixture: ComponentFixture<MyComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MyComponent ]
@Flayed
Flayed / ConfigurationService.cs
Created December 29, 2017 17:48
ConfigurationService
public class ConfigurationService : IConfigurationService
{
public ConfigurationService(IDataService dataService)
{
_configurationSet = dataService.GetConfigurationSet();
}
public ITriangleConfiguration TriangleConfiguration => _configurationSet.TriangleConfiguration;
public ISquareConfiguration SquareConfiguration => _configurationSet.SquareConfiguration;
public ICircleConfiguration CircleConfiguration => _configurationSet.CircleConfiguration;